Skip to content

Commit 5dc8107

Browse files
committed
Updated tests
1 parent 3096d74 commit 5dc8107

File tree

2 files changed

+32
-28
lines changed

2 files changed

+32
-28
lines changed

sentry_sdk/consts.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -681,8 +681,6 @@ class OP:
681681
MIDDLEWARE_STARLITE = "middleware.starlite"
682682
MIDDLEWARE_STARLITE_RECEIVE = "middleware.starlite.receive"
683683
MIDDLEWARE_STARLITE_SEND = "middleware.starlite.send"
684-
OPENAI_CHAT_COMPLETIONS_CREATE = "ai.chat_completions.create.openai"
685-
OPENAI_EMBEDDINGS_CREATE = "ai.embeddings.create.openai"
686684
HUGGINGFACE_HUB_CHAT_COMPLETIONS_CREATE = (
687685
"ai.chat_completions.create.huggingface_hub"
688686
)

tests/integrations/openai/test_openai.py

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,17 @@ def test_nonstreaming_chat_completion(
8181
tx = events[0]
8282
assert tx["type"] == "transaction"
8383
span = tx["spans"][0]
84-
assert span["op"] == "ai.chat_completions.create.openai"
84+
assert span["op"] == "gen_ai.chat"
8585

8686
if send_default_pii and include_prompts:
87-
assert "hello" in span["data"][SPANDATA.AI_INPUT_MESSAGES]["content"]
88-
assert "the model response" in span["data"][SPANDATA.AI_RESPONSES]["content"]
87+
assert "hello" in span["data"][SPANDATA.GEN_AI_REQUEST_MESSAGES]["content"]
88+
assert (
89+
"the model response"
90+
in span["data"][SPANDATA.GEN_AI_RESPONSE_TEXT]["content"]
91+
)
8992
else:
90-
assert SPANDATA.AI_INPUT_MESSAGES not in span["data"]
91-
assert SPANDATA.AI_RESPONSES not in span["data"]
93+
assert SPANDATA.GEN_AI_REQUEST_MESSAGES not in span["data"]
94+
assert SPANDATA.GEN_AI_RESPONSE_TEXT not in span["data"]
9295

9396
assert span["measurements"]["ai_completion_tokens_used"]["value"] == 10
9497
assert span["measurements"]["ai_prompt_tokens_used"]["value"] == 20
@@ -123,14 +126,17 @@ async def test_nonstreaming_chat_completion_async(
123126
tx = events[0]
124127
assert tx["type"] == "transaction"
125128
span = tx["spans"][0]
126-
assert span["op"] == "ai.chat_completions.create.openai"
129+
assert span["op"] == "gen_ai.chat"
127130

128131
if send_default_pii and include_prompts:
129-
assert "hello" in span["data"][SPANDATA.AI_INPUT_MESSAGES]["content"]
130-
assert "the model response" in span["data"][SPANDATA.AI_RESPONSES]["content"]
132+
assert "hello" in span["data"][SPANDATA.GEN_AI_REQUEST_MESSAGES]["content"]
133+
assert (
134+
"the model response"
135+
in span["data"][SPANDATA.GEN_AI_RESPONSE_TEXT]["content"]
136+
)
131137
else:
132-
assert SPANDATA.AI_INPUT_MESSAGES not in span["data"]
133-
assert SPANDATA.AI_RESPONSES not in span["data"]
138+
assert SPANDATA.GEN_AI_REQUEST_MESSAGES not in span["data"]
139+
assert SPANDATA.GEN_AI_RESPONSE_TEXT not in span["data"]
134140

135141
assert span["measurements"]["ai_completion_tokens_used"]["value"] == 10
136142
assert span["measurements"]["ai_prompt_tokens_used"]["value"] == 20
@@ -216,14 +222,14 @@ def test_streaming_chat_completion(
216222
tx = events[0]
217223
assert tx["type"] == "transaction"
218224
span = tx["spans"][0]
219-
assert span["op"] == "ai.chat_completions.create.openai"
225+
assert span["op"] == "gen_ai.chat"
220226

221227
if send_default_pii and include_prompts:
222-
assert "hello" in span["data"][SPANDATA.AI_INPUT_MESSAGES]["content"]
223-
assert "hello world" in span["data"][SPANDATA.AI_RESPONSES]
228+
assert "hello" in span["data"][SPANDATA.GEN_AI_REQUEST_MESSAGES]["content"]
229+
assert "hello world" in span["data"][SPANDATA.GEN_AI_RESPONSE_TEXT]
224230
else:
225-
assert SPANDATA.AI_INPUT_MESSAGES not in span["data"]
226-
assert SPANDATA.AI_RESPONSES not in span["data"]
231+
assert SPANDATA.GEN_AI_REQUEST_MESSAGES not in span["data"]
232+
assert SPANDATA.GEN_AI_RESPONSE_TEXT not in span["data"]
227233

228234
try:
229235
import tiktoken # type: ignore # noqa # pylint: disable=unused-import
@@ -312,14 +318,14 @@ async def test_streaming_chat_completion_async(
312318
tx = events[0]
313319
assert tx["type"] == "transaction"
314320
span = tx["spans"][0]
315-
assert span["op"] == "ai.chat_completions.create.openai"
321+
assert span["op"] == "gen_ai.chat"
316322

317323
if send_default_pii and include_prompts:
318-
assert "hello" in span["data"][SPANDATA.AI_INPUT_MESSAGES]["content"]
319-
assert "hello world" in span["data"][SPANDATA.AI_RESPONSES]
324+
assert "hello" in span["data"][SPANDATA.GEN_AI_REQUEST_MESSAGES]["content"]
325+
assert "hello world" in span["data"][SPANDATA.GEN_AI_RESPONSE_TEXT]
320326
else:
321-
assert SPANDATA.AI_INPUT_MESSAGES not in span["data"]
322-
assert SPANDATA.AI_RESPONSES not in span["data"]
327+
assert SPANDATA.GEN_AI_REQUEST_MESSAGES not in span["data"]
328+
assert SPANDATA.GEN_AI_RESPONSE_TEXT not in span["data"]
323329

324330
try:
325331
import tiktoken # type: ignore # noqa # pylint: disable=unused-import
@@ -403,11 +409,11 @@ def test_embeddings_create(
403409
tx = events[0]
404410
assert tx["type"] == "transaction"
405411
span = tx["spans"][0]
406-
assert span["op"] == "ai.embeddings.create.openai"
412+
assert span["op"] == "gen_ai.embeddings"
407413
if send_default_pii and include_prompts:
408-
assert "hello" in span["data"][SPANDATA.AI_INPUT_MESSAGES]
414+
assert "hello" in span["data"][SPANDATA.GEN_AI_REQUEST_MESSAGES]
409415
else:
410-
assert SPANDATA.AI_INPUT_MESSAGES not in span["data"]
416+
assert SPANDATA.GEN_AI_REQUEST_MESSAGES not in span["data"]
411417

412418
assert span["measurements"]["ai_prompt_tokens_used"]["value"] == 20
413419
assert span["measurements"]["ai_total_tokens_used"]["value"] == 30
@@ -451,11 +457,11 @@ async def test_embeddings_create_async(
451457
tx = events[0]
452458
assert tx["type"] == "transaction"
453459
span = tx["spans"][0]
454-
assert span["op"] == "ai.embeddings.create.openai"
460+
assert span["op"] == "gen_ai.embeddings"
455461
if send_default_pii and include_prompts:
456-
assert "hello" in span["data"][SPANDATA.AI_INPUT_MESSAGES]
462+
assert "hello" in span["data"][SPANDATA.GEN_AI_REQUEST_MESSAGES]
457463
else:
458-
assert SPANDATA.AI_INPUT_MESSAGES not in span["data"]
464+
assert SPANDATA.GEN_AI_REQUEST_MESSAGES not in span["data"]
459465

460466
assert span["measurements"]["ai_prompt_tokens_used"]["value"] == 20
461467
assert span["measurements"]["ai_total_tokens_used"]["value"] == 30

0 commit comments

Comments
 (0)