Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: set span error metadata only for escaped errors #12004

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions ddtrace/internal/opentelemetry/span.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,16 +259,17 @@ def record_exception(self, exception, attributes=None, timestamp=None, escaped=F
attrs.update(attributes)

# Set the error type, error message and error stacktrace tags on the span
self._ddspan._meta[ERROR_MSG] = attrs["exception.message"]
self._ddspan._meta[ERROR_TYPE] = attrs["exception.type"]
if "exception.stacktrace" in attrs:
self._ddspan._meta[ERROR_STACK] = attrs["exception.stacktrace"]
else:
self._ddspan._meta[ERROR_STACK] = "".join(
traceback.format_exception(
type(exception), exception, exception.__traceback__, limit=config._span_traceback_max_size
if escaped:
self._ddspan._meta[ERROR_MSG] = attrs["exception.message"]
self._ddspan._meta[ERROR_TYPE] = attrs["exception.type"]
if "exception.stacktrace" in attrs:
self._ddspan._meta[ERROR_STACK] = attrs["exception.stacktrace"]
else:
self._ddspan._meta[ERROR_STACK] = "".join(
traceback.format_exception(
type(exception), exception, exception.__traceback__, limit=config._span_traceback_max_size
)
)
)
self.add_event(name="exception", attributes=attrs, timestamp=timestamp)

def __enter__(self):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
fixes:
- |
opentelemetry: Ensures ``Span.record_exception(...)`` sets the span error metadata only if escaped is True.
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@
"meta": {
"_dd.p.dm": "-0",
"_dd.p.tid": "6658897400000000",
"error.message": "MoonEar Fire!!!",
"error.stack": "Fake traceback",
"error.type": "RandoException",
"events": "[{\"name\": \"exception\", \"time_unix_nano\": 1716560281337739000, \"attributes\": {\"exception.type\": \"builtins.IndexError\", \"exception.message\": \"Invalid Operation 2\", \"exception.escaped\": \"False\", \"exception.stuff\": \"thing 2\"}}, {\"name\": \"exception\", \"time_unix_nano\": 1716560271237812000, \"attributes\": {\"exception.type\": \"RandoException\", \"exception.message\": \"MoonEar Fire!!!\", \"exception.escaped\": \"False\", \"exception.stacktrace\": \"Fake traceback\", \"exception.details\": \"This is FAKE, I overwrote the real exception details\"}}]",
"language": "python",
"runtime-id": "d0950ce7bda6498183acde9036abb131"
Expand Down
Loading