document how to use micrometer tracing with spring starter
zeitlinger opened this issue · comments
It should work by adding runtimeOnly "io.micrometer:micrometer-tracing-bridge-otel"
to the dependencies.
Not sure if this should be included in the starter by default.
Here's how to do it:
Dependencies:
implementation "io.micrometer:micrometer-tracing-bridge-otel"
Enable support for @NewSpan
- which is from micrometer tracing.
management:
observations:
annotations:
enabled: true
Use @NewSpan
@Service
public class DemoService {
@NewSpan
public String sayHello() {
return "hello LGTM";
}
}
I didn't test any more advanced features of micrometer tracing - so it's possible there are some rough edges.
Config to suppress double spans:
@Bean
public DefaultTracingObservationHandler defaultTracingObservationHandler(Tracer tracer) {
return new DefaultTracingObservationHandler(tracer) {
@Override
public void onStop(Observation.Context context) {
// no-op
}
@Override
public void onStart(Observation.Context context) {
// no-op
}
};
}
@Bean
public PropagatingReceiverTracingObservationHandler<?> propagatingReceiverTracingObservationHandler(Tracer tracer,
Propagator propagator) {
return new PropagatingReceiverTracingObservationHandler<>(tracer, propagator) {
@Override
public void onError(ReceiverContext context) {
// no-op
}
@Override
public void onStop(ReceiverContext context) {
// no-op
}
};
}
@Bean
public PropagatingSenderTracingObservationHandler<?> propagatingSenderTracingObservationHandler(Tracer tracer,
Propagator propagator) {
return new PropagatingSenderTracingObservationHandler<>(tracer, propagator) {
@Override
public void onError(SenderContext context) {
// no-op
}
@Override
public void onStop(SenderContext context) {
// no-op
}
};
}
before (with double spans):
after:
@jeanbisutti should we document this? should we include the "suppress double spans" code in the starter?
I don't believe supporting micrometer-tracing-bridge-otel
is in scope for us, so would prefer not to document it
in the past the spring folks have suggested they may donate the bridge to opentelemetry-java-contrib repository, in which case we could document it there
@zeitlinger @trask We could discuss during the Java SIG and potentially close this issue
I don't believe supporting micrometer-tracing-bridge-otel is in scope for us, so would prefer not to document it
that's what we agreed to