Trait AwsStreamInstrument

Source
pub trait AwsStreamInstrument<T, E, S>
where E: RequestId + Error, S: Stream<Item = Result<T, E>>,
{ // Required method fn instrument<'a>( self, span: impl Into<AwsSpanBuilder<'a>>, ) -> InstrumentedStream<'a, S>; }
Expand description

A trait for adding OpenTelemetry instrumentation to AWS pagination streams.

This trait provides the instrument method that wraps streams with telemetry capabilities, automatically creating and managing spans for AWS operations. It is designed for AWS pagination streams, but it is implemented for any TryStream yielding AWS SDK errors.

The entire stream gets represented by a single AwsSpan regardless of the number of AWS SDK requests sent by the SDK to produce it.

All instrumented streams automatically include the aws.pagination_stream = true attribute to help identify streaming operations in traces.

§Integration with AwsBuilderInstrument

The recommended pattern is to use AwsBuilderInstrument::build_aws_span to capture all the operation parameters before converting fluent builder into a paginator stream.

§Examples

use aws_sdk_dynamodb::{Client as DynamoClient, types::AttributeValue};
use futures_util::TryStreamExt;
use telemetry_rust::middleware::aws::{AwsBuilderInstrument, AwsStreamInstrument};

async fn query_table() -> Result<usize, Box<dyn std::error::Error>> {
    let config = aws_config::load_from_env().await;
    let dynamo_client = DynamoClient::new(&config);

    // Build the query with all parameters
    let query = dynamo_client
        .query()
        .table_name("table_name")
        .index_name("my_index")
        .key_condition_expression("PK = :pk")
        .expression_attribute_values(":pk", AttributeValue::S("Test".to_string()));

    // Extract span from fluent builder (includes all input attributes)
    let span = query.build_aws_span();

    // Use the span to instrument the paginator stream.
    let items = query
        .into_paginator()
        .items()
        .send()
        .instrument(span)
        .try_collect::<Vec<_>>()
        .await?;

    println!("DynamoDB items: {items:#?}");
    Ok(items.len())
}

Required Methods§

Source

fn instrument<'a>( self, span: impl Into<AwsSpanBuilder<'a>>, ) -> InstrumentedStream<'a, S>

Instruments the stream with OpenTelemetry tracing.

This method wraps a TryStream in an InstrumentedStream that will:

  • Start a span when the stream begins polling
  • End the span with success when the stream completes normally
  • End the span with error information if the stream encounters an error
§Arguments
  • span - The span builder or span configuration to use for instrumentation
§Returns

An InstrumentedStream that wraps the original stream with telemetry capabilities.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<T, E> AwsStreamInstrument<T, E, PaginationStreamImplStream<Result<T, E>>> for PaginationStream<Result<T, E>>
where E: RequestId + Error,

Implementors§

Source§

impl<T, E, S> AwsStreamInstrument<T, E, S> for S
where E: RequestId + Error, S: Stream<Item = Result<T, E>>,