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

Specify which exceptions SHOULD be recorded #761

Closed
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ the release.
New:

- Add resource semantic conventions for operating systems ([#693](https://github.com/open-telemetry/opentelemetry-specification/pull/693))
- Add Span API and semantic conventions for unhandled exceptions
Oberon00 marked this conversation as resolved.
Show resolved Hide resolved
([#697](https://github.com/open-telemetry/opentelemetry-specification/pull/697),
[#761](https://github.com/open-telemetry/opentelemetry-specification/pull/761))

Updates:

Expand Down
4 changes: 2 additions & 2 deletions specification/trace/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -510,8 +510,8 @@ MUST record an exception as an `Event` with the conventions outlined in the

Examples:

- `RecordException(exception: Exception)`
- `RecordException(type: String, message: String, stacktrace: String)`
- `RecordException(exception: Exception, leftScope: boolean? = null)`
- `RecordException(type: String, message: String, stacktrace: String, leftScope: boolean?)`

### Span lifetime

Expand Down
13 changes: 12 additions & 1 deletion specification/trace/semantic_conventions/exceptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,19 @@ exceptions.

## Recording an Exception

An exception SHOULD be recorded as an `Event` on the span during which it occurred.
An unhandled exception that leaves the scope of a span
SHOULD be recorded as an `Event` on that span.
Oberon00 marked this conversation as resolved.
Show resolved Hide resolved
An exception is considered to leave the scope of a span if the span is ended
while the exception is still "in flight"
Oberon00 marked this conversation as resolved.
Show resolved Hide resolved
(special considerations may apply for Go, where exception semantic conventions are used for non-exceptions).

The name of the event MUST be `"exception"`.

Note that multiple events (on the same or different Spans)
might be logged for the same exception object instance.
Oberon00 marked this conversation as resolved.
Show resolved Hide resolved
E.g. one event might be logged in an instrumented exception constructor
and another event might be logged when an exception leaves the scope of a span.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we do this? Can we avoid it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, it does add information about the path of the exception although the full stacktrace would not be relevant each time. I don't think this can be easily avoided.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm.. is the stacktrace not captured when the exception is generated (at least in some languages)? Also what is the point of having stacktrace twice?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no point, but you usually dont't know if the exception was already/will again be recorded.

Maybe a clever exporter can do de-duplication.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this is a "Note" stating what I think can happen in practice.

To allow improving this situation, we could do something like assign an ID to each exception when it is first observed and only record the ID for each further occurrence. But that's probably an after-ga thing.


## Attributes

The table below indicates which attributes should be added to the `Event` and
Expand All @@ -26,6 +36,7 @@ their types.
| exception.type | String | The type of the exception (its fully-qualified class name, if applicable). The dynamic type of the exception should be preferred over the static type in languages that support it. E.g. "java.net.ConnectException", "OSError" | One of `exception.type` or `exception.message` is required |
| exception.message | String | The exception message. E.g. `"Division by zero"`, `"Can't convert 'int' object to str implicitly"` | One of `exception.type` or `exception.message` is required |
| exception.stacktrace | String | A stacktrace as a string in the natural representation for the language runtime. The representation is to be determined and documented by each language SIG. E.g. `"Exception in thread \"main\" java.lang.RuntimeException: Test exception\n at com.example.GenerateTrace.methodB(GenerateTrace.java:13)\n at com.example.GenerateTrace.methodA(GenerateTrace.java:9)\n at com.example.GenerateTrace.main(GenerateTrace.java:5)"`. | No |
| exception.left_scope | Bool | SHOULD be set to true if the exception event is recoded while observing the exception leaving the scope of the span. Note that an exception may still leave the scope of the span even if this was not set or set to false, if the event was recorded at an earlier time. | No |

### Stacktrace Representation

Expand Down