pub trait AwsStreamInstrument<T, E, S>{
// 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.
All instrumented streams automatically include the aws.pagination_stream = true
attribute to help identify streaming operations in traces.
§Examples
use aws_sdk_dynamodb::{Client as DynamoClient, types::AttributeValue};
use futures_util::TryStreamExt;
use telemetry_rust::{
KeyValue,
middleware::aws::{AwsStreamInstrument, DynamodbSpanBuilder},
semconv,
};
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);
let items =
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()))
.into_paginator()
.items()
.send()
.instrument(DynamodbSpanBuilder::query("table_name").attribute(
KeyValue::new(semconv::AWS_DYNAMODB_INDEX_NAME, "my_index"),
))
.try_collect::<Vec<_>>()
.await?;
println!("DynamoDB items: {items:#?}");
Ok(items.len())
}Required Methods§
Sourcefn instrument<'a>(
self,
span: impl Into<AwsSpanBuilder<'a>>,
) -> InstrumentedStream<'a, S>
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.