Skip to content

Commit

Permalink
Add opentelemetry 0.20 (#111)
Browse files Browse the repository at this point in the history
* Add opentelemetry 0.20

* Update github workflow

* clippy nit
  • Loading branch information
asonix committed Aug 5, 2023
1 parent f8b7ca2 commit 7933926
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 6 deletions.
1 change: 1 addition & 0 deletions .github/workflows/general.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ jobs:
- opentelemetry_0_17
- opentelemetry_0_18
- opentelemetry_0_19
- opentelemetry_0_20
steps:
- uses: actions/checkout@v2
- name: Cache dependencies
Expand Down
5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ members = [".", "examples/opentelemetry", "examples/custom-root-span", "examples

[package]
name = "tracing-actix-web"
version = "0.7.5"
version = "0.7.6"
authors = ["Luca Palmieri <rust@lpalmieri.com>"]
edition = "2018"

Expand All @@ -27,6 +27,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_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"]
emit_event_on_error = []

[dependencies]
Expand All @@ -41,13 +42,15 @@ opentelemetry_0_16_pkg = { package = "opentelemetry", version = "0.16", optional
opentelemetry_0_17_pkg = { package = "opentelemetry", version = "0.17", optional = true }
opentelemetry_0_18_pkg = { package = "opentelemetry", version = "0.18", optional = true }
opentelemetry_0_19_pkg = { package = "opentelemetry", version = "0.19", optional = true }
opentelemetry_0_20_pkg = { package = "opentelemetry", version = "0.20", 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 }
tracing-opentelemetry_0_16_pkg = { package = "tracing-opentelemetry",version = "0.16", optional = true }
tracing-opentelemetry_0_17_pkg = { package = "tracing-opentelemetry",version = "0.17", optional = true }
tracing-opentelemetry_0_18_pkg = { package = "tracing-opentelemetry",version = "0.18", optional = true }
tracing-opentelemetry_0_19_pkg = { package = "tracing-opentelemetry",version = "0.19", optional = true }
tracing-opentelemetry_0_20_pkg = { package = "tracing-opentelemetry",version = "0.20", optional = true }

[dev-dependencies]
actix-web = { version = "4", default-features = false, features = ["macros"] }
Expand Down
25 changes: 24 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
//! - `opentelemetry_0_17`: same as above but using `opentelemetry` 0.17;
//! - `opentelemetry_0_18`: same as above but using `opentelemetry` 0.18;
//! - `opentelemetry_0_19`: same as above but using `opentelemetry` 0.19;
//! - `opentelemetry_0_20`: same as above but using `opentelemetry` 0.20;
//! - `emit_event_on_error`: emit a [`tracing`] event when request processing fails with an error (enabled by default).
//!
//! ## Quickstart
Expand Down Expand Up @@ -293,7 +294,8 @@ pub mod root_span_macro;
feature = "opentelemetry_0_16",
feature = "opentelemetry_0_17",
feature = "opentelemetry_0_18",
feature = "opentelemetry_0_19"
feature = "opentelemetry_0_19",
feature = "opentelemetry_0_20"
))]
mod otel;

Expand All @@ -315,6 +317,9 @@ compile_error!("feature \"opentelemetry_0_13\" and feature \"opentelemetry_0_18\
#[cfg(all(feature = "opentelemetry_0_13", feature = "opentelemetry_0_19"))]
compile_error!("feature \"opentelemetry_0_13\" and feature \"opentelemetry_0_19\" cannot be enabled at the same time");

#[cfg(all(feature = "opentelemetry_0_13", feature = "opentelemetry_0_20"))]
compile_error!("feature \"opentelemetry_0_13\" and feature \"opentelemetry_0_20\" cannot be enabled at the same time");

#[cfg(all(feature = "opentelemetry_0_14", feature = "opentelemetry_0_15"))]
compile_error!("feature \"opentelemetry_0_14\" and feature \"opentelemetry_0_15\" cannot be enabled at the same time");

Expand All @@ -330,6 +335,9 @@ compile_error!("feature \"opentelemetry_0_14\" and feature \"opentelemetry_0_18\
#[cfg(all(feature = "opentelemetry_0_14", feature = "opentelemetry_0_19"))]
compile_error!("feature \"opentelemetry_0_14\" and feature \"opentelemetry_0_19\" cannot be enabled at the same time");

#[cfg(all(feature = "opentelemetry_0_14", feature = "opentelemetry_0_20"))]
compile_error!("feature \"opentelemetry_0_14\" and feature \"opentelemetry_0_20\" cannot be enabled at the same time");

#[cfg(all(feature = "opentelemetry_0_15", feature = "opentelemetry_0_16"))]
compile_error!("feature \"opentelemetry_0_15\" and feature \"opentelemetry_0_16\" cannot be enabled at the same time");

Expand All @@ -342,6 +350,9 @@ compile_error!("feature \"opentelemetry_0_15\" and feature \"opentelemetry_0_18\
#[cfg(all(feature = "opentelemetry_0_15", feature = "opentelemetry_0_19"))]
compile_error!("feature \"opentelemetry_0_15\" and feature \"opentelemetry_0_19\" cannot be enabled at the same time");

#[cfg(all(feature = "opentelemetry_0_15", feature = "opentelemetry_0_20"))]
compile_error!("feature \"opentelemetry_0_15\" and feature \"opentelemetry_0_20\" cannot be enabled at the same time");

#[cfg(all(feature = "opentelemetry_0_16", feature = "opentelemetry_0_17"))]
compile_error!("feature \"opentelemetry_0_16\" and feature \"opentelemetry_0_17\" cannot be enabled at the same time");

Expand All @@ -351,11 +362,23 @@ compile_error!("feature \"opentelemetry_0_16\" and feature \"opentelemetry_0_18\
#[cfg(all(feature = "opentelemetry_0_16", feature = "opentelemetry_0_19"))]
compile_error!("feature \"opentelemetry_0_16\" and feature \"opentelemetry_0_19\" cannot be enabled at the same time");

#[cfg(all(feature = "opentelemetry_0_16", feature = "opentelemetry_0_20"))]
compile_error!("feature \"opentelemetry_0_16\" and feature \"opentelemetry_0_20\" cannot be enabled at the same time");

#[cfg(all(feature = "opentelemetry_0_17", feature = "opentelemetry_0_18"))]
compile_error!("feature \"opentelemetry_0_17\" and feature \"opentelemetry_0_18\" cannot be enabled at the same time");

#[cfg(all(feature = "opentelemetry_0_17", feature = "opentelemetry_0_19"))]
compile_error!("feature \"opentelemetry_0_17\" and feature \"opentelemetry_0_19\" cannot be enabled at the same time");

#[cfg(all(feature = "opentelemetry_0_17", feature = "opentelemetry_0_20"))]
compile_error!("feature \"opentelemetry_0_17\" and feature \"opentelemetry_0_20\" cannot be enabled at the same time");

#[cfg(all(feature = "opentelemetry_0_18", feature = "opentelemetry_0_19"))]
compile_error!("feature \"opentelemetry_0_18\" and feature \"opentelemetry_0_19\" cannot be enabled at the same time");

#[cfg(all(feature = "opentelemetry_0_18", feature = "opentelemetry_0_20"))]
compile_error!("feature \"opentelemetry_0_18\" and feature \"opentelemetry_0_20\" cannot be enabled at the same time");

#[cfg(all(feature = "opentelemetry_0_19", feature = "opentelemetry_0_20"))]
compile_error!("feature \"opentelemetry_0_19\" and feature \"opentelemetry_0_20\" cannot be enabled at the same time");
2 changes: 1 addition & 1 deletion src/middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ where
fn new_transform(&self, service: S) -> Self::Future {
ready(Ok(TracingLoggerMiddleware {
service,
root_span_builder: std::marker::PhantomData::default(),
root_span_builder: std::marker::PhantomData,
}))
}
}
Expand Down
10 changes: 8 additions & 2 deletions src/otel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ use opentelemetry_0_17_pkg as opentelemetry;
use opentelemetry_0_18_pkg as opentelemetry;
#[cfg(feature = "opentelemetry_0_19")]
use opentelemetry_0_19_pkg as opentelemetry;
#[cfg(feature = "opentelemetry_0_20")]
use opentelemetry_0_20_pkg as opentelemetry;

#[cfg(feature = "opentelemetry_0_13")]
use tracing_opentelemetry_0_12_pkg as tracing_opentelemetry;
Expand All @@ -29,6 +31,8 @@ use tracing_opentelemetry_0_17_pkg as tracing_opentelemetry;
use tracing_opentelemetry_0_18_pkg as tracing_opentelemetry;
#[cfg(feature = "opentelemetry_0_19")]
use tracing_opentelemetry_0_19_pkg as tracing_opentelemetry;
#[cfg(feature = "opentelemetry_0_20")]
use tracing_opentelemetry_0_20_pkg as tracing_opentelemetry;

use opentelemetry::propagation::Extractor;

Expand Down Expand Up @@ -65,14 +69,16 @@ pub(crate) fn set_otel_parent(req: &ServiceRequest, span: &tracing::Span) {
#[cfg(not(any(
feature = "opentelemetry_0_17",
feature = "opentelemetry_0_18",
feature = "opentelemetry_0_19"
feature = "opentelemetry_0_19",
feature = "opentelemetry_0_20"
)))]
let trace_id = span.context().span().span_context().trace_id().to_hex();

#[cfg(any(
feature = "opentelemetry_0_17",
feature = "opentelemetry_0_18",
feature = "opentelemetry_0_19"
feature = "opentelemetry_0_19",
feature = "opentelemetry_0_20"
))]
let trace_id = {
let id = span.context().span().span_context().trace_id();
Expand Down
3 changes: 2 additions & 1 deletion src/root_span_macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ pub mod private {
feature = "opentelemetry_0_16",
feature = "opentelemetry_0_17",
feature = "opentelemetry_0_18",
feature = "opentelemetry_0_19"
feature = "opentelemetry_0_19",
feature = "opentelemetry_0_20"
))]
crate::otel::set_otel_parent(req, span);
}
Expand Down

0 comments on commit 7933926

Please sign in to comment.