diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b1cb2b2e7b..f345d8c2114 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ([#3973](https://github.com/open-telemetry/opentelemetry-python/pull/3966)) - Update semantic conventions to version 1.26.0. ([#3964](https://github.com/open-telemetry/opentelemetry-python/pull/3964)) + - Use semconv exception attributes for record exceptions in spans + ([#3979](https://github.com/open-telemetry/opentelemetry-python/pull/3979)) ## Version 1.25.0/0.46b0 (2024-05-30) diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py index 99c0825f9e5..4c34b8e9d5a 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py @@ -64,6 +64,12 @@ InstrumentationInfo, InstrumentationScope, ) +from opentelemetry.semconv.attributes.exception_attributes import ( + EXCEPTION_ESCAPED, + EXCEPTION_MESSAGE, + EXCEPTION_STACKTRACE, + EXCEPTION_TYPE, +) from opentelemetry.trace import NoOpTracer, SpanContext from opentelemetry.trace.status import Status, StatusCode from opentelemetry.util import types @@ -1016,10 +1022,10 @@ def record_exception( else qualname ) _attributes: MutableMapping[str, types.AttributeValue] = { - "exception.type": exception_type, - "exception.message": str(exception), - "exception.stacktrace": stacktrace, - "exception.escaped": str(escaped), + EXCEPTION_TYPE: exception_type, + EXCEPTION_MESSAGE: str(exception), + EXCEPTION_STACKTRACE: stacktrace, + EXCEPTION_ESCAPED: str(escaped), } if attributes: _attributes.update(attributes)