pub trait AwsBuilderInstrument<'a>where
Self: Sized,{
// Required method
fn build_aws_span(&self) -> AwsSpanBuilder<'a>;
// Provided method
fn instrument(self) -> InstrumentedFluentBuilder<'a, Self> { ... }
}
Expand description
A trait for AWS service clients that can be instrumented with OpenTelemetry tracing.
This trait provides methods to build spans for AWS operations and instrument the fluent builders returned by AWS SDK operations. The instrumentation automatically extracts both input attributes (from the fluent builder configuration) and output attributes (from the operation response) following OpenTelemetry semantic conventions.
§Example
use aws_sdk_dynamodb::{Client as DynamoClient, types::AttributeValue};
use telemetry_rust::middleware::aws::AwsBuilderInstrument;
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()))
.consistent_read(true)
.projection_expression("id,name")
.instrument()
.send()
.await?;
// Automatically extracts span attributes from the builder:
// - aws.dynamodb.table_name: "table_name"
// - aws.dynamodb.index_name: "my_index"
// - aws.dynamodb.consistent_read: true
// - aws.dynamodb.projection: "id,name"
//
// And from the AWS output:
// - aws.dynamodb.count: number of items returned
// - aws.dynamodb.scanned_count: number of items scanned
println!("DynamoDB items: {:#?}", resp.items());
Ok(resp.count())
}
§Comparison with Manual Instrumentation
This trait provides automatic instrumentation as an alternative to manual instrumentation
using AwsInstrument
. The automatic approach extracts attributes based on OpenTelemetry
semantic conventions without requiring explicit attribute specification:
// Automatic instrumentation (recommended)
let _ = dynamo_client
.get_item()
.table_name("table")
.instrument() // All attributes extracted automatically
.send()
.await?;
// Manual instrumentation (more control, more verbose)
let _ = dynamo_client
.get_item()
.table_name("table")
.send()
.instrument(DynamodbSpanBuilder::get_item("table"))
.await?;
Required Methods§
Sourcefn build_aws_span(&self) -> AwsSpanBuilder<'a>
fn build_aws_span(&self) -> AwsSpanBuilder<'a>
Builds an AWS span for the specific operation represented by this builder.
Returns an AwsSpanBuilder
that contains the necessary span attributes
and metadata for the AWS operation.
Provided Methods§
Sourcefn instrument(self) -> InstrumentedFluentBuilder<'a, Self>
fn instrument(self) -> InstrumentedFluentBuilder<'a, Self>
Instruments this fluent builder with OpenTelemetry tracing.
Returns an InstrumentedFluentBuilder
that will automatically create
and manage spans when the operation is executed.
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.