Skip to content

Commit

Permalink
Support opentelemetry 0.22 (#118)
Browse files Browse the repository at this point in the history
  • Loading branch information
rbtcollins authored Mar 11, 2024
1 parent b53d355 commit d44458f
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions reqwest-tracing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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 }
Expand All @@ -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"] }
Expand Down
2 changes: 1 addition & 1 deletion reqwest-tracing/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.

Expand Down
1 change: 1 addition & 0 deletions reqwest-tracing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions reqwest-tracing/src/middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<crate::DisableOtelPropagation>() {
// Adds tracing headers to the given request to propagate the OpenTelemetry context to downstream revivers of the request.
Expand Down
25 changes: 21 additions & 4 deletions reqwest-tracing/src/otel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Check failure on line 116 in reqwest-tracing/src/otel.rs

View workflow job for this annotation

GitHub Actions / Clippy (opentelemetry_0_22)

failed to resolve: use of undeclared crate or module `opentelemetry_sdk_0_22`

Check failure on line 116 in reqwest-tracing/src/otel.rs

View workflow job for this annotation

GitHub Actions / Test Suite (opentelemetry_0_22)

failed to resolve: use of undeclared crate or module `opentelemetry_sdk_0_22`
use reqwest::Response;
use reqwest_middleware::{ClientBuilder, ClientWithMiddleware, Extension};
use tracing::{info_span, Instrument, Level};
Expand All @@ -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;

Check failure on line 152 in reqwest-tracing/src/otel.rs

View workflow job for this annotation

GitHub Actions / Clippy (opentelemetry_0_22)

unused import: `opentelemetry::trace::TracerProvider`

Check warning on line 152 in reqwest-tracing/src/otel.rs

View workflow job for this annotation

GitHub Actions / Test Suite (opentelemetry_0_22)

unused import: `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()
Expand All @@ -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()

Check failure on line 171 in reqwest-tracing/src/otel.rs

View workflow job for this annotation

GitHub Actions / Clippy (opentelemetry_0_22)

failed to resolve: use of undeclared crate or module `opentelemetry_sdk_0_22`

Check failure on line 171 in reqwest-tracing/src/otel.rs

View workflow job for this annotation

GitHub Actions / Test Suite (opentelemetry_0_22)

failed to resolve: use of undeclared crate or module `opentelemetry_sdk_0_22`
.with_simple_exporter(exporter)
.build();
let tracer = provider.versioned_tracer("reqwest", None::<&str>, None::<&str>, None);
let _ = global::set_tracer_provider(provider);
tracer
Expand Down

0 comments on commit d44458f

Please sign in to comment.