diff --git a/examples/aws-xray/src/client.rs b/examples/aws-xray/src/client.rs index a74c3eb6943..48680d6a7e3 100644 --- a/examples/aws-xray/src/client.rs +++ b/examples/aws-xray/src/client.rs @@ -2,11 +2,11 @@ use hyper::{body::Body, Client}; use opentelemetry::api::{Context, TraceContextExt, Tracer}; use opentelemetry::{ api, exporter::trace::stdout, global, sdk, sdk::id_generator::aws::XrayIdGenerator, + sdk::propagator::aws::XrayPropagator, }; -use opentelemetry_contrib::XrayTraceContextPropagator; fn init_tracer() -> (sdk::Tracer, stdout::Uninstall) { - global::set_text_map_propagator(XrayTraceContextPropagator::new()); + global::set_text_map_propagator(XrayPropagator::new()); // Install stdout exporter pipeline to be able to retrieve the collected spans. // For the demonstration, use `Sampler::AlwaysOn` sampler to sample all traces. In a production diff --git a/examples/aws-xray/src/server.rs b/examples/aws-xray/src/server.rs index da548d82618..b4901441295 100644 --- a/examples/aws-xray/src/server.rs +++ b/examples/aws-xray/src/server.rs @@ -5,8 +5,8 @@ use opentelemetry::{ exporter::trace::stdout, global, sdk, sdk::id_generator::aws::XrayIdGenerator, + sdk::propagator::aws::XrayPropagator, }; -use opentelemetry_contrib::XrayTraceContextPropagator; use std::{convert::Infallible, net::SocketAddr}; async fn handle(req: Request) -> Result, Infallible> { @@ -29,7 +29,7 @@ async fn handle(req: Request) -> Result, Infallible> { } fn init_tracer() -> (sdk::Tracer, stdout::Uninstall) { - global::set_text_map_propagator(XrayTraceContextPropagator::new()); + global::set_text_map_propagator(XrayPropagator::new()); // Install stdout exporter pipeline to be able to retrieve the collected spans. // For the demonstration, use `Sampler::AlwaysOn` sampler to sample all traces. In a production diff --git a/opentelemetry-contrib/src/id_generator/mod.rs b/opentelemetry-contrib/src/id_generator/mod.rs deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/opentelemetry-contrib/src/lib.rs b/opentelemetry-contrib/src/lib.rs index e12df27c94f..c2e799b1090 100644 --- a/opentelemetry-contrib/src/lib.rs +++ b/opentelemetry-contrib/src/lib.rs @@ -4,14 +4,5 @@ //! some users. //! //! Typically, those include vendor specific propagators. - -mod trace_propagator; - #[cfg(feature = "datadog")] pub mod datadog; - -pub use trace_propagator::{ - aws_xray_propagator::XrayTraceContextPropagator, - b3_propagator::{B3Encoding, B3Propagator}, - jaeger_propagator::JaegerPropagator, -}; diff --git a/opentelemetry-contrib/src/trace_propagator/mod.rs b/opentelemetry-contrib/src/trace_propagator/mod.rs deleted file mode 100644 index fb6b1a79a02..00000000000 --- a/opentelemetry-contrib/src/trace_propagator/mod.rs +++ /dev/null @@ -1,7 +0,0 @@ -//! External context propagators -//! -//! - -pub mod aws_xray_propagator; -pub mod b3_propagator; -pub mod jaeger_propagator; diff --git a/opentelemetry-contrib/src/trace_propagator/aws_xray_propagator.rs b/src/sdk/trace/propagator/aws.rs similarity index 90% rename from opentelemetry-contrib/src/trace_propagator/aws_xray_propagator.rs rename to src/sdk/trace/propagator/aws.rs index 3e011ec7a30..52396e9c2f7 100644 --- a/opentelemetry-contrib/src/trace_propagator/aws_xray_propagator.rs +++ b/src/sdk/trace/propagator/aws.rs @@ -1,7 +1,26 @@ -use opentelemetry::api::trace::span_context::TraceState; -use opentelemetry::api::{ - Context, Extractor, FieldIter, Injector, SpanContext, SpanId, TextMapFormat, TraceContextExt, - TraceId, TRACE_FLAG_DEFERRED, TRACE_FLAG_NOT_SAMPLED, TRACE_FLAG_SAMPLED, +//! # AWS X-Ray Trace Propagator +//! +//! Extracts and injects values to/from the `x-amzn-trace-id` header. Converting between +//! OpenTelemetry [SpanContext][otel-spec] and [X-Ray Trace format][xray-trace-id]. +//! +//! For details on the [`x-amzn-trace-id` header][xray-header] see the AWS X-Ray Docs. +//! +//! ## Example +//! +//! ``` +//! use opentelemetry::global; +//! use opentelemetry::sdk::propagator::aws::XrayPropagator; +//! +//! global::set_text_map_propagator(XrayPropagator::default()); +//! ``` +//! +//! [otel-spec]: https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/api.md#spancontext +//! [xray-trace-id]: https://docs.aws.amazon.com/xray/latest/devguide/xray-api-sendingdata.html#xray-api-traceids +//! [xray-header]: https://docs.aws.amazon.com/xray/latest/devguide/xray-concepts.html#xray-concepts-tracingheader +use crate::api::{ + trace::span_context::TraceState, Context, Extractor, FieldIter, Injector, SpanContext, SpanId, + TextMapFormat, TraceContextExt, TraceId, TRACE_FLAG_DEFERRED, TRACE_FLAG_NOT_SAMPLED, + TRACE_FLAG_SAMPLED, }; const AWS_XRAY_TRACE_HEADER: &str = "x-amzn-trace-id"; @@ -18,34 +37,16 @@ lazy_static::lazy_static! { static ref AWS_XRAY_HEADER_FIELD: [String; 1] = [AWS_XRAY_TRACE_HEADER.to_string()]; } -/// # AWS X-Ray Trace Propagator -/// -/// Extracts and injects values to/from the `x-amzn-trace-id` header. Converting between -/// OpenTelemetry [SpanContext][otel-spec] and [X-Ray Trace format][xray-trace-id]. -/// -/// For details on the [`x-amzn-trace-id` header][xray-header] see the AWS X-Ray Docs. -/// -/// ## Example -/// -/// ``` -/// extern crate opentelemetry; -/// use opentelemetry::global; -/// use opentelemetry_contrib::XrayTraceContextPropagator; -/// -/// global::set_text_map_propagator(XrayTraceContextPropagator::default()); -/// ``` -/// -/// [otel-spec]: https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/trace/api.md#spancontext -/// [xray-trace-id]: https://docs.aws.amazon.com/xray/latest/devguide/xray-api-sendingdata.html#xray-api-traceids -/// [xray-header]: https://docs.aws.amazon.com/xray/latest/devguide/xray-concepts.html#xray-concepts-tracingheader +/// Extracts and injects `SpanContext`s into `Extractor`s or `Injector`s using AWS X-Ray header format. #[derive(Clone, Debug, Default)] -pub struct XrayTraceContextPropagator { +pub struct XrayPropagator { _private: (), } -impl XrayTraceContextPropagator { +impl XrayPropagator { + /// Creates a new `XrayTraceContextPropagator`. pub fn new() -> Self { - XrayTraceContextPropagator::default() + XrayPropagator::default() } fn extract_span_context(&self, extractor: &dyn Extractor) -> Result { @@ -102,7 +103,7 @@ impl XrayTraceContextPropagator { } } -impl TextMapFormat for XrayTraceContextPropagator { +impl TextMapFormat for XrayPropagator { fn inject_context(&self, cx: &Context, injector: &mut dyn Injector) { let span_context: SpanContext = cx.span().span_context(); if span_context.is_valid() { @@ -233,8 +234,8 @@ fn title_case(s: &str) -> String { #[cfg(test)] mod tests { use super::*; - use opentelemetry::api; - use opentelemetry::api::trace::span_context::TraceState; + use crate::api; + use crate::api::trace::span_context::TraceState; use std::collections::HashMap; use std::str::FromStr; use std::time::SystemTime; @@ -278,7 +279,7 @@ mod tests { .into_iter() .collect(); - let propagator = XrayTraceContextPropagator::default(); + let propagator = XrayPropagator::default(); let context = propagator.extract(&map); assert_eq!(context.remote_span_context(), Some(&expected)); } @@ -287,7 +288,7 @@ mod tests { #[test] fn test_extract_empty() { let map: HashMap = HashMap::new(); - let propagator = XrayTraceContextPropagator::default(); + let propagator = XrayPropagator::default(); let context = propagator.extract(&map); assert_eq!( context.remote_span_context(), @@ -320,7 +321,7 @@ mod tests { #[test] fn test_inject() { - let propagator = XrayTraceContextPropagator::default(); + let propagator = XrayPropagator::default(); for (header_value, span_context) in inject_test_data() { let mut injector: HashMap = HashMap::new(); propagator.inject_context( diff --git a/opentelemetry-contrib/src/trace_propagator/b3_propagator.rs b/src/sdk/trace/propagator/b3.rs similarity index 98% rename from opentelemetry-contrib/src/trace_propagator/b3_propagator.rs rename to src/sdk/trace/propagator/b3.rs index d1f67a81d40..1998b68620f 100644 --- a/opentelemetry-contrib/src/trace_propagator/b3_propagator.rs +++ b/src/sdk/trace/propagator/b3.rs @@ -13,10 +13,12 @@ //! //! If `inject_encoding` is set to `B3Encoding::SingleHeader` then `b3` header is used to inject //! and extract. Otherwise, separate headers are used to inject and extract. -use opentelemetry::api::trace::span_context::TraceState; -use opentelemetry::{ +use crate::{ api, - api::{context::propagation::text_propagator::FieldIter, TraceContextExt, TRACE_FLAG_DEFERRED}, + api::{ + context::propagation::text_propagator::FieldIter, trace::span_context::TraceState, + TraceContextExt, TRACE_FLAG_DEFERRED, + }, }; static B3_SINGLE_HEADER: &str = "b3"; @@ -310,10 +312,8 @@ impl api::TextMapFormat for B3Propagator { #[cfg(test)] mod tests { use super::*; - use opentelemetry::api::trace::span_context::{SpanId, TraceId, TRACE_FLAG_NOT_SAMPLED}; - use opentelemetry::api::{ - TextMapFormat, TRACE_FLAG_DEBUG, TRACE_FLAG_DEFERRED, TRACE_FLAG_SAMPLED, - }; + use crate::api::trace::span_context::{SpanId, TraceId, TRACE_FLAG_NOT_SAMPLED}; + use crate::api::{TextMapFormat, TRACE_FLAG_DEBUG, TRACE_FLAG_DEFERRED, TRACE_FLAG_SAMPLED}; use std::collections::HashMap; const TRACE_ID_STR: &str = "4bf92f3577b34da6a3ce929d0e0e4736"; diff --git a/opentelemetry-contrib/src/trace_propagator/jaeger_propagator.rs b/src/sdk/trace/propagator/jaeger.rs similarity index 97% rename from opentelemetry-contrib/src/trace_propagator/jaeger_propagator.rs rename to src/sdk/trace/propagator/jaeger.rs index b29a6f215b6..d05c0982fbe 100644 --- a/opentelemetry-contrib/src/trace_propagator/jaeger_propagator.rs +++ b/src/sdk/trace/propagator/jaeger.rs @@ -6,8 +6,8 @@ //! //! [`Jaeger documentation`]: https://www.jaegertracing.io/docs/1.18/client-libraries/#propagation-format -use opentelemetry::api::trace::span_context::TraceState; -use opentelemetry::api::{ +use crate::api::trace::span_context::TraceState; +use crate::api::{ Context, Extractor, FieldIter, Injector, SpanContext, SpanId, TextMapFormat, TraceContextExt, TraceId, TRACE_FLAG_DEBUG, TRACE_FLAG_NOT_SAMPLED, TRACE_FLAG_SAMPLED, }; @@ -171,13 +171,13 @@ impl TextMapFormat for JaegerPropagator { #[cfg(test)] mod tests { - use crate::trace_propagator::jaeger_propagator::{JaegerPropagator, JAEGER_HEADER}; - use opentelemetry::api; - use opentelemetry::api::trace::span_context::TraceState; - use opentelemetry::api::{ + use crate::api; + use crate::api::trace::span_context::TraceState; + use crate::api::{ Context, Injector, Span, SpanContext, SpanId, TextMapFormat, TraceContextExt, TraceId, TRACE_FLAG_DEBUG, TRACE_FLAG_NOT_SAMPLED, TRACE_FLAG_SAMPLED, }; + use crate::sdk::propagator::jaeger::{JaegerPropagator, JAEGER_HEADER}; use std::collections::HashMap; use std::time::SystemTime; diff --git a/src/sdk/trace/propagator/mod.rs b/src/sdk/trace/propagator/mod.rs index 70bdac9fefe..4bddd4fdb03 100644 --- a/src/sdk/trace/propagator/mod.rs +++ b/src/sdk/trace/propagator/mod.rs @@ -6,4 +6,7 @@ //! more information see the [OpenTelemetry Spec]['spec']. //! //! ['spec']: https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/context/api-propagators.md#overview +pub mod aws; +pub mod b3; +pub mod jaeger; pub mod w3;