Skip to content

Commit 7702ad8

Browse files
author
Liudmila Molkova
committed
changelog and lint
1 parent 96b5dfa commit 7702ad8

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ release.
4141

4242
### OTEPs
4343

44+
- [OTEP-4333](https://github.com/open-telemetry/oteps/blob/main/text/4333-component.md)
45+
Recording exceptions on logs.
46+
4447
## v1.47.0 (2025-07-18)
4548

4649
### Traces

oteps/4333-recording-exceptions-on-logs.md

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ This OTEP provides guidance on how to record exceptions using OpenTelemetry logs
77
Today OTel supports recording exceptions using span events available through Trace API. Outside of OTel world, exceptions are usually recorded by user apps and libraries using logging libraries and may be recorded as OTel logs via logging bridge.
88

99
Exceptions recorded on logs have the following advantages over span events:
10+
1011
- they can be recorded for operations that don't have any tracing instrumentation
1112
- they can be sampled along with or separately from spans
1213
- they can have different severity levels to reflect how critical the exception is
1314
- they are already reported natively by many frameworks and libraries
1415

15-
Recording exceptions is essential for troubleshooting. Regardless of how exceptions are recorded, they could be noisy:
16+
Recording exceptions is essential for troubleshooting, but regardless of how exceptions are recorded, they could be noisy:
17+
1618
- distributed applications experience transient errors at the rate proportional to their scale and exceptions in logs could be misleading -
1719
individual occurrence of transient errors are not necessarily indicative of a problem.
1820
- exception stack traces can be huge. Corresponding attribute value can frequently reach several KBs resulting in high costs
@@ -70,7 +72,6 @@ this OTEP proposes to record exception stack traces on log with `Error` or highe
7072
See [logback exception config](https://logback.qos.ch/manual/layouts.html#ex) for an example of configuration that
7173
records stack trace conditionally.
7274

73-
7475
> [!NOTE]
7576
>
7677
> Based on this guidance non-native instrumentations should record exceptions in top-level instrumentations only (#2 in [Details](#details))
@@ -179,7 +180,8 @@ public class Connection {
179180
return socketChannel.write(content);
180181
} catch (SocketException ex) {
181182
logger.logRecordBuilder()
182-
// we retry it, so it's Info or lower
183+
// we'll retry it, so it's info or lower.
184+
// we'll write a warn for overall operation if retries are exhausted.
183185
.setSeverity(Severity.INFO)
184186
.addAttribute("connection.id", this.getId())
185187
.addException(ex)
@@ -193,7 +195,7 @@ public class Connection {
193195

194196
#### Messaging processor instrumentation
195197

196-
In this example, application code provides and callback to the messaging processor to
198+
In this example, application code provides the callback to the messaging processor to
197199
execute for each message.
198200

199201
```java
@@ -208,19 +210,21 @@ processorClient.start();
208210
```
209211

210212
The `MessagingProcessorClient` implementation should catch exceptions thrown by the `processMessage` callback and log them similarly to
213+
this example:
211214

212215
```java
213216
MessageContext context = retrieveNext();
214217
try {
215218
processMessage.accept(context)
216219
} catch (Throwable t) {
217-
// this native instrumentation may use OTel log API or another logging library
218-
// such as SLF4J
220+
// This native instrumentation may use OTel log API or another logging library such as SLF4J.
221+
// Here we use Error severity since it remained unhandled by the application code
219222
logger.atError()
220223
.addKeyValuePair("messaging.message.id", context.getMessageId())
221224
...
222225
.setException(t)
223-
.log()
226+
.log();
227+
// error handling logic ...
224228
}
225229
```
226230

0 commit comments

Comments
 (0)