Trait AwsInstrument

Source
pub trait AwsInstrument<T, E, F>
where T: RequestId, E: RequestId + Error, F: Future<Output = Result<T, E>>,
{ // Required method fn instrument<'a>( self, span: impl Into<AwsSpanBuilder<'a>>, ) -> InstrumentedFuture<F, AwsSpan> ; }
Expand description

Trait for instrumenting AWS futures with automatic span management.

This trait provides a convenient way to wrap AWS SDK futures with OpenTelemetry instrumentation, automatically handling span creation, error recording, and cleanup.

For automatic span attributes extraction, use AwsBuilderInstrument trait.

§Example

use aws_sdk_dynamodb::{Client as DynamoClient, types::AttributeValue};
use telemetry_rust::{
    KeyValue,
    middleware::aws::{AwsInstrument, DynamodbSpanBuilder},
    semconv,
};

async fn query_table() -> Result<i32, Box<dyn std::error::Error>> {
    let config = aws_config::load_from_env().await;
    let dynamo_client = DynamoClient::new(&config);
    let resp =
        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()))
            .send()
            .instrument(DynamodbSpanBuilder::query("table_name").attribute(
                KeyValue::new(semconv::AWS_DYNAMODB_INDEX_NAME, "my_index"),
            ))
            .await?;
    println!("DynamoDB items: {:#?}", resp.items());
    Ok(resp.count())
}

Required Methods§

Source

fn instrument<'a>( self, span: impl Into<AwsSpanBuilder<'a>>, ) -> InstrumentedFuture<F, AwsSpan>

Instruments the future with an AWS span.

Creates an instrumented future that will automatically start a span when polled and properly handle the result when the future completes.

§Arguments
  • span - A span builder or span to use for instrumentation
§Returns

An instrumented future that will record AWS operation details

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.

Implementors§

Source§

impl<T, E, F> AwsInstrument<T, E, F> for F
where T: RequestId, E: RequestId + Error, F: Future<Output = Result<T, E>>,