Skip to content
Draft
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
10 changes: 5 additions & 5 deletions sentry_sdk/integrations/cohere.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def collect_chat_response_fields(

for attr in COLLECTED_CHAT_RESP_ATTRS:
if hasattr(res, attr):
set_data_normalized(span, "ai." + attr, getattr(res, attr))
span.set_data("ai." + attr, getattr(res, attr))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-primitive span data may break serialization

Medium Severity

Replacing set_data_normalized with span.set_data stores raw values for COLLECTED_CHAT_RESP_ATTRS and COLLECTED_CHAT_PARAMS. If Cohere returns non-primitive types (for example enum-like objects for finish_reason or custom numeric types), the span/event JSON serialization can fail or silently drop data that previously got normalized/stringified.

Additional Locations (1)

Fix in Cursor Fix in Web


if hasattr(res, "meta"):
if hasattr(res.meta, "billed_units"):
Expand Down Expand Up @@ -180,8 +180,8 @@ def new_chat(*args: "Any", **kwargs: "Any") -> "Any":

for k, v in COLLECTED_CHAT_PARAMS.items():
if k in kwargs:
set_data_normalized(span, v, kwargs[k])
set_data_normalized(span, SPANDATA.AI_STREAMING, False)
span.set_data(v, kwargs[k])
span.set_data(SPANDATA.AI_STREAMING, False)

if streaming:
old_iterator = res
Expand Down Expand Up @@ -212,7 +212,7 @@ def new_iterator() -> "Iterator[StreamedChatResponse]":
)
span.__exit__(None, None, None)
else:
set_data_normalized(span, "unknown_response", True)
span.set_data("unknown_response", True)
span.__exit__(None, None, None)
return res

Expand Down Expand Up @@ -246,7 +246,7 @@ def new_embed(*args: "Any", **kwargs: "Any") -> "Any":
)

if "model" in kwargs:
set_data_normalized(span, SPANDATA.AI_MODEL_ID, kwargs["model"])
span.set_data(SPANDATA.AI_MODEL_ID, kwargs["model"])
try:
res = f(*args, **kwargs)
except Exception as e:
Expand Down
Loading