Support opentelemetry 0.22 (#118)

pull/124/head
Robert Collins 2024-03-11 18:04:51 +01:00 committed by GitHub
parent b53d355aea
commit d44458f402
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 30 additions and 5 deletions

View File

@ -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

View File

@ -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"] }

View File

@ -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`.

View File

@ -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;

View File

@ -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.

View File

@ -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