Skip to content

Commit c39d47f

Browse files
OpenAI pipeline name and streaming attribute (#4628)
Rename attributes for AI pipeline name and the streaming boolean. --------- Co-authored-by: Ivana Kellyer <[email protected]>
1 parent fbbb5c4 commit c39d47f

File tree

4 files changed

+19
-5
lines changed

4 files changed

+19
-5
lines changed

sentry_sdk/ai/monitoring.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def sync_wrapped(*args, **kwargs):
4040
for k, v in kwargs.pop("sentry_data", {}).items():
4141
span.set_data(k, v)
4242
if curr_pipeline:
43-
span.set_data(SPANDATA.AI_PIPELINE_NAME, curr_pipeline)
43+
span.set_data(SPANDATA.GEN_AI_PIPELINE_NAME, curr_pipeline)
4444
return f(*args, **kwargs)
4545
else:
4646
_ai_pipeline_name.set(description)
@@ -69,7 +69,7 @@ async def async_wrapped(*args, **kwargs):
6969
for k, v in kwargs.pop("sentry_data", {}).items():
7070
span.set_data(k, v)
7171
if curr_pipeline:
72-
span.set_data(SPANDATA.AI_PIPELINE_NAME, curr_pipeline)
72+
span.set_data(SPANDATA.GEN_AI_PIPELINE_NAME, curr_pipeline)
7373
return await f(*args, **kwargs)
7474
else:
7575
_ai_pipeline_name.set(description)
@@ -108,7 +108,7 @@ def record_token_usage(
108108
# TODO: move pipeline name elsewhere
109109
ai_pipeline_name = get_ai_pipeline_name()
110110
if ai_pipeline_name:
111-
span.set_data(SPANDATA.AI_PIPELINE_NAME, ai_pipeline_name)
111+
span.set_data(SPANDATA.GEN_AI_PIPELINE_NAME, ai_pipeline_name)
112112

113113
if input_tokens is not None:
114114
span.set_data(SPANDATA.GEN_AI_USAGE_INPUT_TOKENS, input_tokens)

sentry_sdk/consts.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ class SPANDATA:
169169
AI_PIPELINE_NAME = "ai.pipeline.name"
170170
"""
171171
Name of the AI pipeline or chain being executed.
172+
DEPRECATED: Use GEN_AI_PIPELINE_NAME instead.
172173
Example: "qa-pipeline"
173174
"""
174175

@@ -229,6 +230,7 @@ class SPANDATA:
229230
AI_STREAMING = "ai.streaming"
230231
"""
231232
Whether or not the AI model call's response was streamed back asynchronously
233+
DEPRECATED: Use GEN_AI_RESPONSE_STREAMING instead.
232234
Example: true
233235
"""
234236

@@ -372,12 +374,24 @@ class SPANDATA:
372374
Example: "chat"
373375
"""
374376

377+
GEN_AI_PIPELINE_NAME = "gen_ai.pipeline.name"
378+
"""
379+
Name of the AI pipeline or chain being executed.
380+
Example: "qa-pipeline"
381+
"""
382+
375383
GEN_AI_RESPONSE_MODEL = "gen_ai.response.model"
376384
"""
377385
Exact model identifier used to generate the response
378386
Example: gpt-4o-mini-2024-07-18
379387
"""
380388

389+
GEN_AI_RESPONSE_STREAMING = "gen_ai.response.streaming"
390+
"""
391+
Whether or not the AI model call's response was streamed back asynchronously
392+
Example: true
393+
"""
394+
381395
GEN_AI_RESPONSE_TEXT = "gen_ai.response.text"
382396
"""
383397
The model's response text messages.

sentry_sdk/integrations/openai.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ def _set_input_data(span, kwargs, operation, integration):
183183
# Input attributes: Optional
184184
kwargs_keys_to_attributes = {
185185
"model": SPANDATA.GEN_AI_REQUEST_MODEL,
186-
"stream": SPANDATA.AI_STREAMING,
186+
"stream": SPANDATA.GEN_AI_RESPONSE_STREAMING,
187187
"max_tokens": SPANDATA.GEN_AI_REQUEST_MAX_TOKENS,
188188
"presence_penalty": SPANDATA.GEN_AI_REQUEST_PRESENCE_PENALTY,
189189
"frequency_penalty": SPANDATA.GEN_AI_REQUEST_FREQUENCY_PENALTY,

tests/integrations/openai/test_openai.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1159,11 +1159,11 @@ async def test_ai_client_span_streaming_responses_async_api(
11591159
assert spans[0]["op"] == "gen_ai.responses"
11601160
assert spans[0]["origin"] == "auto.ai.openai"
11611161
assert spans[0]["data"] == {
1162-
"ai.streaming": True,
11631162
"gen_ai.operation.name": "responses",
11641163
"gen_ai.request.messages": "How do I check if a Python object is an instance of a class?",
11651164
"gen_ai.request.model": "gpt-4o",
11661165
"gen_ai.response.model": "response-model-id",
1166+
"gen_ai.response.streaming": True,
11671167
"gen_ai.system": "openai",
11681168
"gen_ai.usage.input_tokens": 20,
11691169
"gen_ai.usage.input_tokens.cached": 5,

0 commit comments

Comments
 (0)