mirror of
https://github.com/TrueLayer/reqwest-middleware.git
synced 2024-12-27 03:16:32 +00:00
Support opentelemetry 0.22 (#118)
This commit is contained in:
parent
b53d355aea
commit
d44458f402
6 changed files with 30 additions and 5 deletions
3
.github/workflows/ci.yml
vendored
3
.github/workflows/ci.yml
vendored
|
@ -21,6 +21,7 @@ jobs:
|
||||||
- opentelemetry_0_19
|
- opentelemetry_0_19
|
||||||
- opentelemetry_0_20
|
- opentelemetry_0_20
|
||||||
- opentelemetry_0_21
|
- opentelemetry_0_21
|
||||||
|
- opentelemetry_0_22
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
|
@ -69,6 +70,7 @@ jobs:
|
||||||
- opentelemetry_0_19
|
- opentelemetry_0_19
|
||||||
- opentelemetry_0_20
|
- opentelemetry_0_20
|
||||||
- opentelemetry_0_21
|
- opentelemetry_0_21
|
||||||
|
- opentelemetry_0_22
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
|
@ -100,6 +102,7 @@ jobs:
|
||||||
- opentelemetry_0_19
|
- opentelemetry_0_19
|
||||||
- opentelemetry_0_20
|
- opentelemetry_0_20
|
||||||
- opentelemetry_0_21
|
- opentelemetry_0_21
|
||||||
|
- opentelemetry_0_22
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
|
|
|
@ -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_19 = ["opentelemetry_0_19_pkg", "tracing-opentelemetry_0_19_pkg"]
|
||||||
opentelemetry_0_20 = ["opentelemetry_0_20_pkg", "tracing-opentelemetry_0_20_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_21 = ["opentelemetry_0_21_pkg", "tracing-opentelemetry_0_22_pkg"]
|
||||||
|
opentelemetry_0_22 = ["opentelemetry_0_22_pkg", "tracing-opentelemetry_0_23_pkg"]
|
||||||
|
|
||||||
|
|
||||||
[dependencies]
|
[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_19_pkg = { package = "opentelemetry", version = "0.19.0", optional = true }
|
||||||
opentelemetry_0_20_pkg = { package = "opentelemetry", version = "0.20.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_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_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_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 }
|
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_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_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_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]
|
[target.'cfg(target_arch = "wasm32")'.dependencies]
|
||||||
getrandom = { version = "0.2.0", features = ["js"] }
|
getrandom = { version = "0.2.0", features = ["js"] }
|
||||||
|
|
|
@ -92,7 +92,7 @@ an opentelemetry version feature:
|
||||||
reqwest-tracing = { version = "0.3.1", features = ["opentelemetry_0_18"] }
|
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_19`, `opentelemetry_0_18`, `opentelemetry_0_17`, `opentelemetry_0_16`,
|
||||||
`opentelemetry_0_15`, `opentelemetry_0_14` and `opentelemetry_0_13`.
|
`opentelemetry_0_15`, `opentelemetry_0_14` and `opentelemetry_0_13`.
|
||||||
|
|
||||||
|
|
|
@ -93,6 +93,7 @@ mod middleware;
|
||||||
feature = "opentelemetry_0_19",
|
feature = "opentelemetry_0_19",
|
||||||
feature = "opentelemetry_0_20",
|
feature = "opentelemetry_0_20",
|
||||||
feature = "opentelemetry_0_21",
|
feature = "opentelemetry_0_21",
|
||||||
|
feature = "opentelemetry_0_22",
|
||||||
))]
|
))]
|
||||||
mod otel;
|
mod otel;
|
||||||
mod reqwest_otel_span_builder;
|
mod reqwest_otel_span_builder;
|
||||||
|
|
|
@ -55,6 +55,7 @@ where
|
||||||
feature = "opentelemetry_0_19",
|
feature = "opentelemetry_0_19",
|
||||||
feature = "opentelemetry_0_20",
|
feature = "opentelemetry_0_20",
|
||||||
feature = "opentelemetry_0_21",
|
feature = "opentelemetry_0_21",
|
||||||
|
feature = "opentelemetry_0_22",
|
||||||
))]
|
))]
|
||||||
let req = if !extensions.contains::<crate::DisableOtelPropagation>() {
|
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.
|
// Adds tracing headers to the given request to propagate the OpenTelemetry context to downstream revivers of the request.
|
||||||
|
|
|
@ -30,6 +30,9 @@ use opentelemetry_0_20_pkg as opentelemetry;
|
||||||
#[cfg(feature = "opentelemetry_0_21")]
|
#[cfg(feature = "opentelemetry_0_21")]
|
||||||
use opentelemetry_0_21_pkg as opentelemetry;
|
use opentelemetry_0_21_pkg as opentelemetry;
|
||||||
|
|
||||||
|
#[cfg(feature = "opentelemetry_0_22")]
|
||||||
|
use opentelemetry_0_22_pkg as opentelemetry;
|
||||||
|
|
||||||
#[cfg(feature = "opentelemetry_0_13")]
|
#[cfg(feature = "opentelemetry_0_13")]
|
||||||
pub use tracing_opentelemetry_0_12_pkg as tracing_opentelemetry;
|
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")]
|
#[cfg(feature = "opentelemetry_0_21")]
|
||||||
pub use tracing_opentelemetry_0_22_pkg as tracing_opentelemetry;
|
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::global;
|
||||||
use opentelemetry::propagation::Injector;
|
use opentelemetry::propagation::Injector;
|
||||||
use tracing_opentelemetry::OpenTelemetrySpanExt;
|
use tracing_opentelemetry::OpenTelemetrySpanExt;
|
||||||
|
@ -102,10 +108,12 @@ mod test {
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::{DisableOtelPropagation, TracingMiddleware};
|
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;
|
use opentelemetry::sdk::propagation::TraceContextPropagator;
|
||||||
#[cfg(feature = "opentelemetry_0_21")]
|
#[cfg(feature = "opentelemetry_0_21")]
|
||||||
use opentelemetry_sdk_0_21::propagation::TraceContextPropagator;
|
use opentelemetry_sdk_0_21::propagation::TraceContextPropagator;
|
||||||
|
#[cfg(feature = "opentelemetry_0_22")]
|
||||||
|
use opentelemetry_sdk_0_22::propagation::TraceContextPropagator;
|
||||||
use reqwest::Response;
|
use reqwest::Response;
|
||||||
use reqwest_middleware::{ClientBuilder, ClientWithMiddleware, Extension};
|
use reqwest_middleware::{ClientBuilder, ClientWithMiddleware, Extension};
|
||||||
use tracing::{info_span, Instrument, Level};
|
use tracing::{info_span, Instrument, Level};
|
||||||
|
@ -129,17 +137,22 @@ mod test {
|
||||||
TELEMETRY.get_or_init(|| {
|
TELEMETRY.get_or_init(|| {
|
||||||
#[cfg(all(
|
#[cfg(all(
|
||||||
not(feature = "opentelemetry_0_20"),
|
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()
|
let tracer = opentelemetry::sdk::export::trace::stdout::new_pipeline()
|
||||||
.with_writer(std::io::sink())
|
.with_writer(std::io::sink())
|
||||||
.install_simple();
|
.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 = {
|
let tracer = {
|
||||||
use opentelemetry::trace::TracerProvider;
|
use opentelemetry::trace::TracerProvider;
|
||||||
#[cfg(feature = "opentelemetry_0_20")]
|
#[cfg(feature = "opentelemetry_0_20")]
|
||||||
use opentelemetry_stdout_0_1::SpanExporterBuilder;
|
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;
|
use opentelemetry_stdout_0_2::SpanExporterBuilder;
|
||||||
|
|
||||||
let exporter = SpanExporterBuilder::default()
|
let exporter = SpanExporterBuilder::default()
|
||||||
|
@ -154,6 +167,10 @@ mod test {
|
||||||
let provider = opentelemetry_sdk_0_21::trace::TracerProvider::builder()
|
let provider = opentelemetry_sdk_0_21::trace::TracerProvider::builder()
|
||||||
.with_simple_exporter(exporter)
|
.with_simple_exporter(exporter)
|
||||||
.build();
|
.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 tracer = provider.versioned_tracer("reqwest", None::<&str>, None::<&str>, None);
|
||||||
let _ = global::set_tracer_provider(provider);
|
let _ = global::set_tracer_provider(provider);
|
||||||
tracer
|
tracer
|
||||||
|
|
Loading…
Reference in a new issue