@@ -7,61 +7,11 @@ path_base_for_github_subdir:
77
88# Semantic Conventions for Exceptions
99
10- ** Status** : [ Stable] [ DocumentStatus ] , Unless otherwise specified.
10+ ** Status** : [ Stable] [ DocumentStatus ]
1111
1212Semantic conventions for Exceptions are defined for the following signals:
1313
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 exceptions in instrumentation code
18-
19- ** Status** : [ Development] [ DocumentStatus ]
20-
21- When an instrumented operation fails with an exception, instrumentation SHOULD record
22- this exception as a [ span event] ( exceptions-spans.md ) or a [ log record] ( exceptions-logs.md ) .
23-
24- Recording exceptions on spans SHOULD be accompanied by:
25-
26- - setting span status to ` ERROR `
27- - setting [ ` error.type ` ] ( https://github.com/open-telemetry/semantic-conventions/blob/main/docs/attributes-registry/error.md#error-type ) attribute
28-
29- Refer to the [ Recording errors] ( /docs/general/recording-errors.md ) document for additional
30- details on how to record errors across different signals.
31-
32- It's RECOMMENDED to use the ` Span.recordException ` API or logging library API that takes exception instance
33- instead of providing individual attributes. This enables the OpenTelemetry SDK to
34- control what information is recorded based on application configuration.
35-
36- It's NOT RECOMMENDED to record the same exception more than once.
37- It's NOT RECOMMENDED to record exceptions that are handled by the instrumented library.
38-
39- For example, in this code-snippet, ` ResourceAlreadyExistsException ` is handled and the corresponding
40- native instrumentation should not record it. Exceptions which are propagated
41- to the caller should be recorded (or logged) once.
42-
43- ``` java
44- public boolean createIfNotExists(String resourceId) throws IOException {
45- Span span = startSpan();
46- try {
47- create(resourceId);
48- return true ;
49- } catch (ResourceAlreadyExistsException e) {
50- // not recording exception and not setting span status to error - exception is handled
51- // but we can set attributes that capture additional details
52- span. setAttribute(AttributeKey . stringKey(" acme.resource.create.status" ), " already_exists" );
53- return false ;
54- } catch (IOException e) {
55- // recording exception here (assuming it was not recorded inside `create` method)
56- span. recordException(e);
57- // or
58- // logger.warn(e);
59-
60- span. setAttribute(AttributeKey . stringKey(" error.type" ), e. getClass(). getCanonicalName())
61- span. setStatus(StatusCode . ERROR , e. getMessage());
62- throw e;
63- }
64- }
65- ```
66-
6717[ DocumentStatus ] : https://opentelemetry.io/docs/specs/otel/document-status
0 commit comments