-
Notifications
You must be signed in to change notification settings - Fork 42
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
Not getting trace id and span id when application crash #684
Comments
Hi! OpenTelemetry has 3 types of data, called signals, which are Traces, Metrics and Logs. Trace id and Span id attrs are only present when there's a Span involved, and application crashes are sent using Logs instead. However, Logs can get the span and trace id attrs if they are created inside a Span, for example: // This function only sends a log and there are no spans involved, so the log won't get any span id nor trace id info:
fun sendLogOnly() {
val openTelemetry: OpenTelemetry
openTelemetry.logsBridge.get("myLogger").logRecordBuilder().setBody("Log body").emit()
}
// This other function creates a log with trace and span id:
fun sendLogWithTraceInfo() {
val openTelemetry: OpenTelemetry
val span = openTelemetry.getTracer("myTracer").spanBuilder("My Span").startSpan()
span.makeCurrent().use {
// This log is created inside a span, so it will get the trace attrs.
openTelemetry.logsBridge.get("myLogger").logRecordBuilder().setBody("Log body").emit()
}
span.end()
} For more info on how to create spans and logs, I'd suggest taking a look at the Java docs: https://opentelemetry.io/docs/languages/java/ OTel Android sends crashes as Log signals, which means that there has to be an active span in the same thread where the crash occurred for it to contain trace attrs. So you will probably get some crashes with this info and some others without it. In theory, the more spans you have around your app, the more chances there will be of crashes containing this info. |
@LikeTheSalad Is it possible you to share new version of android agent library which will have span_id and trace_id. because seems changes required in instrumentation module. |
I'm not sure I'm following. If you'd like to see trace_id and span_id in logs you need to make sure to have a Span marked as "current", by calling
Can you please elaborate a bit more on what changes and where are you referring to? |
Nothing, as long as there's a span marked as "current" in the thread, that log should be provided with the trace and span ids. For example: fun crashWithTraceInfo() {
val openTelemetry: OpenTelemetry
val span = openTelemetry.getTracer("myTracer").spanBuilder("My Span").startSpan()
span.makeCurrent().use {
throw RuntimeException() // This crash should contain the trace and span ids from the span marked as current in the line above.
}
span.end()
} I haven't tested it, though in theory that's the way you should be able to get trace info in crashes. |
@tech-ind-02 did the advice from @LikeTheSalad work out for you? 🙏🏻 |
Hello,
I am new to otel and android both. After running demo app i have followed steps to make application crash.
here i am getting logs in otel collector but not getting trace id and span id for same.
Pls help !!!
The text was updated successfully, but these errors were encountered: