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

Not getting trace id and span id when application crash #684

Open
tech-ind-02 opened this issue Nov 7, 2024 · 6 comments
Open

Not getting trace id and span id when application crash #684

tech-ind-02 opened this issue Nov 7, 2024 · 6 comments
Labels
needs author feedback Waiting for additional feedback from the author

Comments

@tech-ind-02
Copy link

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 !!!

image

@LikeTheSalad
Copy link
Contributor

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.

@tech-ind-02
Copy link
Author

tech-ind-02 commented Nov 12, 2024

@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.

@LikeTheSalad
Copy link
Contributor

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 span.makeCurrent() as I showed in my previous example. Logs on their own can't have a trace_id and span_id, that's something outside the scope of this project.

because seems changes required in instrumentation module

Can you please elaborate a bit more on what changes and where are you referring to?

@LikeTheSalad
Copy link
Contributor

LikeTheSalad commented Nov 13, 2024

what change i need to do in above line.

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.

@breedx-splk
Copy link
Contributor

@tech-ind-02 did the advice from @LikeTheSalad work out for you? 🙏🏻

@breedx-splk breedx-splk added the needs author feedback Waiting for additional feedback from the author label Dec 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs author feedback Waiting for additional feedback from the author
Projects
None yet
Development

No branches or pull requests

3 participants