Skip to content

Commit

Permalink
Support otel 0.23 (#124)
Browse files Browse the repository at this point in the history
  • Loading branch information
omid authored Jun 5, 2024
1 parent e097e56 commit d3b81c4
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 4 deletions.
1 change: 1 addition & 0 deletions .github/workflows/general.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ jobs:
- opentelemetry_0_20
- opentelemetry_0_21
- opentelemetry_0_22
- opentelemetry_0_23
steps:
- uses: actions/checkout@v2
- name: Cache dependencies
Expand Down
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ opentelemetry_0_19 = ["opentelemetry_0_19_pkg", "tracing-opentelemetry_0_19_pkg"
opentelemetry_0_20 = ["opentelemetry_0_20_pkg", "tracing-opentelemetry_0_21_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"]
opentelemetry_0_23 = ["opentelemetry_0_23_pkg", "tracing-opentelemetry_0_24_pkg"]
emit_event_on_error = []
uuid_v7 = ["uuid/v7"]

Expand All @@ -49,6 +50,7 @@ opentelemetry_0_19_pkg = { package = "opentelemetry", version = "0.19", optional
opentelemetry_0_20_pkg = { package = "opentelemetry", version = "0.20", optional = true }
opentelemetry_0_21_pkg = { package = "opentelemetry", version = "0.21", optional = true }
opentelemetry_0_22_pkg = { package = "opentelemetry", version = "0.22", optional = true }
opentelemetry_0_23_pkg = { package = "opentelemetry", version = "0.23", 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 }
Expand All @@ -59,6 +61,7 @@ tracing-opentelemetry_0_19_pkg = { package = "tracing-opentelemetry", version =
tracing-opentelemetry_0_21_pkg = { package = "tracing-opentelemetry", version = "0.21", optional = true }
tracing-opentelemetry_0_22_pkg = { package = "tracing-opentelemetry", version = "0.22", optional = true }
tracing-opentelemetry_0_23_pkg = { package = "tracing-opentelemetry", version = "0.23", optional = true }
tracing-opentelemetry_0_24_pkg = { package = "tracing-opentelemetry", version = "0.24", optional = true }

[dev-dependencies]
actix-web = { version = "4", default-features = false, features = ["macros"] }
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ actix-web = "4"
- `opentelemetry_0_20`: same as above but using `opentelemetry` 0.20;
- `opentelemetry_0_21`: same as above but using `opentelemetry` 0.21;
- `opentelemetry_0_22`: same as above but using `opentelemetry` 0.22;
- `opentelemetry_0_23`: same as above but using `opentelemetry` 0.23;
- `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
Expand Down
8 changes: 4 additions & 4 deletions examples/opentelemetry/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ license = "MIT/Apache-2.0"
[dependencies]
actix-web = "4"
tracing = "0.1.19"
opentelemetry = "0.22"
opentelemetry-jaeger = { version = "0.21", features = ["rt-tokio-current-thread"] }
tracing-opentelemetry = { version = "0.23" }
opentelemetry = "0.23"
opentelemetry-jaeger = { version = "0.22", features = ["rt-tokio-current-thread"] }
tracing-opentelemetry = { version = "0.24" }
tracing-subscriber = { version = "0.3", features = ["registry", "env-filter"] }
tracing-bunyan-formatter = "0.3"
tracing-actix-web = { path = "../..", features = ["opentelemetry_0_22"] }
tracing-actix-web = { path = "../..", features = ["opentelemetry_0_23"] }
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
//! - `opentelemetry_0_20`: same as above but using `opentelemetry` 0.20;
//! - `opentelemetry_0_21`: same as above but using `opentelemetry` 0.21;
//! - `opentelemetry_0_22`: same as above but using `opentelemetry` 0.22;
//! - `opentelemetry_0_23`: same as above but using `opentelemetry` 0.23;
//! - `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).
//!
Expand Down Expand Up @@ -303,6 +304,7 @@ mutually_exclusive_features::none_or_one_of!(
"opentelemetry_0_20",
"opentelemetry_0_21",
"opentelemetry_0_22",
"opentelemetry_0_23",
);

#[cfg(any(
Expand All @@ -316,5 +318,6 @@ mutually_exclusive_features::none_or_one_of!(
feature = "opentelemetry_0_20",
feature = "opentelemetry_0_21",
feature = "opentelemetry_0_22",
feature = "opentelemetry_0_23",
))]
mod otel;
6 changes: 6 additions & 0 deletions src/otel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ use opentelemetry_0_20_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_23")]
use opentelemetry_0_23_pkg as opentelemetry;

#[cfg(feature = "opentelemetry_0_13")]
use tracing_opentelemetry_0_12_pkg as tracing_opentelemetry;
Expand All @@ -41,6 +43,8 @@ use tracing_opentelemetry_0_21_pkg as tracing_opentelemetry;
use tracing_opentelemetry_0_22_pkg as tracing_opentelemetry;
#[cfg(feature = "opentelemetry_0_22")]
use tracing_opentelemetry_0_23_pkg as tracing_opentelemetry;
#[cfg(feature = "opentelemetry_0_23")]
use tracing_opentelemetry_0_24_pkg as tracing_opentelemetry;

use opentelemetry::propagation::Extractor;

Expand Down Expand Up @@ -81,6 +85,7 @@ pub(crate) fn set_otel_parent(req: &ServiceRequest, span: &tracing::Span) {
feature = "opentelemetry_0_20",
feature = "opentelemetry_0_21",
feature = "opentelemetry_0_22",
feature = "opentelemetry_0_23",
)))]
let trace_id = span.context().span().span_context().trace_id().to_hex();

Expand All @@ -91,6 +96,7 @@ pub(crate) fn set_otel_parent(req: &ServiceRequest, span: &tracing::Span) {
feature = "opentelemetry_0_20",
feature = "opentelemetry_0_21",
feature = "opentelemetry_0_22",
feature = "opentelemetry_0_23",
))]
let trace_id = {
let id = span.context().span().span_context().trace_id();
Expand Down
1 change: 1 addition & 0 deletions src/root_span_macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ pub mod private {
feature = "opentelemetry_0_20",
feature = "opentelemetry_0_21",
feature = "opentelemetry_0_22",
feature = "opentelemetry_0_23",
))]
crate::otel::set_otel_parent(req, span);
}
Expand Down

0 comments on commit d3b81c4

Please sign in to comment.