Skip to content

Commit

Permalink
Merge pull request #1 from will-bank/bump-otel-0.21
Browse files Browse the repository at this point in the history
feat: bump deps to support otel 0.21
  • Loading branch information
fhsgoncalves authored Feb 10, 2024
2 parents 30cdfba + e5b4a7c commit cac61d7
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 33 deletions.
26 changes: 14 additions & 12 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "datadog-tracing"
version = "0.0.1"
version = "0.1.6"
authors = [
"Fernando Goncalves <[email protected]>",
"Alefh Sousa <[email protected]>"
Expand All @@ -21,18 +21,20 @@ axum = ["dep:axum", "dep:tokio", "dep:axum-tracing-opentelemetry"]
[dependencies]
axum = { version = "^0.6.10", optional = true }
axum-tracing-opentelemetry = { version = "^0.10.0", optional = true }
chrono = "^0.4.24"
opentelemetry = { version = "^0.18.0", features = ["rt-tokio"] }
opentelemetry-datadog = { version = "0.6.0", features = ["reqwest-client"] }
chrono = "^0.4.33"
opentelemetry = { version = "^0.21.0"}
opentelemetry_sdk = { version = "^0.21.2", features = ["rt-tokio"] }
opentelemetry-http = { version = "^0.10.0" }
opentelemetry-datadog = { version = "0.9.0", features = ["reqwest-client"] }
reqwest = { version = "0.11", default-features = false }
serde = { version = "^1.0.156", features = ["derive"] }
serde_json = "^1.0.95"
tokio = { version = "^1.26.0", features = ["signal", "macros"], optional = true }
tracing = "^0.1.37"
tracing-appender = "0.2.2"
tracing-opentelemetry = "^0.18.0"
serde = { version = "^1.0.196", features = ["derive"] }
serde_json = "^1.0.113"
tokio = { version = "^1.36.0", features = ["signal", "macros"], optional = true}
tracing = "^0.1.40"
tracing-appender = "0.2.3"
tracing-opentelemetry = "^0.22.0"
tracing-serde = "^0.1.3"
tracing-subscriber = { version = "^0.3.16", features = ["env-filter", "json"] }
tracing-subscriber = { version = "^0.3.18", features = ["env-filter", "json"] }

[patch.crates-io]
axum-tracing-opentelemetry = { git = "https://github.com/fhsgoncalves/tracing-opentelemetry-instrumentation-sdk", branch = "0.10.0-with-span-type" }
axum-tracing-opentelemetry = { git = "https://github.com/fhsgoncalves/tracing-opentelemetry-instrumentation-sdk", branch = "0.10.0-with-span-type-and-otel-0.21" }
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ This crate contains the necessary glue to bridge the gap between OpenTelemetry,

The lib is configurable via environment variables as following:

| env var | default value | description |
|------------------------|---------------------------------------------|-----------------------------------------------------------|
| DD_ENABLED | false | Enables the datadog exporter and trace_id/span_id on logs |
| DD_SERVICE | <required> | Datadog service name |
| DD_AGENT_HOST | localhost | Datadog agent host |
| DD_AGENT_PORT | 8126 | Datadog agent port |
| RUST_LOG | info | |
| AXUM_TRACING_LOG_LEVEL | if DD_ENABLED=true, "info", otherwise "off" | |
| OTEL_LOG_LEVEL | debug | |
| env var | default value | description |
|------------------------|----------------------------------------------|-----------------------------------------------------------|
| DD_ENABLED | false | Enables the datadog exporter and trace_id/span_id on logs |
| DD_SERVICE | <required> | Datadog service name |
| DD_AGENT_HOST | localhost | Datadog agent host |
| DD_AGENT_PORT | 8126 | Datadog agent port |
| RUST_LOG | info | |
| AXUM_TRACING_LOG_LEVEL | if DD_ENABLED=true, "trace", otherwise "off" | |
| OTEL_LOG_LEVEL | debug | |


# Examples
Expand Down
1 change: 0 additions & 1 deletion src/axum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
//! [`axum-tracing-opentelemetry`]: https://github.com/davidB/axum-tracing-opentelemetry
pub use axum_tracing_opentelemetry::opentelemetry_tracing_layer;
pub use axum_tracing_opentelemetry::opentelemetry_tracing_layer_grpc;
use crate::shutdown::TracerShutdown;
use tokio::signal;

Expand Down
7 changes: 4 additions & 3 deletions src/init.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::env;
use opentelemetry::trace::TraceError;
use tracing::Subscriber;
use tracing_subscriber::registry::LookupSpan;
use tracing_subscriber::{EnvFilter, Layer, Registry};
Expand All @@ -7,20 +8,20 @@ use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::util::SubscriberInitExt;
use crate::formatter::DatadogFormatter;
use crate::shutdown::TracerShutdown;
use crate::tracer::{build_tracer, TraceError};
use crate::tracer::build_tracer;

fn loglevel_filter_layer(dd_enabled: bool) -> EnvFilter {
let log_level = env::var("RUST_LOG").unwrap_or_else(|_| "info".to_string());

// `axum_tracing_opentelemetry` should be a level info to emit opentelemetry trace & span
let axum_tracing_log_level = env::var("AXUM_TRACING_LOG_LEVEL").unwrap_or_else(|_| if dd_enabled { "info".to_string() } else { "off".to_string() });
let axum_tracing_log_level = env::var("AXUM_TRACING_LOG_LEVEL").unwrap_or_else(|_| if dd_enabled { "trace".to_string() } else { "off".to_string() });

// `otel::setup` set to debug to log detected resources, configuration read and infered
let otel_log_level = env::var("OTEL_LOG_LEVEL").unwrap_or_else(|_| "debug".to_string());

env::set_var(
"RUST_LOG",
format!("{log_level},axum_tracing_opentelemetry={axum_tracing_log_level},otel={otel_log_level}"),
format!("{log_level},otel::tracing={axum_tracing_log_level},otel={otel_log_level}"),
);

EnvFilter::from_default_env()
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ pub mod init;
pub mod shutdown;

pub use init::init;
pub use opentelemetry::global::shutdown_tracer_provider;
pub use opentelemetry::global::shutdown_tracer_provider;
13 changes: 6 additions & 7 deletions src/tracer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@
//!
//! It also contains a convenience function to build a layer with the tracer.
use std::env;
use std::sync::Arc;
use opentelemetry::sdk::trace::{RandomIdGenerator, Sampler, Tracer};
use opentelemetry::sdk::trace;
pub use opentelemetry::trace::{TraceError, TraceResult};
use opentelemetry_sdk::trace::{RandomIdGenerator, Sampler, Tracer};
use opentelemetry_sdk::trace;
use opentelemetry::global;
use std::time::Duration;
pub use opentelemetry::trace::{TraceError, TraceId, TraceResult};
use opentelemetry_datadog::{ApiVersion, DatadogPropagator};
use tracing::Subscriber;
use tracing_opentelemetry::{OpenTelemetryLayer, PreSampledTracer};
Expand All @@ -33,16 +32,16 @@ pub fn build_tracer() -> TraceResult<Tracer> {
.expect("Could not init datadog http_client");

let tracer = opentelemetry_datadog::new_pipeline()
.with_http_client::<reqwest::Client>(Arc::new(dd_http_client))
.with_http_client(dd_http_client)
.with_service_name(service_name)
.with_version(ApiVersion::Version05)
.with_api_version(ApiVersion::Version05)
.with_agent_endpoint(format!("http://{dd_host}:{dd_port}"))
.with_trace_config(
trace::config()
.with_sampler(Sampler::AlwaysOn)
.with_id_generator(RandomIdGenerator::default()),
)
.install_batch(opentelemetry::runtime::Tokio);
.install_batch(opentelemetry_sdk::runtime::Tokio);

global::set_text_map_propagator(DatadogPropagator::default());

Expand Down

0 comments on commit cac61d7

Please sign in to comment.