mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-06 13:27:43 +00:00
fix(tracing): Fix distributed tracing context linking (#2247)
This commit is contained in:
@@ -35,6 +35,7 @@ use hyper_util::{
|
||||
};
|
||||
use metrics::{counter, histogram};
|
||||
use opentelemetry::global;
|
||||
use opentelemetry::trace::TraceContextExt;
|
||||
use rustfs_common::GlobalReadiness;
|
||||
use rustfs_config::{RUSTFS_TLS_CERT, RUSTFS_TLS_KEY};
|
||||
use rustfs_ecstore::rpc::{TONIC_RPC_PREFIX, verify_rpc_signature};
|
||||
@@ -636,7 +637,7 @@ fn process_connection(
|
||||
.layer(
|
||||
TraceLayer::new_for_http()
|
||||
.make_span_with(|request: &HttpRequest<_>| {
|
||||
let trace_id = request
|
||||
let request_id = request
|
||||
.headers()
|
||||
.get(http::header::HeaderName::from_static("x-request-id"))
|
||||
.and_then(|v| v.to_str().ok())
|
||||
@@ -646,6 +647,18 @@ fn process_connection(
|
||||
propagator.extract(&HeaderMapCarrier::new(request.headers()))
|
||||
});
|
||||
|
||||
// Log trace context extraction for debugging distributed tracing
|
||||
if parent_context.has_active_span() {
|
||||
let span_ref = parent_context.span();
|
||||
debug!(
|
||||
otel_trace_id = %span_ref.span_context().trace_id(),
|
||||
otel_parent_span_id = %span_ref.span_context().span_id(),
|
||||
sampled = span_ref.span_context().is_sampled(),
|
||||
"Extracted trace context from incoming request headers"
|
||||
);
|
||||
} else {
|
||||
debug!("No trace context found in request headers, will create root span");
|
||||
}
|
||||
// Extract real client IP from trusted proxy middleware if available
|
||||
let client_info = request.extensions().get::<ClientInfo>();
|
||||
let real_ip = client_info
|
||||
@@ -653,7 +666,7 @@ fn process_connection(
|
||||
.unwrap_or_else(|| "unknown".to_string());
|
||||
|
||||
let span = tracing::info_span!("http-request",
|
||||
trace_id = %trace_id,
|
||||
request_id = %request_id,
|
||||
status_code = tracing::field::Empty,
|
||||
method = %request.method(),
|
||||
real_ip = %real_ip,
|
||||
|
||||
Reference in New Issue
Block a user