Skip to content

Commit

Permalink
Exception semantic conventions: Add example & more explanation for ex…
Browse files Browse the repository at this point in the history
…ception.escaped. (open-telemetry#946)

* Add example & explanation for exception.escaped.

* Reshuffle paragraphs.

* Remove potentially controversial changes.

* Fill in CHANGELOG link.

* Address review comments.

* Wording

Co-authored-by: Tigran Najaryan <4194920+tigrannajaryan@users.noreply.github.com>

* Use actual OTel-Java API.

* Revert "Use actual OTel-Java API."

This reverts commit d359f47.

* Clarify CHANGELOG

* Re-generate tables.

* Typo in CHANGELOG.md

Co-authored-by: Armin Ruech <armin.ruech@dynatrace.com>

* Clarify exception escaped description.

Co-authored-by: Tigran Najaryan <4194920+tigrannajaryan@users.noreply.github.com>
Co-authored-by: Armin Ruech <armin.ruech@dynatrace.com>
  • Loading branch information
3 people authored Sep 19, 2020
1 parent 7bb6b1f commit 11e3d44
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 10 deletions.
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ New:
([#606](https://github.com/open-telemetry/opentelemetry-specification/pull/606/))
- Clarification of the behavior of the Trace API, re: context propagation, in
the absence of an installed SDK
- Add Span API and semantic conventions for recording exceptions
- Add API and semantic conventions for recording exceptions as Span Events
([#697](https://github.com/open-telemetry/opentelemetry-specification/pull/697))
* API was extended to allow adding arbitrary event attributes ([#874](https://github.com/open-telemetry/opentelemetry-specification/pull/874))
* `exception.escaped` was added ([#784](https://github.com/open-telemetry/opentelemetry-specification/pull/784))
* `exception.escaped` semantic span event attribute was added
([#784](https://github.com/open-telemetry/opentelemetry-specification/pull/784),
[#946](https://github.com/open-telemetry/opentelemetry-specification/pull/946))

Updates:

Expand Down
24 changes: 19 additions & 5 deletions semantic_conventions/trace/exception.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,25 @@ groups:
type: boolean
brief: >
SHOULD be set to true if the exception event is recorded at a point where
it is known that the exception is escaping the scope of the span (e.g. if
there is an exception active just before ending the span).
note: >
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.
it is known that the exception is escaping the scope of the span.
note: |-
An exception is considered to have escaped (or left) the scope of a span,
if that span is ended while the exception is still logically "in flight".
This may be actually "in flight" in some languages (e.g. if the exception
is passed to a Context manager's `__exit__` method in Python) but will
usually be caught at the point of recording the exception in most languages.
It is usually not possible to determine at the point where an exception is thrown
whether it will escape the scope of a span.
However, it is trivial to know that an exception
will escape, if one checks for an active exception just before ending the span,
as done in the [example above](#exception-end-example).
It follows that an exception may still escape the scope of the span
even if the `exception.escaped` attribute was not set or set to false,
since the event might have been recorded at a time where it was not
clear whether the exception will escape.
constraints:
- any_of:
- "exception.type"
Expand Down
39 changes: 36 additions & 3 deletions specification/trace/semantic_conventions/exceptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,24 @@ exceptions.
An exception SHOULD be recorded as an `Event` on the span during which it occurred.
The name of the event MUST be `"exception"`.

<a name="exception-end-example"></a>

A typical template for an auto-instrumentation implementing this semantic convention
using an [API-provided `recordException` method](../api.md#record-exception)
could look like this (pseudo-Java):

```java
Span span = myTracer.startSpan(/*...*/);
try {
// Code that does the actual work which the Span represents
} catch (Throwable e) {
span.recordException(e, Attributes.of("exception.escaped", true));
throw e;
} finally {
span.end();
}
```

## Attributes

The table below indicates which attributes should be added to the `Event` and
Expand All @@ -27,9 +45,24 @@ 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. | `java.net.ConnectException`<br>`OSError` | See below |
| `exception.message` | string | The exception message. | `Division by zero`<br>`Can't convert 'int' object to str implicitly` | See below |
| `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. | `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.escaped` | boolean | SHOULD be set to true if the exception event is recorded at a point where it is known that the exception is escaping the scope of the span (e.g. if there is an exception active just before ending the span). [1] | | No |

**[1]:** 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.
| `exception.escaped` | boolean | SHOULD be set to true if the exception event is recorded at a point where it is known that the exception is escaping the scope of the span. [1] | | No |

**[1]:** An exception is considered to have escaped (or left) the scope of a span,
if that span is ended while the exception is still logically "in flight".
This may be actually "in flight" in some languages (e.g. if the exception
is passed to a Context manager's `__exit__` method in Python) but will
usually be caught at the point of recording the exception in most languages.

It is usually not possible to determine at the point where an exception is thrown
whether it will escape the scope of a span.
However, it is trivial to know that an exception
will escape, if one checks for an active exception just before ending the span,
as done in the [example above](#exception-end-example).

It follows that an exception may still escape the scope of the span
even if the `exception.escaped` attribute was not set or set to false,
since the event might have been recorded at a time where it was not
clear whether the exception will escape.

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

Expand Down

0 comments on commit 11e3d44

Please sign in to comment.