Is it possible to include parent_span_id in auto-instrumented logs? #13876
-
Description:Hi OpenTelemetry team, First, thank you for your work on this incredible instrumentation library! I’m exploring ways to correlate logs with tracing spans in our Java application. Currently, logs automatically include Questions:
Use Case:When analyzing logs (e.g., in ELK), having parent_span_id would let us:
Thank you for your time! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
no, there isn't
It is a bit problematic since the opentelemetry java api provided by https://github.com/open-telemetry/opentelemetry-java that this project uses does not provide a way to get the parent span. To get the parent span one has to go through the sdk classes such as https://github.com/open-telemetry/opentelemetry-java/blob/cc7d0855e7f04e529c794b965e247a86d052426c/sdk/trace/src/main/java/io/opentelemetry/sdk/trace/ReadableSpan.java#L36 |
Beta Was this translation helpful? Give feedback.
I doubt that we'll be adding this any time soon, but if you so wish you can probably get
parent_span_id
added to mdc yourself. If you are not using the agent then casting toReadableSpan
should succeed. If you use agent then in the agent extension casting toReadableSpan
should also succeed. If you are using agent and wish to do it in application code then you could use reflection to callopentelemetry-java-instrumentation/instrumentation/opentelemetry-api/opentelemetry-api-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/opentelemetryapi/trace/Bridging.java
Line 72 in 114ae39