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

recordException should support chained exceptions #941

Open
dvoytenko opened this issue Oct 26, 2023 · 5 comments
Open

recordException should support chained exceptions #941

dvoytenko opened this issue Oct 26, 2023 · 5 comments
Assignees

Comments

@dvoytenko
Copy link

What are you trying to achieve?

Many languages support a concept of a chained exception. For instance, JavaScript has Error.cause. Java also has Throwable.getCause(). When present, is just as important (and often more so), than the wrapping exception. Currently recordException() loses this information.

It'd be valuable to clarify whether the relevant languages should support the cause and how.

@trask
Copy link
Member

trask commented Oct 31, 2023

fwiw, OpenTelemetry Java SDK implementation of recordException uses Throwable.printStackTrace() which does include the full causal chain

@dvoytenko
Copy link
Author

It might be good to clarify a construction of the unified stack trace in other languages, since not all of them do this.

However, I also think that combining stack traces is not enough. The "cause" exceptions often have valuable metadata, such as HTTP status codes and other attributes. Ideally there'd be a way to preserve it all.

@MrAlias
Copy link
Contributor

MrAlias commented Nov 1, 2023

Please provide a comprehensive breakdown of what this would mean for all the languages OTel is implemented in. It is not obvious how this would apply to all languages, especially non-object-oriented languages or those that do not use exceptions as control flow.

@dvoytenko
Copy link
Author

In JavaScript, the errors can be chained and accessed using error.cause. If someone needs the full stack, they are expected to interrogate error.cause recursively - it's not an automatic behavior. We could document for an appropriate OTEL library to combine all stacks (see open-telemetry/opentelemetry-js#4227). However, the issue might be deeper, since the errors also contain important metadata, including code, name, and other fields/attributes.

The data model for this could be presented as:

Error {
  exception.type: "",
  exception.message: "",
  exception.stacktrace: "",
  exception.cause: {
    exception.type: "",
    exception.message: "",
    exception.stacktrace: "",
    exception.cause: { ... }
  }
}

However, it's not clear how to codify this in OTEL data model:

  1. Attributes do not allow nested sub-structures. Only primitives and arrays-of-primitves are allowed. This could be extended (Support map values and nested values for attributes opentelemetry-specification#376) and may already be possible in LogRecord (Align Embedded Logs data model with Standalone Logs data model opentelemetry-specification#622).
  2. "Error event" data model could be extended to allow sub-events.
  3. A library may already chose to add each error in a chain in a flat "error event" list. However, this would lose the parent/child relationships between errors.

@tigrannajaryan tigrannajaryan transferred this issue from open-telemetry/opentelemetry-specification Apr 19, 2024
@NicholasGWK
Copy link

NicholasGWK commented Dec 3, 2024

Just ran into this problem as well and ended up here. Has there been any further discussion?

I don't really have anything to contribute other than expressing support for tackling this...would chaining span events somehow be an option?

Thanks!

Update: You CAN call span.recordException multiple times which creates a span events for every exception.

I guess it'd be possible to use that to unwind the error.cause chain at the point where you actually record the exception, but not sure if this would be something recommended/considered by the spec or just happens to work :P

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants