Replies: 2 comments
-
|
still have a same problem |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
Omg at last it works! use axum::{body::Body, http::Request, middleware::Next, response::Response};
use opentelemetry::{
Context, SpanId, TraceId,
trace::{SpanContext, TraceContextExt, TraceFlags, TraceState},
};
use tracing::{Level, span, warn};
use tracing_opentelemetry::OpenTelemetrySpanExt;
async fn tracing_middleware(req: Request<Body>, next: Next<Body>) -> Response {
if let Some((trace_id, span_id)) = req
.headers()
.get("traceparent")
.and_then(|h| h.to_str().ok())
.and_then(parse_traceparent)
{
let span_context = SpanContext::new(
trace_id,
span_id,
TraceFlags::default(),
true, // is_remote
TraceState::default(),
);
let otel_context = Context::new().with_remote_span_context(span_context);
let tracing_span = span!(Level::INFO, "Incoming http");
if let Err(e) = tracing_span.set_parent(otel_context) {
warn!("set_parent err: {e}");
}
let _tracing_guard = tracing_span.enter();
handle_request(req, next).await
} else {
handle_request(req, next).await
}
}
async fn handle_request(req: Request<Body>, next: Next<Body>) -> Response {
todo!()
}
fn parse_traceparent(header: &str) -> Option<(TraceId, SpanId)> {
todo!()
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, I have been trying to make use of tracing + opentelemetry crates to instrument my code for distributed tracing purposes. I intend to have an http request pass through my service, there will be calls to subsequent services that I am addding
traceparentheaders to, according to the W3C trace-context spec:I am seeing different traceid when comparing traceparent sent to the downstream service and the x-trace-id response header, what am I doing wrong?
Beta Was this translation helpful? Give feedback.
All reactions