Skip to content

Conversation

@kianjones9
Copy link

@kianjones9 kianjones9 commented Dec 19, 2025

Description

Seems there's a bug in version 4.1.0 on the Anthropic client with beta endpoint, where the ddtrace throws if the message content field is empty. I tried using the latest release candidate on PyPI, and tried using the tagged release version of 4.1.0 from source.

Testing

Added regression test.

Wasn't working at all and now I see the traces show up.
image

Risks

None

Additional Notes

In case this is relevant, here's the original Traceback:

Error processing streamed completion/chat response.
Traceback (most recent call last):
  File "/Users/kian/Developer/letta-cloud/apps/core/.venv/lib/python3.13/site-packages/ddtrace/contrib/internal/anthropic/_streaming.py", line 80, in _process_finished_stream
    resp_message = _construct_message(streamed_chunks)
  File "/Users/kian/Developer/letta-cloud/apps/core/.venv/lib/python3.13/site-packages/ddtrace/contrib/internal/anthropic/_streaming.py", line 94, in _construct_message
    message = _extract_from_chunk(chunk, message)
  File "/Users/kian/Developer/letta-cloud/apps/core/.venv/lib/python3.13/site-packages/ddtrace/contrib/internal/anthropic/_streaming.py", line 111, in _extract_from_chunk
    message = transformation(chunk, message)
  File "/Users/kian/Developer/letta-cloud/apps/core/.venv/lib/python3.13/site-packages/ddtrace/contrib/internal/anthropic/_streaming.py", line 168, in _on_content_block_stop_chunk
    content_type = _get_attr(message["content"][-1], "type", "")
                             ~~~~~~~~~~~~~~~~~~^^^^
IndexError: list index out of range
2025-12-18 16:27:55,199 - ddtrace.contrib.internal.anthropic._streaming - WARNING - [dd.env=development dd.service=letta-server] - Error processing streamed completion/chat response.
Traceback (most recent call last):
  File "/Users/kian/Developer/letta-cloud/apps/core/.venv/lib/python3.13/site-packages/ddtrace/contrib/internal/anthropic/_streaming.py", line 80, in _process_finished_stream
    resp_message = _construct_message(streamed_chunks)
  File "/Users/kian/Developer/letta-cloud/apps/core/.venv/lib/python3.13/site-packages/ddtrace/contrib/internal/anthropic/_streaming.py", line 94, in _construct_message
    message = _extract_from_chunk(chunk, message)
  File "/Users/kian/Developer/letta-cloud/apps/core/.venv/lib/python3.13/site-packages/ddtrace/contrib/internal/anthropic/_streaming.py", line 111, in _extract_from_chunk
    message = transformation(chunk, message)
  File "/Users/kian/Developer/letta-cloud/apps/core/.venv/lib/python3.13/site-packages/ddtrace/contrib/internal/anthropic/_streaming.py", line 168, in _on_content_block_stop_chunk
    content_type = _get_attr(message["content"][-1], "type", "")
                             ~~~~~~~~~~~~~~~~~~^^^^
IndexError: list index out of range
Error generating LLMObs span event for span <Span(id=8004297588287725996,trace_id=139924324531680363119519793493218318237,parent_id=16512148357580560487,name=anthropic.request)>, likely due to malformed span
Traceback (most recent call last):
  File "/Users/kian/Developer/letta-cloud/apps/core/.venv/lib/python3.13/site-packages/ddtrace/llmobs/_llmobs.py", line 283, in _submit_llmobs_span
    span_event = self._llmobs_span_event(span)
  File "/Users/kian/Developer/letta-cloud/apps/core/.venv/lib/python3.13/site-packages/ddtrace/llmobs/_llmobs.py", line 302, in _llmobs_span_event
    raise KeyError("Span kind not found in span context")
KeyError: 'Span kind not found in span context'
2025-12-18 16:27:55,202 - ddtrace.llmobs._llmobs - ERROR - [dd.env=development dd.service=letta-server] - Error generating LLMObs span event for span <Span(id=8004297588287725996,trace_id=139924324531680363119519793493218318237,parent_id=16512148357580560487,name=anthropic.request)>, likely due to malformed span
Traceback (most recent call last):
  File "/Users/kian/Developer/letta-cloud/apps/core/.venv/lib/python3.13/site-packages/ddtrace/llmobs/_llmobs.py", line 283, in _submit_llmobs_span
    span_event = self._llmobs_span_event(span)
  File "/Users/kian/Developer/letta-cloud/apps/core/.venv/lib/python3.13/site-packages/ddtrace/llmobs/_llmobs.py", line 302, in _llmobs_span_event
    raise KeyError("Span kind not found in span context")
KeyError: 'Span kind not found in span context'

@kianjones9 kianjones9 requested a review from a team as a code owner December 19, 2025 01:43
@kianjones9 kianjones9 changed the title fix and add test fix: Span Creation Fails on Messages with Empty Content Field Dec 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant