Skip to content

Getting different trace Id when using @ControllerAdvice in Java with Opentelemetry #12447

Closed Answered by laurit
keerthanacv asked this question in Q&A
Discussion options

You must be logged in to vote

The reason you get separate traces is that by the time the exception handler is run your span in PortalController is already completed. Since there is no active trace creating a new span in the exception handler will also start a new trace. To overcome this you can either somehow pass your span from the PortalController to the exception handler so you could use it as the parent span, which is probably not a good idea, or you could create a span that surrounds the whole request and would be the parent for both the span you create in PortalController and exception handler. My advice to you would be to use the spring boot starter or the java agent https://opentelemetry.io/docs/zero-code/java/

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@keerthanacv
Comment options

@laurit
Comment options

Answer selected by keerthanacv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants