java-spring-jaeger icon indicating copy to clipboard operation
java-spring-jaeger copied to clipboard

Custom name for trace-id

Open czyzniek opened this issue 5 years ago • 4 comments

Hi!

Is there way to configure opentracing-spring-jaeger-cloud-starter to handle any other header than Uber-Trace-Id? I have Traefik as an ingress in my kubernetes cluster. Traefik can be configured to change traceContextHeaderName. Default value is "uber-trace-id". When I change it to some custom, there is no connection between services. I believe that opentracing works only with Uber-Trace-Id. Is there way to configure that?

Thanks for help!

czyzniek avatar Jul 02 '19 19:07 czyzniek

Hello,

I am personally not aware of something, but @pavolloffay is the expert on the subject

geoand avatar Jul 03 '19 08:07 geoand

I found culprit: io.jaegertracing.internal.propagation.TextMapCodec in jaeger-core dependency. There is private constant private static final String SPAN_CONTEXT_KEY = "uber-trace-id";. I believe we stuck with this. :(

czyzniek avatar Jul 03 '19 19:07 czyzniek

The context key is configurable on the builder inside the codec https://github.com/jaegertracing/jaeger-client-java/blob/88a849722d7056557a2643330737967d77b87f88/jaeger-core/src/main/java/io/jaegertracing/internal/propagation/TextMapCodec.java#L246.

This lib could use that builder and allow consumers to modify it before constructing the tracer.

pavolloffay avatar Jul 16 '19 13:07 pavolloffay

Temporary solution:

  @Bean
  public TracerBuilderCustomizer useCustomTraceIdHeader() {
    TextMapCodec httpCodec = TextMapCodec.builder()
      .withUrlEncoding(true)
      .withObjectFactory(new JaegerObjectFactory())
      .withSpanContextKey(CUSTOM_TRACE_ID)
      .build();
    return builder -> builder
      .registerInjector(HTTP_HEADERS, httpCodec)
      .registerExtractor(HTTP_HEADERS, httpCodec);
  }

privettoli avatar Jun 26 '20 21:06 privettoli