Status: Stable, Unless otherwise specified.
This document defines how to record exceptions and their attributes.
An exception SHOULD be recorded as an Event
on the span during which it occurred
if and only if it remains unhandled when the span ends and causes the span status
to be set to ERROR.
The name of the event MUST be "exception"
.
Status: Development - Refer to the Recording Errors document for the details on how to report errors across signals.
A typical template for an auto-instrumentation implementing this semantic convention
using an API-provided recordException
method
could look like this (pseudo-Java):
Span span = myTracer.startSpan(/*...*/);
try {
// Code that does the actual work which the Span represents
} catch (Throwable e) {
span.recordException(e);
span.setAttribute(AttributeKey.stringKey("error.type"), e.getClass().getCanonicalName())
span.setStatus(StatusCode.ERROR, e.getMessage());
throw e;
} finally {
span.end();
}
An event representing an exception MUST have an
event name exception
.
Additionally, the following attributes SHOULD be filled out:
exception.message
exception.stacktrace
exception.type
The format and semantics of these attributes are defined in semantic conventions.