From 3e5a9ddf46b925193c061bd16fdd417cee95dba9 Mon Sep 17 00:00:00 2001 From: Omid Rad Date: Thu, 14 Nov 2024 09:59:22 +0100 Subject: [PATCH] Support otel 0.27 --- .github/workflows/general.yml | 1 + Cargo.toml | 6 ++++++ README.md | 2 ++ examples/custom-root-span/Cargo.toml | 12 ++++++------ examples/opentelemetry/Cargo.toml | 12 ++++++------ src/lib.rs | 4 ++++ src/otel.rs | 6 ++++++ src/root_span_macro.rs | 1 + 8 files changed, 32 insertions(+), 12 deletions(-) diff --git a/.github/workflows/general.yml b/.github/workflows/general.yml index 04ea8c8..6fa0139 100644 --- a/.github/workflows/general.yml +++ b/.github/workflows/general.yml @@ -62,6 +62,7 @@ jobs: - opentelemetry_0_24 - opentelemetry_0_25 - opentelemetry_0_26 + - opentelemetry_0_27 steps: - uses: actions/checkout@v2 - name: Cache dependencies diff --git a/Cargo.toml b/Cargo.toml index 027ac62..c219661 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -81,6 +81,10 @@ opentelemetry_0_26 = [ "opentelemetry_0_26_pkg", "tracing-opentelemetry_0_27_pkg", ] +opentelemetry_0_27 = [ + "opentelemetry_0_27_pkg", + "tracing-opentelemetry_0_28_pkg", +] emit_event_on_error = [] uuid_v7 = ["uuid/v7"] @@ -104,6 +108,7 @@ opentelemetry_0_23_pkg = { package = "opentelemetry", version = "0.23", optional opentelemetry_0_24_pkg = { package = "opentelemetry", version = "0.24", optional = true } opentelemetry_0_25_pkg = { package = "opentelemetry", version = "0.25", optional = true } opentelemetry_0_26_pkg = { package = "opentelemetry", version = "0.26", optional = true } +opentelemetry_0_27_pkg = { package = "opentelemetry", version = "0.27", optional = true } tracing-opentelemetry_0_12_pkg = { package = "tracing-opentelemetry", version = "0.12", optional = true } tracing-opentelemetry_0_13_pkg = { package = "tracing-opentelemetry", version = "0.13", optional = true } tracing-opentelemetry_0_14_pkg = { package = "tracing-opentelemetry", version = "0.14", optional = true } @@ -118,6 +123,7 @@ tracing-opentelemetry_0_24_pkg = { package = "tracing-opentelemetry", version = tracing-opentelemetry_0_25_pkg = { package = "tracing-opentelemetry", version = "0.25", optional = true } tracing-opentelemetry_0_26_pkg = { package = "tracing-opentelemetry", version = "0.26", optional = true } tracing-opentelemetry_0_27_pkg = { package = "tracing-opentelemetry", version = "0.27", optional = true } +tracing-opentelemetry_0_28_pkg = { package = "tracing-opentelemetry", version = "0.28", optional = true } [dev-dependencies] actix-web = { version = "4", default-features = false, features = ["macros"] } diff --git a/README.md b/README.md index b394c64..4f15b6f 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,8 @@ actix-web = "4" - `opentelemetry_0_23`: same as above but using `opentelemetry` 0.23; - `opentelemetry_0_24`: same as above but using `opentelemetry` 0.24; - `opentelemetry_0_25`: same as above but using `opentelemetry` 0.25; +- `opentelemetry_0_26`: same as above but using `opentelemetry` 0.26; +- `opentelemetry_0_27`: same as above but using `opentelemetry` 0.27; - `emit_event_on_error`: emit a [`tracing`] event when request processing fails with an error (enabled by default). - `uuid_v7`: use the UUID v7 implementation inside [`RequestId`] instead of UUID v4 (disabled by default). ## Quickstart diff --git a/examples/custom-root-span/Cargo.toml b/examples/custom-root-span/Cargo.toml index c610ede..3b79b63 100644 --- a/examples/custom-root-span/Cargo.toml +++ b/examples/custom-root-span/Cargo.toml @@ -8,12 +8,12 @@ edition = "2021" [dependencies] actix-web = "4" -opentelemetry = "0.25" -opentelemetry-otlp = "0.25" -opentelemetry_sdk = { version = "0.25", features = ["rt-tokio-current-thread"] } -opentelemetry-semantic-conventions = "0.25" -tracing-opentelemetry = { version = "0.26" } +opentelemetry = "0.27" +opentelemetry-otlp = "0.27" +opentelemetry_sdk = { version = "0.27", features = ["rt-tokio-current-thread"] } +opentelemetry-semantic-conventions = "0.27" +tracing-opentelemetry = { version = "0.28" } tracing = "0.1" tracing-subscriber = { version = "0.3", features = ["registry", "env-filter"] } tracing-bunyan-formatter = "0.3" -tracing-actix-web = { path = "../..", features = ["opentelemetry_0_26"] } +tracing-actix-web = { path = "../..", features = ["opentelemetry_0_27"] } diff --git a/examples/opentelemetry/Cargo.toml b/examples/opentelemetry/Cargo.toml index 9932132..ecc5800 100644 --- a/examples/opentelemetry/Cargo.toml +++ b/examples/opentelemetry/Cargo.toml @@ -8,12 +8,12 @@ license = "MIT/Apache-2.0" [dependencies] actix-web = "4" -opentelemetry = "0.25" -opentelemetry_sdk = { version = "0.25", features = ["rt-tokio-current-thread"] } -opentelemetry-otlp = "0.25" -opentelemetry-semantic-conventions = "0.25" -tracing-opentelemetry = "0.26" +opentelemetry = "0.27" +opentelemetry_sdk = { version = "0.27", features = ["rt-tokio-current-thread"] } +opentelemetry-otlp = "0.27" +opentelemetry-semantic-conventions = "0.27" +tracing-opentelemetry = "0.28" tracing-subscriber = { version = "0.3", features = ["registry", "env-filter"] } tracing-bunyan-formatter = "0.3" -tracing-actix-web = { path = "../..", features = ["opentelemetry_0_26"] } +tracing-actix-web = { path = "../..", features = ["opentelemetry_0_27"] } tracing = "0.1.40" diff --git a/src/lib.rs b/src/lib.rs index 902e90e..783d27e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -32,6 +32,8 @@ //! - `opentelemetry_0_23`: same as above but using `opentelemetry` 0.23; //! - `opentelemetry_0_24`: same as above but using `opentelemetry` 0.24; //! - `opentelemetry_0_25`: same as above but using `opentelemetry` 0.25; +//! - `opentelemetry_0_26`: same as above but using `opentelemetry` 0.26; +//! - `opentelemetry_0_27`: same as above but using `opentelemetry` 0.27; //! - `emit_event_on_error`: emit a [`tracing`] event when request processing fails with an error (enabled by default). //! - `uuid_v7`: use the UUID v7 implementation inside [`RequestId`] instead of UUID v4 (disabled by default). //! @@ -310,6 +312,7 @@ mutually_exclusive_features::none_or_one_of!( "opentelemetry_0_24", "opentelemetry_0_25", "opentelemetry_0_26", + "opentelemetry_0_27", ); #[cfg(any( @@ -327,5 +330,6 @@ mutually_exclusive_features::none_or_one_of!( feature = "opentelemetry_0_24", feature = "opentelemetry_0_25", feature = "opentelemetry_0_26", + feature = "opentelemetry_0_27", ))] mod otel; diff --git a/src/otel.rs b/src/otel.rs index 71dc509..2bd130b 100644 --- a/src/otel.rs +++ b/src/otel.rs @@ -28,6 +28,8 @@ use opentelemetry_0_24_pkg as opentelemetry; use opentelemetry_0_25_pkg as opentelemetry; #[cfg(feature = "opentelemetry_0_26")] use opentelemetry_0_26_pkg as opentelemetry; +#[cfg(feature = "opentelemetry_0_27")] +use opentelemetry_0_27_pkg as opentelemetry; #[cfg(feature = "opentelemetry_0_13")] use tracing_opentelemetry_0_12_pkg as tracing_opentelemetry; @@ -57,6 +59,8 @@ use tracing_opentelemetry_0_25_pkg as tracing_opentelemetry; use tracing_opentelemetry_0_26_pkg as tracing_opentelemetry; #[cfg(feature = "opentelemetry_0_26")] use tracing_opentelemetry_0_27_pkg as tracing_opentelemetry; +#[cfg(feature = "opentelemetry_0_27")] +use tracing_opentelemetry_0_28_pkg as tracing_opentelemetry; use opentelemetry::propagation::Extractor; @@ -101,6 +105,7 @@ pub(crate) fn set_otel_parent(req: &ServiceRequest, span: &tracing::Span) { feature = "opentelemetry_0_24", feature = "opentelemetry_0_25", feature = "opentelemetry_0_26", + feature = "opentelemetry_0_27", )))] let trace_id = span.context().span().span_context().trace_id().to_hex(); @@ -115,6 +120,7 @@ pub(crate) fn set_otel_parent(req: &ServiceRequest, span: &tracing::Span) { feature = "opentelemetry_0_24", feature = "opentelemetry_0_25", feature = "opentelemetry_0_26", + feature = "opentelemetry_0_27", ))] let trace_id = { let id = span.context().span().span_context().trace_id(); diff --git a/src/root_span_macro.rs b/src/root_span_macro.rs index da45c47..7c91f75 100644 --- a/src/root_span_macro.rs +++ b/src/root_span_macro.rs @@ -170,6 +170,7 @@ pub mod private { feature = "opentelemetry_0_24", feature = "opentelemetry_0_25", feature = "opentelemetry_0_26", + feature = "opentelemetry_0_27", ))] crate::otel::set_otel_parent(req, span); }