user1800752
user1800752

Reputation: 23

Is there a way to rename traceId and spanId?

Given the following logging layout pattern:

appender.console.layout.pattern = %d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} - [%X{newTraceIdPlaceholder}, %X{newSpanIdPlaceholder}] - %X{Request-Uri} - %msg%n

Is there a way to tell Sleuth to consider the "newTraceIdPlaceholder" and "newSpanIdPlaceholder" fields as traceId and spanId?

Upvotes: 1

Views: 443

Answers (1)

Marcin Grzejszczak
Marcin Grzejszczak

Reputation: 11189

You would have to register your own bean of Brave's CorrelationScopeCustomizer type and over there you can provide additional fields in a similar manner to this:

CurrentTraceContext.ScopeDecorator create() {
    return new Builder()
      .clear()
      .add(SingleCorrelationField.create(BaggageFields.TRACE_ID))
      .add(SingleCorrelationField.create(BaggageFields.PARENT_ID))
      .add(SingleCorrelationField.create(BaggageFields.SPAN_ID))
      .add(SingleCorrelationField.create(BaggageFields.SAMPLED))
      .build();
  }

You can provide your own fields there

Upvotes: 1

Related Questions