Skip to content

Latest commit

 

History

History
65 lines (46 loc) · 3.87 KB

exceptions-logs.md

File metadata and controls

65 lines (46 loc) · 3.87 KB

Semantic Conventions for Exceptions in Logs

Status: Stable

This document defines semantic conventions for recording exceptions on logs and events emitted through the Logger API.

Recording an Exception

Exceptions SHOULD be recorded as attributes on the LogRecord passed to the Logger emit operations. Exceptions MAY be recorded on "logs" or "events" depending on the context.

To encapsulate proper handling of exceptions API authors MAY provide a constructor, RecordException method/extension, or similar helper mechanism on the LogRecord class/structure or wherever it makes the most sense depending on the language runtime.

Attributes

The table below indicates which attributes should be added to the LogRecord and their types.

Attribute Type Description Examples Requirement Level Stability
exception.message string The exception message. Division by zero; Can't convert 'int' object to str implicitly Conditionally Required [1] Stable
exception.type string The 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; OSError Conditionally Required [2] Stable
exception.stacktrace string A 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) Recommended Stable

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

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

Stacktrace Representation

Same as Trace Semantic Conventions for Exceptions - Stacktrace Representation.