Skip to content

Commit 456f377

Browse files
author
Liudmila Molkova
committed
Remove exception.escapted, update examples, remove old example
1 parent 176716a commit 456f377

File tree

5 files changed

+41
-91
lines changed

5 files changed

+41
-91
lines changed

docs/attributes-registry/exception.md

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,23 @@
66

77
# Exception
88

9+
- [Exception Attributes](#exception-attributes)
10+
- [Deprecated Exception Attributes](#deprecated-exception-attributes)
11+
912
## Exception Attributes
1013

1114
This document defines the shared attributes used to report a single exception associated with a span or log.
1215

1316
| Attribute | Type | Description | Examples | Stability |
1417
|---|---|---|---|---|
15-
| <a id="exception-escaped" href="#exception-escaped">`exception.escaped`</a> | 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] | | ![Stable](https://img.shields.io/badge/-stable-lightgreen) |
1618
| <a id="exception-message" href="#exception-message">`exception.message`</a> | string | The exception message. | `Division by zero`; `Can't convert 'int' object to str implicitly` | ![Stable](https://img.shields.io/badge/-stable-lightgreen) |
1719
| <a id="exception-stacktrace" href="#exception-stacktrace">`exception.stacktrace`</a> | 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)` | ![Stable](https://img.shields.io/badge/-stable-lightgreen) |
1820
| <a id="exception-type" href="#exception-type">`exception.type`</a> | 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` | ![Stable](https://img.shields.io/badge/-stable-lightgreen) |
1921

20-
**[1] `exception.escaped`:** An exception is considered to have escaped (or left) the scope of a span,
21-
if that span is ended while the exception is still logically "in flight".
22-
This may be actually "in flight" in some languages (e.g. if the exception
23-
is passed to a Context manager's `__exit__` method in Python) but will
24-
usually be caught at the point of recording the exception in most languages.
25-
26-
It is usually not possible to determine at the point where an exception is thrown
27-
whether it will escape the scope of a span.
28-
However, it is trivial to know that an exception
29-
will escape, if one checks for an active exception just before ending the span,
30-
as done in the [example for recording span exceptions](https://opentelemetry.io/docs/specs/semconv/exceptions/exceptions-spans/#recording-an-exception).
31-
32-
It follows that an exception may still escape the scope of the span
33-
even if the `exception.escaped` attribute was not set or set to false,
34-
since the event might have been recorded at a time where it was not
35-
clear whether the exception will escape.
22+
## Deprecated Exception Attributes
23+
24+
Deprecated exception attributes.
25+
26+
| Attribute | Type | Description | Examples | Stability |
27+
|---|---|---|---|---|
28+
| <a id="exception-escaped" href="#exception-escaped">`exception.escaped`</a> | boolean | Indicates that the exception is escaping the scope of the span. | | ![Deprecated](https://img.shields.io/badge/-deprecated-red)<br>It's no longer recommended to record exceptions that are handled and do not escape the scope of a span. |

docs/exceptions/README.md

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,23 @@ Semantic conventions for Exceptions are defined for the following signals:
1414
* [Exceptions on spans](exceptions-spans.md): Semantic Conventions for Exceptions associated with *spans*.
1515
* [Exceptions in logs](exceptions-logs.md): Semantic Conventions for Exceptions recorded in *logs*.
1616

17-
## Reporting errors in instrumentation code
17+
## Reporting exceptions in instrumentation code
1818

1919
**Status**: [Development][DocumentStatus]
2020

2121
When instrumented operation fails with an exception, instrumentation SHOULD record
2222
this exception as a [span event](exceptions-spans.md) or a [log record](exceptions-logs.md).
2323

24+
Recording exceptions on spans SHOULD be accompanied by
25+
- setting span status to `ERROR`
26+
- setting [`error.type`](https://github.com/open-telemetry/semantic-conventions/blob/main/docs/attributes-registry/error.md#error-type)
27+
28+
Refer to the [Recording errors](/docs/general/recording-errors.md) document for additional
29+
details on how to record errors across different signals.
30+
2431
It's RECOMMENDED to use `Span.recordException` API or logging library API that takes exception instance
2532
instead of providing individual attributes. This enables the OpenTelemetry SDK to
26-
control what information is recorded based on user configuration.
33+
control what information is recorded based on application configuration.
2734

2835
It's NOT RECOMMENDED to record the same exception more than once.
2936
It's NOT RECOMMENDED to record exceptions that are handled by the instrumented library.
@@ -36,18 +43,21 @@ to the caller, should be recorded (or logged) once.
3643
public boolean createIfNotExists(String resourceId) throws IOException {
3744
Span span = startSpan();
3845
try {
39-
create(id);
46+
create(resourceId);
4047
return true;
41-
} catch (ResourceNotFoundException e) {
48+
} catch (ResourceAlreadyExistsException e) {
4249
// not recording exception and not setting span status to error - exception is handled
50+
// but we can set attributes that capture additional details
51+
span.setAttribute(AttributeKey.stringKey("acme.resource.create.status"), "already_exists");
4352
return false;
4453
} catch (IOException e) {
4554
// recording exception here (assuming it was not recorded inside `create` method)
4655
span.recordException(e);
4756
// or
48-
// logger.atWarning().setCause(e).log();
57+
// logger.warn(e);
4958

50-
span.setStatus(StatusCode.ERROR);
59+
span.setAttribute(AttributeKey.stringKey("error.type"), e.getClass().getCanonicalName())
60+
span.setStatus(StatusCode.ERROR, e.getMessage());
5161
throw e;
5262
}
5363
}

docs/exceptions/exceptions-spans.md

Lines changed: 1 addition & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -11,33 +11,6 @@ exceptions associated with spans.
1111

1212
<!-- toc -->
1313

14-
- [Recording an Exception](#recording-an-exception)
15-
- [Exception event](#exception-event)
16-
- [Stacktrace Representation](#stacktrace-representation)
17-
18-
<!-- tocstop -->
19-
20-
## Recording an Exception
21-
22-
An exception SHOULD be recorded as an `Event` on the span during which it occurred.
23-
The name of the event MUST be `"exception"`.
24-
25-
A typical template for an auto-instrumentation implementing this semantic convention
26-
using an [API-provided `recordException` method](https://github.com/open-telemetry/opentelemetry-specification/tree/v1.39.0/specification/trace/api.md#record-exception)
27-
could look like this (pseudo-Java):
28-
29-
```java
30-
Span span = myTracer.startSpan(/*...*/);
31-
try {
32-
// Code that does the actual work which the Span represents
33-
} catch (Throwable e) {
34-
span.recordException(e, Attributes.of("exception.escaped", true));
35-
throw e;
36-
} finally {
37-
span.end();
38-
}
39-
```
40-
4114
## Exception event
4215

4316
<!-- semconv event.exception -->
@@ -57,30 +30,13 @@ This event describes a single exception.
5730
|---|---|---|---|---|---|
5831
| [`exception.message`](/docs/attributes-registry/exception.md) | string | The exception message. | `Division by zero`; `Can't convert 'int' object to str implicitly` | `Conditionally Required` [1] | ![Stable](https://img.shields.io/badge/-stable-lightgreen) |
5932
| [`exception.type`](/docs/attributes-registry/exception.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` | `Conditionally Required` [2] | ![Stable](https://img.shields.io/badge/-stable-lightgreen) |
60-
| [`exception.escaped`](/docs/attributes-registry/exception.md) | 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. [3] | | `Recommended` | ![Stable](https://img.shields.io/badge/-stable-lightgreen) |
33+
| [`exception.escaped`](/docs/attributes-registry/exception.md) | boolean | Indicates that the exception is escaping the scope of the span. | | `Recommended` | ![Deprecated](https://img.shields.io/badge/-deprecated-red)<br>It's no longer recommended to record exceptions that are handled and do not escape the scope of a span. |
6134
| [`exception.stacktrace`](/docs/attributes-registry/exception.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` | ![Stable](https://img.shields.io/badge/-stable-lightgreen) |
6235

6336
**[1] `exception.message`:** Required if `exception.type` is not set, recommended otherwise.
6437

6538
**[2] `exception.type`:** Required if `exception.message` is not set, recommended otherwise.
6639

67-
**[3] `exception.escaped`:** An exception is considered to have escaped (or left) the scope of a span,
68-
if that span is ended while the exception is still logically "in flight".
69-
This may be actually "in flight" in some languages (e.g. if the exception
70-
is passed to a Context manager's `__exit__` method in Python) but will
71-
usually be caught at the point of recording the exception in most languages.
72-
73-
It is usually not possible to determine at the point where an exception is thrown
74-
whether it will escape the scope of a span.
75-
However, it is trivial to know that an exception
76-
will escape, if one checks for an active exception just before ending the span,
77-
as done in the [example for recording span exceptions](https://opentelemetry.io/docs/specs/semconv/exceptions/exceptions-spans/#recording-an-exception).
78-
79-
It follows that an exception may still escape the scope of the span
80-
even if the `exception.escaped` attribute was not set or set to false,
81-
since the event might have been recorded at a time where it was not
82-
clear whether the exception will escape.
83-
8440
<!-- markdownlint-restore -->
8541
<!-- prettier-ignore-end -->
8642
<!-- END AUTOGENERATED TEXT -->
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
groups:
2+
- id: registry.exception.deprecated
3+
type: attribute_group
4+
display_name: Deprecated Exception Attributes
5+
brief: >
6+
Deprecated exception attributes.
7+
attributes:
8+
- id: exception.escaped
9+
type: boolean
10+
stability: stable
11+
deprecated: "It's no longer recommended to record exceptions that are handled
12+
and do not escape the scope of a span."
13+
brief: >
14+
Indicates that the exception is escaping the scope of the span.

model/exceptions/registry.yaml

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -31,26 +31,3 @@ groups:
3131
at com.example.GenerateTrace.methodB(GenerateTrace.java:13)\n
3232
at com.example.GenerateTrace.methodA(GenerateTrace.java:9)\n
3333
at com.example.GenerateTrace.main(GenerateTrace.java:5)
34-
- id: exception.escaped
35-
type: boolean
36-
stability: stable
37-
brief: >
38-
SHOULD be set to true if the exception event is recorded at a point where
39-
it is known that the exception is escaping the scope of the span.
40-
note: |-
41-
An exception is considered to have escaped (or left) the scope of a span,
42-
if that span is ended while the exception is still logically "in flight".
43-
This may be actually "in flight" in some languages (e.g. if the exception
44-
is passed to a Context manager's `__exit__` method in Python) but will
45-
usually be caught at the point of recording the exception in most languages.
46-
47-
It is usually not possible to determine at the point where an exception is thrown
48-
whether it will escape the scope of a span.
49-
However, it is trivial to know that an exception
50-
will escape, if one checks for an active exception just before ending the span,
51-
as done in the [example for recording span exceptions](https://opentelemetry.io/docs/specs/semconv/exceptions/exceptions-spans/#recording-an-exception).
52-
53-
It follows that an exception may still escape the scope of the span
54-
even if the `exception.escaped` attribute was not set or set to false,
55-
since the event might have been recorded at a time where it was not
56-
clear whether the exception will escape.

0 commit comments

Comments
 (0)