diff --git a/Cargo.toml b/Cargo.toml index 2f1c9ce..182872a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "prima-tracing" -version = "0.3.0" +version = "0.3.1" license = "MIT OR Apache-2.0" readme = "README.md" authors = ["Enrico Risa "] @@ -14,6 +14,7 @@ prima-logger = ["tracing-log"] prima-telemetry = ["tracing-opentelemetry", "opentelemetry", "opentelemetry-zipkin"] prima-logger-json = ["prima-logger"] prima-logger-datadog = ["prima-logger-json", "opentelemetry", "tracing-opentelemetry"] +rt-tokio-current-thread = ["opentelemetry/rt-tokio-current-thread"] [[example]] name = "custom-json-subscriber" diff --git a/README.md b/README.md index a93a6d1..096ce0e 100644 --- a/README.md +++ b/README.md @@ -9,17 +9,21 @@ ## Installation -Install from GitHub +Install from [crates.io](https://crates.io/crates/prima-tracing) ```toml -prima-tracing = { git="https://github.com/primait/prima_tracing.rs", branch="master" } +prima-tracing = "0.3.1" ``` ## Cargo features - `prima-logger-json` use JSON as output format -- `prima-logger-datadog` extends `prima-logger-json` output with [trace and span information](https://docs.datadoghq.com/tracing/connect_logs_and_traces/opentelemetry/) allowing Datadog to connect logs and traces +- `prima-logger-datadog` extends `prima-logger-json` output + with [trace and span information](https://docs.datadoghq.com/tracing/connect_logs_and_traces/opentelemetry/) allowing + Datadog to connect logs and traces - `prima-telemetry` integrate opentelemetry with `opentelemetry-zipkin` +- `rt-tokio-current-thread` uses opentelemetry runtime implementation, which works with Tokio’s current thread runtime( + ex. `actix_web::main`). Without this feature the default uses Tokio’s multi thread runtime. ## Example @@ -158,9 +162,11 @@ curl http://localhost:8081/check Open the browser at to inspect the traced request #### OpenTelemetry + JSON logger with Datadog correlation IDs + ```sh RUST_LOG=info cargo run --features=prima-logger-datadog,prima-telemetry --example datadog_json_logger ``` + ### Custom formatter ```sh diff --git a/src/telemetry.rs b/src/telemetry.rs index 0c157e9..185797f 100644 --- a/src/telemetry.rs +++ b/src/telemetry.rs @@ -17,6 +17,17 @@ pub fn configure(config: &SubscriberConfig) -> Tracer { .as_ref() .expect("Tracing config should be provided when the feature `prima-tracing` is enabled"); + let runtime = { + #[cfg(feature = "rt-tokio-current-thread")] + { + opentelemetry::runtime::TokioCurrentThread + } + #[cfg(not(feature = "rt-tokio-current-thread"))] + { + opentelemetry::runtime::Tokio + } + }; + opentelemetry_zipkin::new_pipeline() .with_collector_endpoint(telemetry.collector_url.as_str()) .with_service_name(telemetry.service_name.as_str()) @@ -26,7 +37,7 @@ pub fn configure(config: &SubscriberConfig) -> Tracer { config.env.clone(), )])), ) - .install_batch(opentelemetry::runtime::Tokio) + .install_batch(runtime) .expect("Failed to create the zipkin pipeline") }