From d44458f4029458402e402294e35530c23ee45b10 Mon Sep 17 00:00:00 2001 From: Robert Collins Date: Mon, 11 Mar 2024 18:04:51 +0100 Subject: [PATCH] Support opentelemetry 0.22 (#118) --- .github/workflows/ci.yml | 3 +++ reqwest-tracing/Cargo.toml | 3 +++ reqwest-tracing/README.md | 2 +- reqwest-tracing/src/lib.rs | 1 + reqwest-tracing/src/middleware.rs | 1 + reqwest-tracing/src/otel.rs | 25 +++++++++++++++++++++---- 6 files changed, 30 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8808888..dbdb518 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,6 +21,7 @@ jobs: - opentelemetry_0_19 - opentelemetry_0_20 - opentelemetry_0_21 + - opentelemetry_0_22 steps: - name: Checkout repository uses: actions/checkout@v2 @@ -69,6 +70,7 @@ jobs: - opentelemetry_0_19 - opentelemetry_0_20 - opentelemetry_0_21 + - opentelemetry_0_22 steps: - name: Checkout repository uses: actions/checkout@v2 @@ -100,6 +102,7 @@ jobs: - opentelemetry_0_19 - opentelemetry_0_20 - opentelemetry_0_21 + - opentelemetry_0_22 steps: - name: Checkout repository uses: actions/checkout@v2 diff --git a/reqwest-tracing/Cargo.toml b/reqwest-tracing/Cargo.toml index e5b7bf0..0086a9a 100644 --- a/reqwest-tracing/Cargo.toml +++ b/reqwest-tracing/Cargo.toml @@ -19,6 +19,7 @@ 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"] opentelemetry_0_21 = ["opentelemetry_0_21_pkg", "tracing-opentelemetry_0_22_pkg"] +opentelemetry_0_22 = ["opentelemetry_0_22_pkg", "tracing-opentelemetry_0_23_pkg"] [dependencies] @@ -40,6 +41,7 @@ opentelemetry_0_18_pkg = { package = "opentelemetry", version = "0.18.0", option opentelemetry_0_19_pkg = { package = "opentelemetry", version = "0.19.0", optional = true } opentelemetry_0_20_pkg = { package = "opentelemetry", version = "0.20.0", optional = true } opentelemetry_0_21_pkg = { package = "opentelemetry", version = "0.21.0", optional = true } +opentelemetry_0_22_pkg = { package = "opentelemetry", version = "0.22.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 } @@ -49,6 +51,7 @@ tracing-opentelemetry_0_18_pkg = { package = "tracing-opentelemetry", version = 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 } tracing-opentelemetry_0_22_pkg = { package = "tracing-opentelemetry", version = "0.22.0", optional = true } +tracing-opentelemetry_0_23_pkg = { package = "tracing-opentelemetry", version = "0.23.0", optional = true } [target.'cfg(target_arch = "wasm32")'.dependencies] getrandom = { version = "0.2.0", features = ["js"] } diff --git a/reqwest-tracing/README.md b/reqwest-tracing/README.md index 9d71961..3bc1ca4 100644 --- a/reqwest-tracing/README.md +++ b/reqwest-tracing/README.md @@ -92,7 +92,7 @@ an opentelemetry version feature: reqwest-tracing = { version = "0.3.1", features = ["opentelemetry_0_18"] } ``` -Available opentelemetry features are `opentelemetry_0_21`, `opentelemetry_0_20`, +Available opentelemetry features are `opentelemetry_0_22`, `opentelemetry_0_21`, `opentelemetry_0_20`, `opentelemetry_0_19`, `opentelemetry_0_18`, `opentelemetry_0_17`, `opentelemetry_0_16`, `opentelemetry_0_15`, `opentelemetry_0_14` and `opentelemetry_0_13`. diff --git a/reqwest-tracing/src/lib.rs b/reqwest-tracing/src/lib.rs index 9ce1189..339e62b 100644 --- a/reqwest-tracing/src/lib.rs +++ b/reqwest-tracing/src/lib.rs @@ -93,6 +93,7 @@ mod middleware; feature = "opentelemetry_0_19", feature = "opentelemetry_0_20", feature = "opentelemetry_0_21", + feature = "opentelemetry_0_22", ))] mod otel; mod reqwest_otel_span_builder; diff --git a/reqwest-tracing/src/middleware.rs b/reqwest-tracing/src/middleware.rs index cf7f3cd..345c667 100644 --- a/reqwest-tracing/src/middleware.rs +++ b/reqwest-tracing/src/middleware.rs @@ -55,6 +55,7 @@ where feature = "opentelemetry_0_19", feature = "opentelemetry_0_20", feature = "opentelemetry_0_21", + feature = "opentelemetry_0_22", ))] 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 17f5904..477be7c 100644 --- a/reqwest-tracing/src/otel.rs +++ b/reqwest-tracing/src/otel.rs @@ -30,6 +30,9 @@ use opentelemetry_0_20_pkg as opentelemetry; #[cfg(feature = "opentelemetry_0_21")] use opentelemetry_0_21_pkg as opentelemetry; +#[cfg(feature = "opentelemetry_0_22")] +use opentelemetry_0_22_pkg as opentelemetry; + #[cfg(feature = "opentelemetry_0_13")] pub use tracing_opentelemetry_0_12_pkg as tracing_opentelemetry; @@ -57,6 +60,9 @@ pub use tracing_opentelemetry_0_20_pkg as tracing_opentelemetry; #[cfg(feature = "opentelemetry_0_21")] pub use tracing_opentelemetry_0_22_pkg as tracing_opentelemetry; +#[cfg(feature = "opentelemetry_0_22")] +pub use tracing_opentelemetry_0_23_pkg as tracing_opentelemetry; + use opentelemetry::global; use opentelemetry::propagation::Injector; use tracing_opentelemetry::OpenTelemetrySpanExt; @@ -102,10 +108,12 @@ mod test { use super::*; use crate::{DisableOtelPropagation, TracingMiddleware}; - #[cfg(not(feature = "opentelemetry_0_21"))] + #[cfg(not(any(feature = "opentelemetry_0_22", feature = "opentelemetry_0_21")))] use opentelemetry::sdk::propagation::TraceContextPropagator; #[cfg(feature = "opentelemetry_0_21")] use opentelemetry_sdk_0_21::propagation::TraceContextPropagator; + #[cfg(feature = "opentelemetry_0_22")] + use opentelemetry_sdk_0_22::propagation::TraceContextPropagator; use reqwest::Response; use reqwest_middleware::{ClientBuilder, ClientWithMiddleware, Extension}; use tracing::{info_span, Instrument, Level}; @@ -129,17 +137,22 @@ mod test { TELEMETRY.get_or_init(|| { #[cfg(all( not(feature = "opentelemetry_0_20"), - not(feature = "opentelemetry_0_21") + not(feature = "opentelemetry_0_21"), + not(feature = "opentelemetry_0_22") ))] let tracer = opentelemetry::sdk::export::trace::stdout::new_pipeline() .with_writer(std::io::sink()) .install_simple(); - #[cfg(any(feature = "opentelemetry_0_20", feature = "opentelemetry_0_21"))] + #[cfg(any( + feature = "opentelemetry_0_20", + feature = "opentelemetry_0_21", + feature = "opentelemetry_0_22" + ))] let tracer = { use opentelemetry::trace::TracerProvider; #[cfg(feature = "opentelemetry_0_20")] use opentelemetry_stdout_0_1::SpanExporterBuilder; - #[cfg(feature = "opentelemetry_0_21")] + #[cfg(any(feature = "opentelemetry_0_21", feature = "opentelemetry_0_22"))] use opentelemetry_stdout_0_2::SpanExporterBuilder; let exporter = SpanExporterBuilder::default() @@ -154,6 +167,10 @@ mod test { let provider = opentelemetry_sdk_0_21::trace::TracerProvider::builder() .with_simple_exporter(exporter) .build(); + #[cfg(feature = "opentelemetry_0_22")] + let provider = opentelemetry_sdk_0_22::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