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

[Logs] Add semantic conventions for writing exceptions #2819

Merged
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ release.
- Add `process.context_switches`, and `process.open_file_descriptors`, to the
metrics semantic conventions
([#2706](https://github.com/open-telemetry/opentelemetry-specification/pull/2706))
- Add exceptions to the logs semantic conventions
cijothomas marked this conversation as resolved.
Show resolved Hide resolved
([#2819](https://github.com/open-telemetry/opentelemetry-specification/pull/2819))

### Compatibility

Expand Down
15 changes: 15 additions & 0 deletions semantic_conventions/logs/log-exception.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
groups:
- id: log-exception
prefix: exception
brief: >
This document defines attributes for exceptions represented using Log
Records.
attributes:
- ref: exception.type
- ref: exception.message
- ref: exception.stacktrace

constraints:
- any_of:
- "exception.type"
- "exception.message"
2 changes: 1 addition & 1 deletion specification/logs/data-model.md
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ Additional information about errors and/or exceptions that are associated with
a log record MAY be included in the structured data in the `Attributes` section
of the record.
If included, they MUST follow the OpenTelemetry
[semantic conventions for exception-related attributes](../trace/semantic_conventions/exceptions.md#attributes).
[semantic conventions for exception-related attributes](./semantic_conventions/exceptions.md#attributes).

## Example Log Records

Expand Down
50 changes: 50 additions & 0 deletions specification/logs/semantic_conventions/exceptions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Semantic Conventions for Exceptions

**Status**: [Experimental](../../document-status.md)

This document defines semantic conventions for recording exceptions on
[logs](../api.md#emit-logrecord) and [events](../api.md#emit-event) emitted
through the [Logger API](../api.md#logger).

<!-- toc -->

- [Recording an Exception](#recording-an-exception)
- [Attributes](#attributes)
* [Stacktrace Representation](#stacktrace-representation)

<!-- tocstop -->

## Recording an Exception

Exceptions SHOULD be recorded as attributes on the
[LogRecord](../api.md#logrecord) passed to the [Logger](../api.md#logger) emit
operations. Exceptions MAY be recorded on "logs" or "events" depending on the
cijothomas marked this conversation as resolved.
Show resolved Hide resolved
context.
CodeBlanch marked this conversation as resolved.
Show resolved Hide resolved

To encapsulate proper handling of exceptions API authors MAY provide a
constructor, `RecordException` method/extension, or similar helper mechanism on
the `LogRecord` class/structure or wherever it makes the most sense depending on
the language runtime.

## Attributes

The table below indicates which attributes should be added to the
[LogRecord](../api.md#logrecord) and their types.

<!-- semconv log-exception -->
| Attribute | Type | Description | Examples | Requirement Level |
|---|---|---|---|---|
| [`exception.message`](../../trace/semantic_conventions/exceptions.md) | string | The exception message. | `Division by zero`; `Can't convert 'int' object to str implicitly` | See below |
| [`exception.stacktrace`](../../trace/semantic_conventions/exceptions.md) | 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. | `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)` | Recommended |
| [`exception.type`](../../trace/semantic_conventions/exceptions.md) | 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. | `java.net.ConnectException`; `OSError` | See below |

**Additional attribute requirements:** At least one of the following sets of attributes is required:

* [`exception.type`](../../trace/semantic_conventions/exceptions.md)
cijothomas marked this conversation as resolved.
Show resolved Hide resolved
* [`exception.message`](../../trace/semantic_conventions/exceptions.md)
<!-- endsemconv -->

### Stacktrace Representation

See [Trace Semantic Conventions for Exceptions - Stacktrace
CodeBlanch marked this conversation as resolved.
Show resolved Hide resolved
Representation](../../trace/semantic_conventions/exceptions.md#stacktrace-representation).