question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Return traceId in header response.

See original GitHub issue

Description To debug more easily an Ajax request I propose to return the traceId in response header.

image

image

image

Implementation ideas

I’ve follow this code https://github.com/quarkusio/quarkus/blob/master/extensions/jaeger/runtime/src/main/java/io/quarkus/jaeger/runtime/MDCScope.java

package com.damdamdeo.todo.publicfrontend.interfaces;

import io.jaegertracing.internal.JaegerSpanContext;
import io.opentracing.SpanContext;
import io.opentracing.Tracer;

import javax.inject.Inject;
import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.container.ContainerResponseContext;
import javax.ws.rs.container.ContainerResponseFilter;
import javax.ws.rs.ext.Provider;
import java.io.IOException;

@Provider
public class TraceIdResponseInjector implements ContainerResponseFilter {

    @Inject
    Tracer tracer;

    private static final String TRACE_ID = "traceId";

    @Override
    public void filter(final ContainerRequestContext requestContext, final ContainerResponseContext responseContext) throws IOException {
        final SpanContext spanContext = tracer.scopeManager().active().span().context();
        if (spanContext instanceof JaegerSpanContext) {
            responseContext.getHeaders().add(TRACE_ID, ((JaegerSpanContext) spanContext).getTraceId());
        }
    }

}

I guess it should be implemented in quarkus-smallrye-opentracing.

Regards,

Damien

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:1
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
Ladicekcommented, Sep 7, 2020

I think this makes sense, though there probably should be a configuration switch to turn it off. (I think it’s pretty safe to have it on by default, even in production, but some users in highly regulated environments would probably like to turn it off.)

CC @pavolloffay

0reactions
mellowarecommented, Aug 10, 2022

Yes similar to Spring Boot it should respect incoming HTTP headers for Trace/Span and always put them on the outgoing response. This way you can trace microservice to microservice calls across your organization. This is similar to what Spring Boot Slueth does.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Adding the traceId from Spring Cloud Sleuth to response
Using this method: MDC.get("traceId") will return a string with the value, and can do whatever you want with it. About putting that information...
Read more >
9. Customizations - Spring Cloud
In the following example we will register the TraceFilter bean and we will add the ZIPKIN-TRACE-ID response header containing the current Span's trace...
Read more >
HTTP header manipulation - Envoy Proxy
The trace ID, parent ID and sampling decision are added to HTTP requests in the tracing header. See more on AWS X-Ray tracing...
Read more >
OpenTelemetry Traceparent HTTP Header [Go] - Uptrace
Using the header, you can extract a trace id to find the trace in a distributed tracing tool open in new window, for...
Read more >
Transaction and Trace IDs - Pages - Support
If you sent a trace ID, a traceID object with that value is also returned in the wrapper object of the response. If...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found