diff --git a/CHANGELOG.md b/CHANGELOG.md index d9b86f9..72da3fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,14 @@ and this project adheres to --- +## [0.20.0] - 2024-12-02 + +### Added + +- Support for opentelemetry 0.27, now the default version. + +--- + ## [0.19.0] - 2024-11-25 ### Added @@ -487,8 +495,8 @@ Request::rest(&bridge).send() The old API is still available but deprecated. It will be removed soon. - -[Unreleased]: https://github.com/primait/bridge.rs/compare/0.19.0...HEAD +[Unreleased]: https://github.com/primait/bridge.rs/compare/0.20.0...HEAD +[0.20.0]: https://github.com/primait/bridge.rs/compare/0.19.0...0.20.0 [0.19.0]: https://github.com/primait/bridge.rs/compare/0.18.0...0.19.0 [0.18.0]: https://github.com/primait/bridge.rs/compare/0.17.0...0.18.0 [0.17.0]: https://github.com/primait/bridge.rs/compare/0.16.6...0.17.0 diff --git a/Cargo.toml b/Cargo.toml index a760bb6..51150fa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,7 @@ license = "MIT" name = "prima_bridge" readme = "README.md" repository = "https://github.com/primait/bridge.rs" -version = "0.19.0" +version = "0.20.0" # See https://github.com/rust-lang/rust/issues/107557 rust-version = "1.72" @@ -24,7 +24,7 @@ auth0 = [ ] gzip = ["reqwest/gzip"] redis-tls = ["redis/tls", "redis/tokio-native-tls-comp"] -tracing_opentelemetry = ["tracing_opentelemetry_0_26"] +tracing_opentelemetry = ["tracing_opentelemetry_0_27"] tracing_opentelemetry_0_21 = [ "_any_otel_version", @@ -68,6 +68,13 @@ tracing_opentelemetry_0_26 = [ "opentelemetry_0_26_pkg", "opentelemetry_sdk_0_26_pkg", ] +tracing_opentelemetry_0_27 = [ + "_any_otel_version", + "tracing", + "tracing-opentelemetry_0_28_pkg", + "opentelemetry_0_27_pkg", + "opentelemetry_sdk_0_27_pkg", +] _any_otel_version = [] @@ -88,7 +95,7 @@ redis = { version = "0.27", features = ["tokio-comp"], optional = true } reqwest = { version = "0.12", features = ["json", "multipart", "stream"] } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" -thiserror = "1.0" +thiserror = "2" tokio = { version = "1.16", features = ["macros", "rt-multi-thread", "fs"] } tracing = { version = "0.1", optional = true } uuid = { version = ">=0.7.0, <2.0.0", features = ["serde", "v4"] } @@ -103,25 +110,26 @@ 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 } opentelemetry_sdk_0_21_pkg = { package = "opentelemetry_sdk", version = "0.21", optional = true } opentelemetry_sdk_0_22_pkg = { package = "opentelemetry_sdk", version = "0.22", optional = true } opentelemetry_sdk_0_23_pkg = { package = "opentelemetry_sdk", version = "0.23", optional = true } opentelemetry_sdk_0_24_pkg = { package = "opentelemetry_sdk", version = "0.24", optional = true } opentelemetry_sdk_0_25_pkg = { package = "opentelemetry_sdk", version = "0.25", optional = true } opentelemetry_sdk_0_26_pkg = { package = "opentelemetry_sdk", version = "0.26", optional = true } -tracing-opentelemetry_0_21_pkg = { package = "tracing-opentelemetry", version = "0.21", optional = true } +opentelemetry_sdk_0_27_pkg = { package = "opentelemetry_sdk", version = "0.27", 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 } 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] flate2 = "1.0" mockito = "1.0" tokio = { version = "1.16", features = ["macros", "rt-multi-thread"] } -tokio-test = "0.4" [profile.release] codegen-units = 1 diff --git a/Makefile.toml b/Makefile.toml index a42fb69..49bf839 100644 --- a/Makefile.toml +++ b/Makefile.toml @@ -1,6 +1,17 @@ [config] skip_core_tasks = true +[env] +AVAILABLE_OTEL_FEATURES = [ + "tracing_opentelemetry_0_21", + "tracing_opentelemetry_0_22", + "tracing_opentelemetry_0_23", + "tracing_opentelemetry_0_24", + "tracing_opentelemetry_0_25", + "tracing_opentelemetry_0_26", + "tracing_opentelemetry_0_27", +] + [tasks.build] description = "Runs the rust compiler." category = "Build" @@ -21,12 +32,7 @@ args = ["fmt", "--", "--check"] dependencies = [ "test-base", "test-auth0", - "test-otel-0_21", - "test-otel-0_22", - "test-otel-0_23", - "test-otel-0_24", - "test-otel-0_25", - "test-otel-0_26", + "test-all-otel-versions", ] [tasks.test-base] @@ -39,70 +45,30 @@ command = "cargo" args = ["test", "--features=auth0,gzip", "${@}"] dependencies = ["build"] -[tasks.test-otel-0_21] -command = "cargo" -args = [ - "test", - "--no-default-features", - "--features", - "tracing_opentelemetry_0_21", -] - -[tasks.test-otel-0_22] -command = "cargo" -args = [ - "test", - "--no-default-features", - "--features", - "tracing_opentelemetry_0_22", -] +[tasks.test-all-otel-versions] +script = """#!@duckscript -[tasks.test-otel-0_23] -command = "cargo" -args = [ - "test", - "--no-default-features", - "--features", - "tracing_opentelemetry_0_23", -] +available_otel_features = split ${AVAILABLE_OTEL_FEATURES} ";" +for otel_feature in ${available_otel_features} + set_env otel_feature ${otel_feature} + cm_run_task "test-otel-version-from-env" +end +""" -[tasks.test-otel-0_24] +[tasks.test-otel-version-from-env] command = "cargo" args = [ "test", "--no-default-features", "--features", - "tracing_opentelemetry_0_24", -] - -[tasks.test-otel-0_25] -command = "cargo" -args = [ - "test", - "--no-default-features", - "--features", - "tracing_opentelemetry_0_25", -] - -[tasks.test-otel-0_26] -command = "cargo" -args = [ - "test", - "--no-default-features", - "--features", - "tracing_opentelemetry_0_26", + "${otel_feature}", ] [tasks.clippy] dependencies = [ "clippy-base", "clippy-auth0", - "clippy-otel-0_21", - "clippy-otel-0_22", - "clippy-otel-0_23", - "clippy-otel-0_24", - "clippy-otel-0_25", - "clippy-otel-0_26", + "clippy-all-otel-versions", ] [tasks.clippy-base] @@ -122,78 +88,23 @@ args = [ ] dependencies = ["build"] -[tasks.clippy-otel-0_21] -command = "cargo" -args = [ - "clippy", - "--no-default-features", - "--features", - "tracing_opentelemetry_0_21", - "--all-targets", - "--", - "-D", - "warnings", -] - -[tasks.clippy-otel-0_22] -command = "cargo" -args = [ - "clippy", - "--no-default-features", - "--features", - "tracing_opentelemetry_0_22", - "--all-targets", - "--", - "-D", - "warnings", -] - -[tasks.clippy-otel-0_23] -command = "cargo" -args = [ - "clippy", - "--no-default-features", - "--features", - "tracing_opentelemetry_0_23", - "--all-targets", - "--", - "-D", - "warnings", -] - -[tasks.clippy-otel-0_24] -command = "cargo" -args = [ - "clippy", - "--no-default-features", - "--features", - "tracing_opentelemetry_0_24", - "--all-targets", - "--", - "-D", - "warnings", -] +[tasks.clippy-all-otel-versions] +script = """#!@duckscript -[tasks.clippy-otel-0_25] -command = "cargo" -args = [ - "clippy", - "--no-default-features", - "--features", - "tracing_opentelemetry_0_25", - "--all-targets", - "--", - "-D", - "warnings", -] +available_otel_features = split ${AVAILABLE_OTEL_FEATURES} ";" +for otel_feature in ${available_otel_features} + set_env otel_feature ${otel_feature} + cm_run_task "clippy-otel-version-from-env" +end +""" -[tasks.clippy-otel-0_26] +[tasks.clippy-otel-version-from-env] command = "cargo" args = [ "clippy", "--no-default-features", "--features", - "tracing_opentelemetry_0_26", + "${otel_feature}", "--all-targets", "--", "-D", @@ -202,79 +113,29 @@ args = [ [tasks.deny-check] dependencies = [ - "deny-check-otel-0_21", - "deny-check-otel-0_22", - "deny-check-otel-0_23", - "deny-check-otel-0_24", - "deny-check-otel-0_25", - "deny-check-otel-0_26", + "deny-check-all-otel-versions", ] -[tasks.deny-check-otel-0_21] -args = [ - "deny", - "--no-default-features", - "--features", - "tracing_opentelemetry_0_21", - "check", -] -command = "cargo" -description = "Run cargo-deny with tracing_opentelemetry_0_21 feature" +[tasks.deny-check-all-otel-versions] +script = """#!@duckscript -[tasks.deny-check-otel-0_22] -args = [ - "deny", - "--no-default-features", - "--features", - "tracing_opentelemetry_0_22", - "check", -] -command = "cargo" -description = "Run cargo-deny with tracing_opentelemetry_0_22 feature" +available_otel_features = split ${AVAILABLE_OTEL_FEATURES} ";" +for otel_feature in ${available_otel_features} + set_env otel_feature ${otel_feature} + cm_run_task "deny-check-otel-version-from-env" +end +""" -[tasks.deny-check-otel-0_23] -args = [ - "deny", - "--no-default-features", - "--features", - "tracing_opentelemetry_0_23", - "check", -] +[tasks.deny-check-otel-version-from-env] +description = "Run cargo-deny with ${otel_feature} feature" command = "cargo" -description = "Run cargo-deny with tracing_opentelemetry_0_23 feature" - -[tasks.deny-check-otel-0_24] args = [ "deny", "--no-default-features", "--features", - "tracing_opentelemetry_0_24", + "${otel_feature}", "check", ] -command = "cargo" -description = "Run cargo-deny with tracing_opentelemetry_0_24 feature" - -[tasks.deny-check-otel-0_25] -args = [ - "deny", - "--no-default-features", - "--features", - "tracing_opentelemetry_0_25", - "check", -] -command = "cargo" -description = "Run cargo-deny with tracing_opentelemetry_0_25 feature" - -[tasks.deny-check-otel-0_26] -args = [ - "deny", - "--no-default-features", - "--features", - "tracing_opentelemetry_0_26", - "check", -] -command = "cargo" -description = "Run cargo-deny with tracing_opentelemetry_0_26 feature" [tasks.docs] description = "Build docs as they are rendered on docs.rs" diff --git a/src/lib.rs b/src/lib.rs index b619567..2c142c0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -73,7 +73,7 @@ pub struct BridgeImpl { #[doc(hidden)] pub trait BridgeClient: Sealed { type Builder: PrimaRequestBuilderInner; - fn request(&self, method: http::Method, url: Url) -> PrimaRequestBuilder; + fn request(&self, method: Method, url: Url) -> PrimaRequestBuilder; } /// A trait which abstracts across request builders, to allow for both reqwest and reqwest with middleware @@ -263,6 +263,6 @@ mod sealed { impl Sealed for reqwest_middleware::ClientWithMiddleware {} impl Sealed for reqwest_middleware::RequestBuilder {} impl Sealed for reqwest::RequestBuilder {} - impl<'a, Client: BridgeClient> Sealed for crate::request::RestRequest<'a, Client> {} - impl<'a, Client: BridgeClient> Sealed for crate::request::GraphQLRequest<'a, Client> {} + impl Sealed for crate::request::RestRequest<'_, Client> {} + impl Sealed for crate::request::GraphQLRequest<'_, Client> {} } diff --git a/src/request/otel.rs b/src/request/otel.rs index 7df4762..0a1bd6d 100644 --- a/src/request/otel.rs +++ b/src/request/otel.rs @@ -1,83 +1,58 @@ #[cfg(feature = "tracing_opentelemetry_0_21")] -mod otel_0_21 { - pub use opentelemetry_0_21_pkg::propagation::{Injector, TextMapPropagator}; - pub use opentelemetry_sdk_0_21_pkg::propagation::TraceContextPropagator; - pub use tracing_opentelemetry_0_22_pkg::OpenTelemetrySpanExt; - - pub fn inject_context(injector: &mut dyn Injector) { - TraceContextPropagator::new().inject_context(&tracing::Span::current().context(), injector); - } +mod otel_crates { + pub use opentelemetry_0_21_pkg as opentelemetry; + pub use opentelemetry_sdk_0_21_pkg as opentelemetry_sdk; + pub use tracing_opentelemetry_0_22_pkg as tracing_opentelemetry; } #[cfg(feature = "tracing_opentelemetry_0_22")] -mod otel_0_22 { - pub use opentelemetry_0_22_pkg::propagation::{Injector, TextMapPropagator}; - pub use opentelemetry_sdk_0_22_pkg::propagation::TraceContextPropagator; - pub use tracing_opentelemetry_0_23_pkg::OpenTelemetrySpanExt; - - pub fn inject_context(injector: &mut dyn Injector) { - TraceContextPropagator::new().inject_context(&tracing::Span::current().context(), injector); - } +mod otel_crates { + pub use opentelemetry_0_22_pkg as opentelemetry; + pub use opentelemetry_sdk_0_22_pkg as opentelemetry_sdk; + pub use tracing_opentelemetry_0_23_pkg as tracing_opentelemetry; } #[cfg(feature = "tracing_opentelemetry_0_23")] -mod otel_0_23 { - pub use opentelemetry_0_23_pkg::propagation::{Injector, TextMapPropagator}; - pub use opentelemetry_sdk_0_23_pkg::propagation::TraceContextPropagator; - pub use tracing_opentelemetry_0_24_pkg::OpenTelemetrySpanExt; - - pub fn inject_context(injector: &mut dyn Injector) { - TraceContextPropagator::new().inject_context(&tracing::Span::current().context(), injector); - } +mod otel_crates { + pub use opentelemetry_0_23_pkg as opentelemetry; + pub use opentelemetry_sdk_0_23_pkg as opentelemetry_sdk; + pub use tracing_opentelemetry_0_24_pkg as tracing_opentelemetry; } #[cfg(feature = "tracing_opentelemetry_0_24")] -mod otel_0_24 { - pub use opentelemetry_0_24_pkg::propagation::{Injector, TextMapPropagator}; - pub use opentelemetry_sdk_0_24_pkg::propagation::TraceContextPropagator; - pub use tracing_opentelemetry_0_25_pkg::OpenTelemetrySpanExt; - - pub fn inject_context(injector: &mut dyn Injector) { - TraceContextPropagator::new().inject_context(&tracing::Span::current().context(), injector); - } +mod otel_crates { + pub use opentelemetry_0_24_pkg as opentelemetry; + pub use opentelemetry_sdk_0_24_pkg as opentelemetry_sdk; + pub use tracing_opentelemetry_0_25_pkg as tracing_opentelemetry; } #[cfg(feature = "tracing_opentelemetry_0_25")] -mod otel_0_25 { - pub use opentelemetry_0_25_pkg::propagation::{Injector, TextMapPropagator}; - pub use opentelemetry_sdk_0_25_pkg::propagation::TraceContextPropagator; - pub use tracing_opentelemetry_0_26_pkg::OpenTelemetrySpanExt; - - pub fn inject_context(injector: &mut dyn Injector) { - TraceContextPropagator::new().inject_context(&tracing::Span::current().context(), injector); - } +mod otel_crates { + pub use opentelemetry_0_25_pkg as opentelemetry; + pub use opentelemetry_sdk_0_25_pkg as opentelemetry_sdk; + pub use tracing_opentelemetry_0_26_pkg as tracing_opentelemetry; } #[cfg(feature = "tracing_opentelemetry_0_26")] -mod otel_0_26 { - pub use opentelemetry_0_26_pkg::propagation::{Injector, TextMapPropagator}; - pub use opentelemetry_sdk_0_26_pkg::propagation::TraceContextPropagator; - pub use tracing_opentelemetry_0_27_pkg::OpenTelemetrySpanExt; - - pub fn inject_context(injector: &mut dyn Injector) { - TraceContextPropagator::new().inject_context(&tracing::Span::current().context(), injector); - } +mod otel_crates { + pub use opentelemetry_0_26_pkg as opentelemetry; + pub use opentelemetry_sdk_0_26_pkg as opentelemetry_sdk; + pub use tracing_opentelemetry_0_27_pkg as tracing_opentelemetry; } -#[cfg(feature = "tracing_opentelemetry_0_21")] -pub use otel_0_21::inject_context; - -#[cfg(feature = "tracing_opentelemetry_0_22")] -pub use otel_0_22::inject_context; - -#[cfg(feature = "tracing_opentelemetry_0_23")] -pub use otel_0_23::inject_context; +#[cfg(feature = "tracing_opentelemetry_0_27")] +mod otel_crates { + pub use opentelemetry_0_27_pkg as opentelemetry; + pub use opentelemetry_sdk_0_27_pkg as opentelemetry_sdk; + pub use tracing_opentelemetry_0_28_pkg as tracing_opentelemetry; +} -#[cfg(feature = "tracing_opentelemetry_0_24")] -pub use otel_0_24::inject_context; +use otel_crates::*; -#[cfg(feature = "tracing_opentelemetry_0_25")] -pub use otel_0_25::inject_context; +use opentelemetry::propagation::{Injector, TextMapPropagator}; +use opentelemetry_sdk::propagation::TraceContextPropagator; +use tracing_opentelemetry::OpenTelemetrySpanExt; -#[cfg(feature = "tracing_opentelemetry_0_26")] -pub use otel_0_26::inject_context; +pub fn inject_context(injector: &mut dyn Injector) { + TraceContextPropagator::new().inject_context(&tracing::Span::current().context(), injector); +}