diff --git a/src/axum/middleware.rs b/src/axum/middleware.rs index 9f1fe67..78893a9 100644 --- a/src/axum/middleware.rs +++ b/src/axum/middleware.rs @@ -42,7 +42,6 @@ use std::{ task::{Context, Poll}, }; use tower::{Layer, Service}; -use tracing::field::Empty; use tracing::Span; use tracing_opentelemetry_instrumentation_sdk::http as otel_http; diff --git a/src/formatter.rs b/src/formatter.rs index efe346e..d1ac1b9 100644 --- a/src/formatter.rs +++ b/src/formatter.rs @@ -42,8 +42,8 @@ impl From for DatadogId { } fn lookup_trace_info(span_ref: &SpanRef) -> Option - where - S: Subscriber + for<'a> LookupSpan<'a>, +where + S: Subscriber + for<'a> LookupSpan<'a>, { span_ref.extensions().get::().map(|o| { let trace_id = if o.parent_cx.has_active_span() { @@ -62,9 +62,9 @@ fn lookup_trace_info(span_ref: &SpanRef) -> Option pub struct DatadogFormatter; impl FormatEvent for DatadogFormatter - where - S: Subscriber + for<'lookup> LookupSpan<'lookup>, - N: for<'writer> FormatFields<'writer> + 'static, +where + S: Subscriber + for<'lookup> LookupSpan<'lookup>, + N: for<'writer> FormatFields<'writer> + 'static, { fn format_event( &self, @@ -72,8 +72,8 @@ impl FormatEvent for DatadogFormatter mut writer: Writer<'_>, event: &Event<'_>, ) -> std::fmt::Result - where - S: Subscriber + for<'a> LookupSpan<'a>, + where + S: Subscriber + for<'a> LookupSpan<'a>, { let meta = event.metadata(); @@ -159,4 +159,4 @@ mod tests { assert_eq!(datadog_id.0, 6359193864645272721); } -} \ No newline at end of file +} diff --git a/src/init.rs b/src/init.rs index 0a36a96..c21e3fe 100644 --- a/src/init.rs +++ b/src/init.rs @@ -1,20 +1,26 @@ -use std::env; +use crate::formatter::DatadogFormatter; +use crate::shutdown::TracerShutdown; +use crate::tracer::build_tracer; use opentelemetry::trace::TraceError; +use std::env; use tracing::Subscriber; -use tracing_subscriber::registry::LookupSpan; -use tracing_subscriber::{EnvFilter, Layer, Registry}; use tracing_appender::non_blocking::{NonBlocking, WorkerGuard}; use tracing_subscriber::layer::SubscriberExt; +use tracing_subscriber::registry::LookupSpan; use tracing_subscriber::util::SubscriberInitExt; -use crate::formatter::DatadogFormatter; -use crate::shutdown::TracerShutdown; -use crate::tracer::build_tracer; +use tracing_subscriber::{EnvFilter, Layer, Registry}; 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 { "trace".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()); @@ -27,9 +33,12 @@ fn loglevel_filter_layer(dd_enabled: bool) -> EnvFilter { EnvFilter::from_default_env() } -fn log_layer(dd_enabled: bool, non_blocking: NonBlocking) -> Box + Send + Sync + 'static> - where - S: Subscriber + for<'a> LookupSpan<'a>, +fn log_layer( + dd_enabled: bool, + non_blocking: NonBlocking, +) -> Box + Send + Sync + 'static> +where + S: Subscriber + for<'a> LookupSpan<'a>, { if dd_enabled { Box::new( @@ -44,7 +53,6 @@ fn log_layer(dd_enabled: bool, non_blocking: NonBlocking) -> Box } pub fn init() -> Result<(WorkerGuard, TracerShutdown), TraceError> { - let (non_blocking, guard) = tracing_appender::non_blocking(std::io::stdout()); let dd_enabled = env::var("DD_ENABLED").map(|s| s == "true").unwrap_or(false); @@ -62,5 +70,5 @@ pub fn init() -> Result<(WorkerGuard, TracerShutdown), TraceError> { .with(telemetry_layer) .init(); - Ok((guard, TracerShutdown{})) + Ok((guard, TracerShutdown {})) } diff --git a/src/tracer.rs b/src/tracer.rs index f48ffc6..8a883fb 100644 --- a/src/tracer.rs +++ b/src/tracer.rs @@ -4,13 +4,13 @@ //! to send traces to the Datadog agent in batches over gRPC. //! //! It also contains a convenience function to build a layer with the tracer. -use std::env; -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 opentelemetry_sdk::trace; +use opentelemetry_sdk::trace::{RandomIdGenerator, Sampler, Tracer}; +use std::env; +use std::time::Duration; use tracing::Subscriber; use tracing_opentelemetry::{OpenTelemetryLayer, PreSampledTracer}; use tracing_subscriber::registry::LookupSpan; @@ -19,9 +19,9 @@ pub fn build_tracer() -> TraceResult { let service_name = env::var("DD_SERVICE") .map_err(|_| <&str as Into>::into("missing DD_SERVICE"))?; - let dd_host = env::var("DD_AGENT_HOST").unwrap_or("localhost".to_string()); - let dd_port = env::var("DD_AGENT_PORT").ok() + let dd_port = env::var("DD_AGENT_PORT") + .ok() .and_then(|it| it.parse::().ok()) .unwrap_or(8126);