Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to retrieve traceId for observability in routes #2802

Closed
christian-morin opened this issue Jun 17, 2021 · 3 comments
Closed

Ability to retrieve traceId for observability in routes #2802

christian-morin opened this issue Jun 17, 2021 · 3 comments

Comments

@christian-morin
Copy link

christian-morin commented Jun 17, 2021

When adding the camel-quarkus-opentracing dependency, camel will output Jaeger traces using the Quarkus Opentracing tracer. However, it seems it initiates the Span after the Routes have finished?

When using Opentracing with Quarkus, I'm able to do for e.g:

@Path("/")
public class ApplicationResource {

  @Inject
  Tracer tracer;

  @GET
  @Path("/quarkus-jaeger")
  public Response quarkusJaeger() {

    JaegerSpanContext spanCtx = ((JaegerSpan)tracer.activeSpan()).context();

    log.info("Quarkus Jaeger traceId=" + spanCtx.getTraceId());

    return Response.status(Response.Status.OK).build();
  }

And it'll print the traceId:

ApplicationResource : Quarkus Jaeger traceId=a962e2a875c9248c

Also if I add the log format for e.g:

quarkus:
  log:
    console:
      format: "%d{yyyy-MM-dd HH:mm:ss.SSS} %5p [%X{traceId},%X{spanId},%X{sampled}] %i --- [%15.15t] %c{2.} : %s%e%n"

It'll print the current traceId and spanId in every log output:

2021-06-17 11:24:34.597  INFO [a962e2a875c9248c,a962e2a875c9248c,true] 4314 --- [executor-thread] se.in.ApplicationResource : Quarkus Jaeger traceId=a962e2a875c9248c

This is very beneficial as I'm able to go from log to trace very easily. When logging an error I can quickly go from that error log to see the entire trace from the traceId.

But in Camel-Quarkus, it seems there's no current activeSpan() when processing routes? Nowhere in my code/setup am I able to printout/retrieve the current traceId. And the logs doesn't include the traceId by default when using the log-format above. Is this an architectural limitation, or possible to initiate an active Span to be used inside a Route somehow?

@jamesnetherton
Copy link
Contributor

With a bean or processor where you have access to the exchange, something like this may work from a route:

.process(new Processor() {
    @Override
    public void process(Exchange exchange) throws Exception {
        OpenTracingSpanAdapter adapter = (OpenTracingSpanAdapter) ActiveSpanManager.getSpan(exchange);
        System.out.println("=======>" + adapter.getOpenTracingSpan().context().toTraceId());
    }
})

@christian-morin
Copy link
Author

christian-morin commented Jun 18, 2021

Yes, that worked! The context on my OpenTracingSpanAdapter didn't have a toTraceId() method though, but casting the Span to a JaegerSpan made me able to retrieve it.

OpenTracingSpanAdapter adapter = (OpenTracingSpanAdapter) ActiveSpanManager.getSpan(exchange);
JaegerSpanContext spanCtx = ((JaegerSpan)adapter.getOpenTracingSpan()).context();
System.out.println("=======>" + spanCtx.getTraceId());

@jamesnetherton
Copy link
Contributor

Glad it worked for you! If there's anything else required for this issue, feel free to reopen it.

@ppalaga ppalaga added this to the No fix/wont't fix milestone Oct 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants