Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions axum-tracing-opentelemetry/src/middleware/trace_extractor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ where
}

fn call(&mut self, req: Request<B>) -> Self::Future {
use tracing_opentelemetry::OpenTelemetrySpanExt;
use tracing_opentelemetry::{OpenTelemetrySpanExt, SetParentError};
let req = req;
let span = if self.filter.is_none_or(|f| f(req.uri().path())) {
let route = http_route(&req);
Expand All @@ -162,7 +162,12 @@ where
span.record(CLIENT_ADDRESS, client_ip);
}
if let Err(error) = span.set_parent(otel_http::extract_context(req.headers())) {
tracing::warn!(?error, "can not set parent trace_id to span");
match error {
SetParentError::LayerNotFound | SetParentError::AlreadyStarted => {
tracing::warn!(?error, "can not set parent trace_id to span");
}
SetParentError::SpanDisabled => {}
}
}
span
} else {
Expand Down
2 changes: 1 addition & 1 deletion tonic-tracing-opentelemetry/src/middleware/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use tracing_opentelemetry_instrumentation_sdk::{find_context_from_tracing, http
/// - propagate `OpenTelemetry` context (`trace_id`,...) to server
/// - create a Span for `OpenTelemetry` (and tracing) on call
///
/// `OpenTelemetry` context are extracted frim tracing's span.
/// `OpenTelemetry` context are extracted from tracing's span.
#[derive(Default, Debug, Clone)]
pub struct OtelGrpcLayer;

Expand Down
11 changes: 8 additions & 3 deletions tonic-tracing-opentelemetry/src/middleware/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub type Filter = fn(&str) -> bool;
/// - propagate `OpenTelemetry` context (`trace_id`, ...) to server
/// - create a Span for `OpenTelemetry` (and tracing) on call
///
/// `OpenTelemetry` context are extracted frim tracing's span.
/// `OpenTelemetry` context are extracted from tracing's span.
#[derive(Default, Debug, Clone)]
pub struct OtelGrpcLayer {
filter: Option<Filter>,
Expand Down Expand Up @@ -72,7 +72,7 @@ where
}

fn call(&mut self, req: Request<B>) -> Self::Future {
use tracing_opentelemetry::OpenTelemetrySpanExt;
use tracing_opentelemetry::{OpenTelemetrySpanExt, SetParentError};
// This is necessary because tonic internally uses `tower::buffer::Buffer`.
// See https://github.com/tower-rs/tower/issues/547#issuecomment-767629149
// for details on why this is necessary
Expand All @@ -82,7 +82,12 @@ where
let span = if self.filter.is_none_or(|f| f(req.uri().path())) {
let span = otel_http::grpc_server::make_span_from_request(&req);
if let Err(error) = span.set_parent(otel_http::extract_context(req.headers())) {
tracing::warn!(?error, "can not set parent trace_id to span");
match error {
SetParentError::LayerNotFound | SetParentError::AlreadyStarted => {
tracing::warn!(?error, "can not set parent trace_id to span");
}
SetParentError::SpanDisabled => {}
}
}
span
} else {
Expand Down