Skip to content

Commit 024cbff

Browse files
committed
use span.set_data & move system & op name out of try block to capture in exceptions
1 parent 08c1c23 commit 024cbff

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

sentry_sdk/integrations/cohere.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,11 @@ def new_chat(*args: "Any", **kwargs: "Any") -> "Any":
152152
origin=CohereIntegration.origin,
153153
)
154154
span.__enter__()
155+
156+
with capture_internal_exceptions():
157+
span.set_data(SPANDATA.GEN_AI_SYSTEM, "cohere")
158+
span.set_data(SPANDATA.GEN_AI_OPERATION_NAME, "chat")
159+
155160
try:
156161
res = f(*args, **kwargs)
157162
except Exception as e:
@@ -162,9 +167,6 @@ def new_chat(*args: "Any", **kwargs: "Any") -> "Any":
162167
reraise(*exc_info)
163168

164169
with capture_internal_exceptions():
165-
span.set_data(SPANDATA.GEN_AI_SYSTEM, "cohere")
166-
span.set_data(SPANDATA.GEN_AI_OPERATION_NAME, "chat")
167-
168170
if should_send_default_pii() and integration.include_prompts:
169171
messages = []
170172
for x in kwargs.get("chat_history", []):
@@ -241,8 +243,8 @@ def new_embed(*args: "Any", **kwargs: "Any") -> "Any":
241243
name=f"embeddings {model}".strip(),
242244
origin=CohereIntegration.origin,
243245
) as span:
244-
set_data_normalized(span, SPANDATA.GEN_AI_SYSTEM, "cohere")
245-
set_data_normalized(span, SPANDATA.GEN_AI_OPERATION_NAME, "embeddings")
246+
span.set_data(SPANDATA.GEN_AI_SYSTEM, "cohere")
247+
span.set_data(SPANDATA.GEN_AI_OPERATION_NAME, "embeddings")
246248

247249
if "texts" in kwargs and (
248250
should_send_default_pii() and integration.include_prompts

0 commit comments

Comments
 (0)