Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

document how to use micrometer tracing with spring starter #11039

Open
zeitlinger opened this issue Apr 5, 2024 · 4 comments
Open

document how to use micrometer tracing with spring starter #11039

zeitlinger opened this issue Apr 5, 2024 · 4 comments
Assignees
Labels
documentation Improvements or additions to documentation spring boot starter

Comments

@zeitlinger
Copy link
Member

zeitlinger commented Apr 5, 2024

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.

@zeitlinger zeitlinger added documentation Improvements or additions to documentation spring boot starter labels Apr 5, 2024
@zeitlinger zeitlinger self-assigned this Apr 11, 2024
@zeitlinger
Copy link
Member Author

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):

image

after:

image

@zeitlinger
Copy link
Member Author

@jeanbisutti should we document this? should we include the "suppress double spans" code in the starter?

@trask
Copy link
Member

trask commented Apr 11, 2024

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

@jeanbisutti
Copy link
Member

@zeitlinger @trask We could discuss during the Java SIG and potentially close this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation spring boot starter
Projects
Status: No status
Development

No branches or pull requests

3 participants