SleuthSpanContextSupplier should take sampling decision into consideration
fixes gh-2116
This commit is contained in:
@@ -43,13 +43,13 @@ public class SleuthSpanContextSupplier implements SpanContextSupplier {
|
||||
@Override
|
||||
public String getTraceId() {
|
||||
Span span = tracer.currentSpan();
|
||||
return span != null ? span.context().traceId() : null;
|
||||
return (span != null && span.context().sampled()) ? span.context().traceId() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSpanId() {
|
||||
Span span = tracer.currentSpan();
|
||||
return span != null ? span.context().spanId() : null;
|
||||
return (span != null && span.context().sampled()) ? span.context().spanId() : null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -54,11 +54,24 @@ class SleuthSpanContextSupplierTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_provide_values_from_tracer_if_span_is_available() {
|
||||
void should_provide_null_values_if_span_is_available_but_not_sampled() {
|
||||
Span span = mock(Span.class);
|
||||
TraceContext context = mock(TraceContext.class);
|
||||
when(tracer.currentSpan()).thenReturn(span);
|
||||
when(span.context()).thenReturn(context);
|
||||
when(context.sampled()).thenReturn(false);
|
||||
|
||||
assertThat(spanContextSupplier.getTraceId()).isNull();
|
||||
assertThat(spanContextSupplier.getSpanId()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_provide_values_from_tracer_if_span_is_available_and_sampled() {
|
||||
Span span = mock(Span.class);
|
||||
TraceContext context = mock(TraceContext.class);
|
||||
when(tracer.currentSpan()).thenReturn(span);
|
||||
when(span.context()).thenReturn(context);
|
||||
when(context.sampled()).thenReturn(true);
|
||||
when(context.traceId()).thenReturn("42");
|
||||
when(context.spanId()).thenReturn("24");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user