Skip to content

Commit 4649623

Browse files
chore(cohere): Replace deprecated ops with gen_ai.* ops (#7956)
1 parent 5f2726b commit 4649623

3 files changed

Lines changed: 15 additions & 9 deletions

File tree

‎MIGRATION_GUIDE.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ Looking to upgrade from Sentry SDK 2.x to 3.x? Here's a comprehensive list of wh
3737
- We now don't suppress chained exceptions in the ASGI and asyncio integrations by default. The related `suppress_asgi_chained_exceptions` experimental option was removed.
3838
- In the AWS Lambda and GCP integrations, the text of the message of the warning the SDK optionally emits if a function is about to time out has changed.
3939

40+
#### Span operation consolidation
41+
42+
Span ops are now a smaller, framework-neutral set.
43+
44+
- The Cohere integration now emits `gen_ai.chat` instead of `ai.chat_completions.create.cohere`, and `gen_ai.embeddings` instead of `ai.embeddings.create.cohere`.
45+
4046
#### Django
4147

4248
- The Django integration now creates spans for cache operations by default. Pass `DjangoIntegration(cache_spans=False)` to `sentry_sdk.init()` to turn them off.

‎sentry_sdk/integrations/cohere.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def new_chat(*args: "Any", **kwargs: "Any") -> "Any":
179179
span = sentry_sdk.start_span(
180180
name="cohere.client.Chat",
181181
attributes={
182-
"sentry.op": consts.OP.COHERE_CHAT_COMPLETIONS_CREATE,
182+
"sentry.op": consts.OP.GEN_AI_CHAT,
183183
"sentry.origin": CohereIntegration.origin,
184184
},
185185
)
@@ -266,7 +266,7 @@ def new_embed(*args: "Any", **kwargs: "Any") -> "Any":
266266
with sentry_sdk.start_span(
267267
name="Cohere Embedding Creation",
268268
attributes={
269-
"sentry.op": consts.OP.COHERE_EMBEDDINGS_CREATE,
269+
"sentry.op": consts.OP.GEN_AI_EMBEDDINGS,
270270
"sentry.origin": CohereIntegration.origin,
271271
},
272272
) as span:

‎tests/integrations/cohere/test_cohere.py‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from httpx import Client as HTTPXClient
88

99
import sentry_sdk
10-
from sentry_sdk.consts import SPANDATA
10+
from sentry_sdk.consts import OP, SPANDATA
1111
from sentry_sdk.integrations.cohere import CohereIntegration
1212

1313

@@ -55,7 +55,7 @@ def test_nonstreaming_chat(
5555
assert len(items) == 1
5656
span = items[0].payload
5757

58-
assert span["attributes"]["sentry.op"] == "ai.chat_completions.create.cohere"
58+
assert span["attributes"]["sentry.op"] == OP.GEN_AI_CHAT
5959
assert span["attributes"][SPANDATA.AI_MODEL_ID] == "some-model"
6060

6161
assert (
@@ -117,7 +117,7 @@ def test_nonstreaming_chat_no_sensitive_data(
117117
assert len(items) == 1
118118
span = items[0].payload
119119

120-
assert span["attributes"]["sentry.op"] == "ai.chat_completions.create.cohere"
120+
assert span["attributes"]["sentry.op"] == OP.GEN_AI_CHAT
121121
assert span["attributes"][SPANDATA.AI_MODEL_ID] == "some-model"
122122

123123
assert SPANDATA.AI_INPUT_MESSAGES not in span["attributes"]
@@ -187,7 +187,7 @@ def test_streaming_chat(
187187
assert len(items) == 1
188188
span = items[0].payload
189189

190-
assert span["attributes"]["sentry.op"] == "ai.chat_completions.create.cohere"
190+
assert span["attributes"]["sentry.op"] == OP.GEN_AI_CHAT
191191
assert span["attributes"][SPANDATA.AI_MODEL_ID] == "some-model"
192192

193193
assert (
@@ -264,7 +264,7 @@ def test_streaming_chat_no_sensitive_data(
264264
assert len(items) == 1
265265
span = items[0].payload
266266

267-
assert span["attributes"]["sentry.op"] == "ai.chat_completions.create.cohere"
267+
assert span["attributes"]["sentry.op"] == OP.GEN_AI_CHAT
268268
assert span["attributes"][SPANDATA.AI_MODEL_ID] == "some-model"
269269

270270
assert SPANDATA.AI_INPUT_MESSAGES not in span["attributes"]
@@ -317,7 +317,7 @@ def test_embed(
317317
assert len(items) == 1
318318
span = items[0].payload
319319

320-
assert span["attributes"]["sentry.op"] == "ai.embeddings.create.cohere"
320+
assert span["attributes"]["sentry.op"] == OP.GEN_AI_EMBEDDINGS
321321
assert "hello" in span["attributes"][SPANDATA.AI_INPUT_MESSAGES]
322322

323323
assert span["attributes"]["gen_ai.usage.input_tokens"] == 10
@@ -366,7 +366,7 @@ def test_embed_no_sensitive_data(
366366
assert len(items) == 1
367367
span = items[0].payload
368368

369-
assert span["attributes"]["sentry.op"] == "ai.embeddings.create.cohere"
369+
assert span["attributes"]["sentry.op"] == OP.GEN_AI_EMBEDDINGS
370370
assert SPANDATA.AI_INPUT_MESSAGES not in span["attributes"]
371371

372372
assert span["attributes"]["gen_ai.usage.input_tokens"] == 10

0 commit comments

Comments
 (0)