Semantic Conventions for Exceptions on Spans

Status: Stable

This document defines semantic conventions for recording application exceptions associated with spans.

Exception event

Status: Stable

The event name MUST be exception.

This event describes a single exception.

AttributeTypeDescriptionExamplesRequirement LevelStability
exception.messagestringThe exception message.Division by zero; Can't convert 'int' object to str implicitlyConditionally Required [1]Stable
exception.typestringThe type of the exception (its fully-qualified class name, if applicable). The dynamic type of the exception should be preferred over the static type in languages that support it.java.net.ConnectException; OSErrorConditionally Required [2]Stable
exception.escapedbooleanIndicates that the exception is escaping the scope of the span.RecommendedDeprecated
It’s no longer recommended to record exceptions that are handled and do not escape the scope of a span.
exception.stacktracestringA stacktrace as a string in the natural representation for the language runtime. The representation is to be determined and documented by each language SIG.Exception in thread "main" java.lang.RuntimeException: Test exception\n at com.example.GenerateTrace.methodB(GenerateTrace.java:13)\n at com.example.GenerateTrace.methodA(GenerateTrace.java:9)\n at com.example.GenerateTrace.main(GenerateTrace.java:5)RecommendedStable

[1] exception.message: Required if exception.type is not set, recommended otherwise.

[2] exception.type: Required if exception.message is not set, recommended otherwise.

Stacktrace Representation

The table below, adapted from Google Cloud, includes possible representations of stacktraces in various languages. The table is not meant to be a recommendation for any particular language, although SIGs are free to adopt them if they see fit.

LanguageFormat
C#the return value of Exception.ToString()
Elixirthe return value of Exception.format/3
Erlangthe return value of erl_error:format
Gothe return value of runtime.Stack
Javathe contents of Throwable.printStackTrace()
Javascriptthe return value of error.stack as returned by V8
Pythonthe return value of traceback.format_exc()
Rubythe return value of Exception.full_message

Backends can use the language specified methodology for generating a stacktrace combined with platform information from the telemetry sdk resource in order to extract more fine grained information from a stacktrace, if necessary.