Make auto-configured Brave Tracer more compliant with OTel tracer

By default we will not support joined spans and the trace ID will
be 128-bit.

See gh-32615
This commit is contained in:
Marcin Grzejszczak 2022-10-06 13:23:31 +02:00 committed by Andy Wilkinson
parent da7128ce7e
commit dfd148fb76
2 changed files with 25 additions and 2 deletions

View File

@ -92,8 +92,9 @@ public class BraveAutoConfiguration {
List<TracingCustomizer> tracingCustomizers, CurrentTraceContext currentTraceContext,
Factory propagationFactory, Sampler sampler) {
String applicationName = environment.getProperty("spring.application.name", DEFAULT_APPLICATION_NAME);
Builder builder = Tracing.newBuilder().currentTraceContext(currentTraceContext)
.propagationFactory(propagationFactory).sampler(sampler).localServiceName(applicationName);
Builder builder = Tracing.newBuilder().currentTraceContext(currentTraceContext).traceId128Bit(true)
.supportsJoin(false).propagationFactory(propagationFactory).sampler(sampler)
.localServiceName(applicationName);
for (SpanHandler spanHandler : spanHandlers) {
builder.addSpanHandler(spanHandler);
}

View File

@ -16,6 +16,7 @@
package org.springframework.boot.actuate.autoconfigure.tracing;
import brave.Span;
import brave.Tracer;
import brave.Tracing;
import brave.baggage.BaggagePropagation;
@ -211,6 +212,27 @@ class BraveAutoConfigurationTests {
.run((context) -> assertThat(context).hasBean("mdcCorrelationScopeDecoratorBuilder"));
}
@Test
void shouldHave128BitTraceId() {
this.contextRunner.run((context) -> {
Tracing tracing = context.getBean(Tracing.class);
Span span = tracing.tracer().nextSpan();
assertThat(span.context().traceIdString()).hasSize(32);
});
}
@Test
void shouldNotSupportJoinedSpans() {
this.contextRunner.run((context) -> {
Tracing tracing = context.getBean(Tracing.class);
Span parentSpan = tracing.tracer().nextSpan();
Span childSpan = tracing.tracer().joinSpan(parentSpan.context());
assertThat(parentSpan.context().traceIdString()).isEqualTo(childSpan.context().traceIdString());
assertThat(parentSpan.context().spanIdString()).isEqualTo(childSpan.context().parentIdString());
assertThat(parentSpan.context().spanIdString()).isNotEqualTo(childSpan.context().spanIdString());
});
}
@Configuration(proxyBeanMethods = false)
private static class CustomConfiguration {