You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: oteps/4333-recording-exceptions-on-logs.md
+11-7Lines changed: 11 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,12 +7,14 @@ This OTEP provides guidance on how to record exceptions using OpenTelemetry logs
7
7
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.
8
8
9
9
Exceptions recorded on logs have the following advantages over span events:
10
+
10
11
- they can be recorded for operations that don't have any tracing instrumentation
11
12
- they can be sampled along with or separately from spans
12
13
- they can have different severity levels to reflect how critical the exception is
13
14
- they are already reported natively by many frameworks and libraries
14
15
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
+
16
18
- distributed applications experience transient errors at the rate proportional to their scale and exceptions in logs could be misleading -
17
19
individual occurrence of transient errors are not necessarily indicative of a problem.
18
20
- 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
70
72
See [logback exception config](https://logback.qos.ch/manual/layouts.html#ex) for an example of configuration that
71
73
records stack trace conditionally.
72
74
73
-
74
75
> [!NOTE]
75
76
>
76
77
> 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 {
179
180
return socketChannel.write(content);
180
181
} catch (SocketException ex) {
181
182
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.
183
185
.setSeverity(Severity.INFO)
184
186
.addAttribute("connection.id", this.getId())
185
187
.addException(ex)
@@ -193,7 +195,7 @@ public class Connection {
193
195
194
196
#### Messaging processor instrumentation
195
197
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
197
199
execute for each message.
198
200
199
201
```java
@@ -208,19 +210,21 @@ processorClient.start();
208
210
```
209
211
210
212
The `MessagingProcessorClient` implementation should catch exceptions thrown by the `processMessage` callback and log them similarly to
213
+
this example:
211
214
212
215
```java
213
216
MessageContext context = retrieveNext();
214
217
try {
215
218
processMessage.accept(context)
216
219
} 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
0 commit comments