From 7b3493d96c92ef2f5fc855fb0a921772f1b56ffe Mon Sep 17 00:00:00 2001 From: Conrad Ludgate Date: Wed, 23 Aug 2023 11:49:15 +0100 Subject: [PATCH] add opentelementry 0.20 support (#101) --- .github/workflows/ci.yml | 4 ++++ reqwest-tracing/Cargo.toml | 5 +++++ reqwest-tracing/src/lib.rs | 1 + reqwest-tracing/src/middleware.rs | 1 + reqwest-tracing/src/otel.rs | 20 ++++++++++++++++++++ 5 files changed, 31 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6e6c697..bdd0217 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,6 +19,7 @@ jobs: - opentelemetry_0_17 - opentelemetry_0_18 - opentelemetry_0_19 + - opentelemetry_0_20 steps: - name: Checkout repository uses: actions/checkout@v2 @@ -46,6 +47,7 @@ jobs: - opentelemetry_0_17 - opentelemetry_0_18 - opentelemetry_0_19 + - opentelemetry_0_20 steps: - name: Checkout repository uses: actions/checkout@v2 @@ -93,6 +95,7 @@ jobs: - opentelemetry_0_17 - opentelemetry_0_18 - opentelemetry_0_19 + - opentelemetry_0_20 steps: - name: Checkout repository uses: actions/checkout@v2 @@ -122,6 +125,7 @@ jobs: - opentelemetry_0_17 - opentelemetry_0_18 - opentelemetry_0_19 + - opentelemetry_0_20 steps: - name: Checkout repository uses: actions/checkout@v2 diff --git a/reqwest-tracing/Cargo.toml b/reqwest-tracing/Cargo.toml index c5c85f7..cda79ef 100644 --- a/reqwest-tracing/Cargo.toml +++ b/reqwest-tracing/Cargo.toml @@ -17,6 +17,7 @@ opentelemetry_0_16 = ["opentelemetry_0_16_pkg", "tracing-opentelemetry_0_16_pkg" opentelemetry_0_17 = ["opentelemetry_0_17_pkg", "tracing-opentelemetry_0_17_pkg"] opentelemetry_0_18 = ["opentelemetry_0_18_pkg", "tracing-opentelemetry_0_18_pkg"] opentelemetry_0_19 = ["opentelemetry_0_19_pkg", "tracing-opentelemetry_0_19_pkg"] +opentelemetry_0_20 = ["opentelemetry_0_20_pkg", "tracing-opentelemetry_0_20_pkg"] [dependencies] @@ -36,6 +37,7 @@ opentelemetry_0_16_pkg = { package = "opentelemetry", version = "0.16.0", option opentelemetry_0_17_pkg = { package = "opentelemetry", version = "0.17.0", optional = true } opentelemetry_0_18_pkg = { package = "opentelemetry", version = "0.18.0", optional = true } opentelemetry_0_19_pkg = { package = "opentelemetry", version = "0.19.0", optional = true } +opentelemetry_0_20_pkg = { package = "opentelemetry", version = "0.20.0", optional = true } tracing-opentelemetry_0_12_pkg = { package = "tracing-opentelemetry",version = "0.12.0", optional = true } tracing-opentelemetry_0_13_pkg = { package = "tracing-opentelemetry", version = "0.13.0", optional = true } tracing-opentelemetry_0_14_pkg = { package = "tracing-opentelemetry",version = "0.14.0", optional = true } @@ -43,6 +45,7 @@ tracing-opentelemetry_0_16_pkg = { package = "tracing-opentelemetry",version = " tracing-opentelemetry_0_17_pkg = { package = "tracing-opentelemetry",version = "0.17.0", optional = true } tracing-opentelemetry_0_18_pkg = { package = "tracing-opentelemetry",version = "0.18.0", optional = true } tracing-opentelemetry_0_19_pkg = { package = "tracing-opentelemetry",version = "0.19.0", optional = true } +tracing-opentelemetry_0_20_pkg = { package = "tracing-opentelemetry",version = "0.20.0", optional = true } [target.'cfg(target_arch = "wasm32")'.dependencies] getrandom = { version = "0.2.0", features = ["js"] } @@ -52,3 +55,5 @@ tokio = { version = "1.0.0", features = ["macros"] } tracing_subscriber_0_2 = { package = "tracing-subscriber", version = "0.2.0" } tracing_subscriber_0_3 = { package = "tracing-subscriber", version = "0.3.0" } wiremock = "0.5.0" + +opentelemetry-stdout = { version = "0.1.0", features = ["trace"] } diff --git a/reqwest-tracing/src/lib.rs b/reqwest-tracing/src/lib.rs index bcb25d8..205c03b 100644 --- a/reqwest-tracing/src/lib.rs +++ b/reqwest-tracing/src/lib.rs @@ -91,6 +91,7 @@ mod middleware; feature = "opentelemetry_0_17", feature = "opentelemetry_0_18", feature = "opentelemetry_0_19", + feature = "opentelemetry_0_20", ))] mod otel; mod reqwest_otel_span_builder; diff --git a/reqwest-tracing/src/middleware.rs b/reqwest-tracing/src/middleware.rs index 0d5283b..4b7a057 100644 --- a/reqwest-tracing/src/middleware.rs +++ b/reqwest-tracing/src/middleware.rs @@ -53,6 +53,7 @@ where feature = "opentelemetry_0_17", feature = "opentelemetry_0_18", feature = "opentelemetry_0_19", + feature = "opentelemetry_0_20", ))] let req = if !extensions.contains::() { // Adds tracing headers to the given request to propagate the OpenTelemetry context to downstream revivers of the request. diff --git a/reqwest-tracing/src/otel.rs b/reqwest-tracing/src/otel.rs index 616ae22..4bfb546 100644 --- a/reqwest-tracing/src/otel.rs +++ b/reqwest-tracing/src/otel.rs @@ -24,6 +24,9 @@ use opentelemetry_0_18_pkg as opentelemetry; #[cfg(feature = "opentelemetry_0_19")] use opentelemetry_0_19_pkg as opentelemetry; +#[cfg(feature = "opentelemetry_0_20")] +use opentelemetry_0_20_pkg as opentelemetry; + #[cfg(feature = "opentelemetry_0_13")] pub use tracing_opentelemetry_0_12_pkg as tracing_opentelemetry; @@ -45,6 +48,9 @@ pub use tracing_opentelemetry_0_18_pkg as tracing_opentelemetry; #[cfg(feature = "opentelemetry_0_19")] pub use tracing_opentelemetry_0_19_pkg as tracing_opentelemetry; +#[cfg(feature = "opentelemetry_0_20")] +pub use tracing_opentelemetry_0_20_pkg as tracing_opentelemetry; + use opentelemetry::global; use opentelemetry::propagation::Injector; use tracing_opentelemetry::OpenTelemetrySpanExt; @@ -112,9 +118,23 @@ mod test { static TELEMETRY: OnceLock<()> = OnceLock::new(); TELEMETRY.get_or_init(|| { + #[cfg(not(feature = "opentelemetry_0_20"))] let tracer = opentelemetry::sdk::export::trace::stdout::new_pipeline() .with_writer(std::io::sink()) .install_simple(); + #[cfg(feature = "opentelemetry_0_20")] + let tracer = { + use opentelemetry::trace::TracerProvider; + let exporter = opentelemetry_stdout::SpanExporterBuilder::default() + .with_writer(std::io::sink()) + .build(); + let provider = opentelemetry::sdk::trace::TracerProvider::builder() + .with_simple_exporter(exporter) + .build(); + let tracer = provider.versioned_tracer("reqwest", None::<&str>, None::<&str>, None); + let _ = global::set_tracer_provider(provider); + tracer + }; let telemetry = tracing_opentelemetry::layer().with_tracer(tracer); let subscriber = Registry::default() .with(