mirror of
https://github.com/TrueLayer/reqwest-middleware.git
synced 2024-12-27 03:16:32 +00:00
add opentelementry 0.20 support (#101)
This commit is contained in:
parent
a530ea7f93
commit
7b3493d96c
5 changed files with 31 additions and 0 deletions
4
.github/workflows/ci.yml
vendored
4
.github/workflows/ci.yml
vendored
|
@ -19,6 +19,7 @@ jobs:
|
||||||
- opentelemetry_0_17
|
- opentelemetry_0_17
|
||||||
- opentelemetry_0_18
|
- opentelemetry_0_18
|
||||||
- opentelemetry_0_19
|
- opentelemetry_0_19
|
||||||
|
- opentelemetry_0_20
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
|
@ -46,6 +47,7 @@ jobs:
|
||||||
- opentelemetry_0_17
|
- opentelemetry_0_17
|
||||||
- opentelemetry_0_18
|
- opentelemetry_0_18
|
||||||
- opentelemetry_0_19
|
- opentelemetry_0_19
|
||||||
|
- opentelemetry_0_20
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
|
@ -93,6 +95,7 @@ jobs:
|
||||||
- opentelemetry_0_17
|
- opentelemetry_0_17
|
||||||
- opentelemetry_0_18
|
- opentelemetry_0_18
|
||||||
- opentelemetry_0_19
|
- opentelemetry_0_19
|
||||||
|
- opentelemetry_0_20
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
|
@ -122,6 +125,7 @@ jobs:
|
||||||
- opentelemetry_0_17
|
- opentelemetry_0_17
|
||||||
- opentelemetry_0_18
|
- opentelemetry_0_18
|
||||||
- opentelemetry_0_19
|
- opentelemetry_0_19
|
||||||
|
- opentelemetry_0_20
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
|
|
|
@ -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_17 = ["opentelemetry_0_17_pkg", "tracing-opentelemetry_0_17_pkg"]
|
||||||
opentelemetry_0_18 = ["opentelemetry_0_18_pkg", "tracing-opentelemetry_0_18_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_19 = ["opentelemetry_0_19_pkg", "tracing-opentelemetry_0_19_pkg"]
|
||||||
|
opentelemetry_0_20 = ["opentelemetry_0_20_pkg", "tracing-opentelemetry_0_20_pkg"]
|
||||||
|
|
||||||
|
|
||||||
[dependencies]
|
[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_17_pkg = { package = "opentelemetry", version = "0.17.0", optional = true }
|
||||||
opentelemetry_0_18_pkg = { package = "opentelemetry", version = "0.18.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_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_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 }
|
||||||
|
@ -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_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_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_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]
|
[target.'cfg(target_arch = "wasm32")'.dependencies]
|
||||||
getrandom = { version = "0.2.0", features = ["js"] }
|
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_2 = { package = "tracing-subscriber", version = "0.2.0" }
|
||||||
tracing_subscriber_0_3 = { package = "tracing-subscriber", version = "0.3.0" }
|
tracing_subscriber_0_3 = { package = "tracing-subscriber", version = "0.3.0" }
|
||||||
wiremock = "0.5.0"
|
wiremock = "0.5.0"
|
||||||
|
|
||||||
|
opentelemetry-stdout = { version = "0.1.0", features = ["trace"] }
|
||||||
|
|
|
@ -91,6 +91,7 @@ mod middleware;
|
||||||
feature = "opentelemetry_0_17",
|
feature = "opentelemetry_0_17",
|
||||||
feature = "opentelemetry_0_18",
|
feature = "opentelemetry_0_18",
|
||||||
feature = "opentelemetry_0_19",
|
feature = "opentelemetry_0_19",
|
||||||
|
feature = "opentelemetry_0_20",
|
||||||
))]
|
))]
|
||||||
mod otel;
|
mod otel;
|
||||||
mod reqwest_otel_span_builder;
|
mod reqwest_otel_span_builder;
|
||||||
|
|
|
@ -53,6 +53,7 @@ where
|
||||||
feature = "opentelemetry_0_17",
|
feature = "opentelemetry_0_17",
|
||||||
feature = "opentelemetry_0_18",
|
feature = "opentelemetry_0_18",
|
||||||
feature = "opentelemetry_0_19",
|
feature = "opentelemetry_0_19",
|
||||||
|
feature = "opentelemetry_0_20",
|
||||||
))]
|
))]
|
||||||
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.
|
||||||
|
|
|
@ -24,6 +24,9 @@ use opentelemetry_0_18_pkg as opentelemetry;
|
||||||
#[cfg(feature = "opentelemetry_0_19")]
|
#[cfg(feature = "opentelemetry_0_19")]
|
||||||
use opentelemetry_0_19_pkg as opentelemetry;
|
use opentelemetry_0_19_pkg as opentelemetry;
|
||||||
|
|
||||||
|
#[cfg(feature = "opentelemetry_0_20")]
|
||||||
|
use opentelemetry_0_20_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;
|
||||||
|
|
||||||
|
@ -45,6 +48,9 @@ pub use tracing_opentelemetry_0_18_pkg as tracing_opentelemetry;
|
||||||
#[cfg(feature = "opentelemetry_0_19")]
|
#[cfg(feature = "opentelemetry_0_19")]
|
||||||
pub use tracing_opentelemetry_0_19_pkg as tracing_opentelemetry;
|
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::global;
|
||||||
use opentelemetry::propagation::Injector;
|
use opentelemetry::propagation::Injector;
|
||||||
use tracing_opentelemetry::OpenTelemetrySpanExt;
|
use tracing_opentelemetry::OpenTelemetrySpanExt;
|
||||||
|
@ -112,9 +118,23 @@ mod test {
|
||||||
static TELEMETRY: OnceLock<()> = OnceLock::new();
|
static TELEMETRY: OnceLock<()> = OnceLock::new();
|
||||||
|
|
||||||
TELEMETRY.get_or_init(|| {
|
TELEMETRY.get_or_init(|| {
|
||||||
|
#[cfg(not(feature = "opentelemetry_0_20"))]
|
||||||
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(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 telemetry = tracing_opentelemetry::layer().with_tracer(tracer);
|
||||||
let subscriber = Registry::default()
|
let subscriber = Registry::default()
|
||||||
.with(
|
.with(
|
||||||
|
|
Loading…
Reference in a new issue