opentelemetry-aws 0.21.0

AWS exporters and propagators for OpenTelemetry
Documentation

OpenTelemetry AWS

OpenTelemetry — An observability framework for cloud-native software.

Status
Stability beta
Owners Jonathan Lee, Chinmay Chahar

Additional types for exporting OpenTelemetry data to AWS.

Crates.io: opentelemetry-aws Documentation Slack

Overview

OpenTelemetry is a collection of tools, APIs, and SDKs used to instrument, generate, collect, and export telemetry data (metrics, logs, and traces) for analysis in order to understand your software's performance and behavior. This crate provides additional propagators and exporters for sending telemetry data to AWS's telemetry platform.

Components

Component Feature Description
X-Ray Propagator trace Propagates trace context using the X-Amzn-Trace-Id header
X-Ray ID Generator trace Generates X-Ray-compatible trace and span IDs (time-based trace IDs)
X-Ray Exporter xray-exporter Exports OpenTelemetry spans as X-Ray segment documents
Lambda Resource Detector detector-aws-lambda Detects AWS Lambda resource attributes from the environment
EC2 Resource Detector detector-aws-ec2 Detects AWS EC2 resource attributes via IMDSv2
ECS Resource Detector detector-aws-ecs Detects AWS ECS resource attributes via the task and container metadata endpoints
EKS Resource Detector detector-aws-eks Detects AWS EKS resource attributes via the Kubernetes service-account mount and IMDSv2

Quick Start

Basic setup forwarding Segments to the local X-Ray daemon (requires xray-daemon-client feature):

use opentelemetry_aws::{
    trace::XrayIdGenerator,
    xray_exporter::{XrayExporter, daemon_client::XrayDaemonClient},
};
use opentelemetry_sdk::trace::SdkTracerProvider;
use opentelemetry::global;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Create a client that sends to the X-Ray daemon on localhost:2000 (UDP)
    let daemon_addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::LOCALHOST), 2000);
    let client = XrayDaemonClient::new(daemon_addr)?;

    // Create the exporter
    let exporter = XrayExporter::new(client);

    // Build and register the tracer provider
    let provider = SdkTracerProvider::builder()
        .with_id_generator(XrayIdGenerator::default())
        .with_batch_exporter(exporter)
        .build();

    global::set_tracer_provider(provider);
    Ok(())
}

Feature Flags

Feature Default Description
trace Yes X-Ray propagator and ID generator
internal-logs Yes Internal instrumentation via the tracing crate
xray-exporter No X-Ray span exporter with SegmentTranslator and SegmentDocumentExporter trait
xray-daemon-client No XrayDaemonClient — UDP client for the X-Ray daemon
xray-stdout-client No StdoutClient — writes segment documents to stdout (useful for debugging)
xray-subsegment-nesting No Enables subsegment nesting within parent segments during translation
detector-aws-lambda No AWS Lambda resource detector
detector-aws-ec2 No AWS EC2 resource detector
detector-aws-ecs No AWS ECS resource detector
detector-aws-eks No AWS EKS resource detector