Crate opentelemetry_aws
source · [−]Expand description
This crate provides unofficial integration with AWS services.
Components
As for now, the only components provided in this crate is AWS X-Ray propagator.
AWS X-Ray Propagator
This propagator helps propagate tracing information from upstream services to downstream services.
Quick start
use opentelemetry::global;
use opentelemetry_aws::trace::XrayPropagator;
use opentelemetry::{sdk::export::trace::stdout, trace::Tracer};
use opentelemetry_http::HeaderInjector;
#[tokio::main]
async fn main() -> std::result::Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
// Set the global propagator to X-Ray propagator
global::set_text_map_propagator(XrayPropagator::default());
let tracer = stdout::new_pipeline().install_simple();
let mut req = hyper::Request::builder().uri("http://127.0.0.1:3000");
tracer.in_span("doing_work", |cx| {
// Send request to downstream services.
// Build request
global::get_text_map_propagator(|propagator| {
// Set X-Ray tracing header in request object `req`
propagator.inject_context(&cx, &mut HeaderInjector(req.headers_mut().unwrap()));
println!("Headers: {:?}", req.headers_ref());
})
});
Ok(())
}
A more detailed example can be found in opentelemetry-rust repo
Re-exports
pub use trace::XrayPropagator;