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

chore(tracer): add more detail in encoding error message #12280

Closed
wants to merge 2 commits into from
Closed
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
14 changes: 12 additions & 2 deletions ddtrace/internal/_encoding.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import threading
from json import dumps as json_dumps

from ._utils cimport PyBytesLike_Check

import traceback

# Do not use an absolute import here Cython<3.0.0 will
# import `ddtrace.internal.constants` instead when this
Expand Down Expand Up @@ -500,7 +500,17 @@ cdef class MsgpackEncoderBase(BufferedEncoder):
try:
ret = self.pack_span(span, dd_origin)
except Exception as e:
raise RuntimeError("failed to pack span: {!r}. Exception: {}".format(span, e))
# Capture full traceback information.
tb_info = traceback.format_exc()
# Safely get the _metrics attribute from span, if available.
metrics = getattr(span, "_metrics", None)
raise RuntimeError(
"Failed to pack span: {!r}.\n"
"Span metrics: {!r}.\n"
"Exception: {}.\n"
"Traceback:\n{}"
.format(span, metrics, e, tb_info)
) from e

# No exception was raised, but we got an error code from msgpack
if ret != 0:
Expand Down
1 change: 1 addition & 0 deletions tests/tracer/test_encoders.py
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,7 @@ def test_encoding_invalid_data(data):
with pytest.raises(RuntimeError) as e:
encoder.put(trace)

# Rachel - these tests will fail
assert e.match(r"failed to pack span: <Span\(id="), e
assert encoder.encode()[0] is None

Expand Down
Loading