Skip to content

Commit 4c1fdc3

Browse files
author
Liudmila Molkova
committed
feedback and some clarifications
1 parent 110e28b commit 4c1fdc3

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

docs/exceptions/README.md

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,36 @@ Semantic conventions for Exceptions are defined for the following signals:
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-
It's NOT RECOMMENDED to record exceptions that are handled by the instrumented library.
25-
2624
It's RECOMMENDED to use `Span.recordException` API or logging library API that takes exception instance
2725
instead of providing individual attributes. This enables the OpenTelemetry SDK to
2826
control what information is recorded based on user configuration.
2927

28+
It's NOT RECOMMENDED to record the same exception more than once.
29+
It's NOT RECOMMENDED to record exceptions that are handled by the instrumented library.
30+
31+
For example, in this code-snippet, `ResourceNotFoundException` is handled and corresponding
32+
native instrumentation should not record it. Other exceptions, that are propagated
33+
to the caller, should be recorded (or logged) once.
34+
35+
```java
36+
public boolean createIfNotExists(String resourceId) throws IOException {
37+
Span span = startSpan();
38+
try {
39+
create(id);
40+
return true;
41+
} catch (ResourceNotFoundException e) {
42+
// not recording exception and not setting span status to error - exception is handled
43+
return false;
44+
} catch (IOException e) {
45+
// recording exception here (assuming it was not recorded inside `create` method)
46+
span.recordException(e);
47+
// or
48+
// logger.atWarning().setCause(e).log();
49+
50+
span.setStatus(StatusCode.ERROR);
51+
throw e;
52+
}
53+
}
54+
```
55+
3056
[DocumentStatus]: https://opentelemetry.io/docs/specs/otel/document-status

0 commit comments

Comments
 (0)