We are using Springboot 3.1.4 and i have been trying to leverage the Micrometer based approach for distrubted tracing of the application. I have included the right build.gradle dependencies but the traces are only working for the health checkpoints and nothing else. Looking deeper I noticed a strange behavior. There are 2 flows i tested:
Flow 1 -> REST call to service 1 -> JMS Publish to service 2 method
Flow 2 -> REST call to service 2 method
In both cases, the incoming service received a PropagatedSpan with traceFlags=00. In this case no traces/spans got captured/sent.
({opentelemetry-trace-span-key=PropagatedSpan{ImmutableSpanContext{traceId=a2ea0716a45d02a490d7cef097acdb9a, spanId=adb8f982d4294b13, traceFlags=00, traceState=ArrayBasedTraceState{entries=[]}, remote=false, valid=true}}, opentelemetry-baggage-key={}, otelTraceContext=ImmutableSpanContext{traceId=a2ea0716a45d02a490d7cef097acdb9a, spanId=adb8f982d4294b13, traceFlags=00, traceState=ArrayBasedTraceState{entries=[]}, remote=false, valid=true}})
However, when the service 2 received the request from service 1 in Flow 1, it received the span as a SDKSpan with traceFlags=01. When this happens, i see the traces/spans captured for the service 2 (not service 1).
({opentelemetry-baggage-key={}, opentelemetry-trace-span-key=SdkSpan{traceId=c92ee058c19d5288d6cc72d2bb9c2a3b, spanId=5797df5b5620f02d, parentSpanContext=ImmutableSpanContext{traceId=00000000000000000000000000000000, spanId=0000000000000000, traceFlags=00, traceState=ArrayBasedTraceState{entries=[]}, remote=false, valid=false}, name=, kind=SERVER, attributes=null, status=ImmutableStatusData{statusCode=UNSET, description=}, totalRecordedEvents=0, totalRecordedLinks=0, startEpochNanos=1727214899985765169, endEpochNanos=0}, otelTraceContext=ImmutableSpanContext{traceId=c92ee058c19d5288d6cc72d2bb9c2a3b, spanId=5797df5b5620f02d, traceFlags=01, traceState=ArrayBasedTraceState{entries=[]}, remote=false, valid=true}}
Is there a way i can make the incoming trace/span to leverage SDKSpan instead of PropagatedSpan, which seems to block even the custom spans i created?
Any other way to address this issue? Thank you in advance!
SG
In Springboot 3.1.4 there’s a change only health checkpoints are traced by default. There is also this in the logs : traceFlags=00
it indicates that requests will not be traced.
I would suggest doing the following:
1- Activating sampling to trace requests and add it in your application.yml properties file :
opentelemetry:
tracing:
endpoint: "http://your-otel-collector:4317"
sampling-rate: 1 # 100% of traces
2- Create tracing config and configure it with OpenTelemetry :
@Configuration
public class OpenTelemetryConfig {
@Bean
public SdkTracerProvider sdkTracerProvider() {
// Create a span exporter (you can choose other exporters)
OtlpGrpcSpanExporter spanExporter = OtlpGrpcSpanExporter.builder()
.setEndpoint("http://your-otel-collector:4317")
.setTimeout(Duration.ofSeconds(2))
.build();
// Configure the SDK with a batch span processor
return SdkTracerProvider.builder()
.addSpanProcessor(BatchSpanProcessor.builder(spanExporter).build())
.build();
}
@Bean
public OpenTelemetry openTelemetry(SdkTracerProvider sdkTracerProvider) {
// Initialize OpenTelemetry with the TracerProvider
return OpenTelemetrySdk.builder()
.setTracerProvider(sdkTracerProvider)
.buildAndRegisterGlobal();
}
@Bean
public Tracer tracer(OpenTelemetry openTelemetry) {
// This will create a tracer with the name of your application
return openTelemetry.getTracer("your-application-name");
}
}
3- Make sure tracing is propagated properly as interceptor :
@Configuration
public class RestTemplateConfig {
@Autowired
private RestTemplateBuilder restTemplateBuilder;
@Bean
public RestTemplate restTemplate() {
TextMapPropagator propagator = GlobalOpenTelemetry.getPropagators().getTextMapPropagator();
return restTemplateBuilder
.additionalInterceptors((request, body, execution) -> {
propagator.inject(Context.current(), request, (req, key, value) -> req.getHeaders().set(key, value));
return execution.execute(request, body);
})
.build();
}
}
9