Getting different trace Id when using @ControllerAdvice in Java with Opentelemetry #12447
-
I'm using @ControllerAdvice to handle all the exceptions in java, but I'm receiving a different trace Id, when an exception is thrown @ControllerAdvice
|
Beta Was this translation helpful? Give feedback.
Answered by
laurit
Oct 16, 2024
Replies: 1 comment 2 replies
-
Please provide minimal application that reproduces your issue along with any instructions necessary. |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 thePortalController
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 inPortalController
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/ …