diff --git a/sentry_sdk/ai/monitoring.py b/sentry_sdk/ai/monitoring.py index 7a687736d0..e3f372c3ba 100644 --- a/sentry_sdk/ai/monitoring.py +++ b/sentry_sdk/ai/monitoring.py @@ -40,7 +40,7 @@ def sync_wrapped(*args, **kwargs): for k, v in kwargs.pop("sentry_data", {}).items(): span.set_data(k, v) if curr_pipeline: - span.set_data(SPANDATA.AI_PIPELINE_NAME, curr_pipeline) + span.set_data(SPANDATA.GEN_AI_PIPELINE_NAME, curr_pipeline) return f(*args, **kwargs) else: _ai_pipeline_name.set(description) @@ -69,7 +69,7 @@ async def async_wrapped(*args, **kwargs): for k, v in kwargs.pop("sentry_data", {}).items(): span.set_data(k, v) if curr_pipeline: - span.set_data(SPANDATA.AI_PIPELINE_NAME, curr_pipeline) + span.set_data(SPANDATA.GEN_AI_PIPELINE_NAME, curr_pipeline) return await f(*args, **kwargs) else: _ai_pipeline_name.set(description) @@ -108,7 +108,7 @@ def record_token_usage( # TODO: move pipeline name elsewhere ai_pipeline_name = get_ai_pipeline_name() if ai_pipeline_name: - span.set_data(SPANDATA.AI_PIPELINE_NAME, ai_pipeline_name) + span.set_data(SPANDATA.GEN_AI_PIPELINE_NAME, ai_pipeline_name) if input_tokens is not None: span.set_data(SPANDATA.GEN_AI_USAGE_INPUT_TOKENS, input_tokens) diff --git a/sentry_sdk/consts.py b/sentry_sdk/consts.py index 533aa9f815..a82ff94c49 100644 --- a/sentry_sdk/consts.py +++ b/sentry_sdk/consts.py @@ -169,6 +169,7 @@ class SPANDATA: AI_PIPELINE_NAME = "ai.pipeline.name" """ Name of the AI pipeline or chain being executed. + DEPRECATED: Use GEN_AI_PIPELINE_NAME instead. Example: "qa-pipeline" """ @@ -229,6 +230,7 @@ class SPANDATA: AI_STREAMING = "ai.streaming" """ Whether or not the AI model call's response was streamed back asynchronously + DEPRECATED: Use GEN_AI_RESPONSE_STREAMING instead. Example: true """ @@ -372,12 +374,24 @@ class SPANDATA: Example: "chat" """ + GEN_AI_PIPELINE_NAME = "gen_ai.pipeline.name" + """ + Name of the AI pipeline or chain being executed. + Example: "qa-pipeline" + """ + GEN_AI_RESPONSE_MODEL = "gen_ai.response.model" """ Exact model identifier used to generate the response Example: gpt-4o-mini-2024-07-18 """ + GEN_AI_RESPONSE_STREAMING = "gen_ai.response.streaming" + """ + Whether or not the AI model call's response was streamed back asynchronously + Example: true + """ + GEN_AI_RESPONSE_TEXT = "gen_ai.response.text" """ The model's response text messages. diff --git a/sentry_sdk/integrations/openai.py b/sentry_sdk/integrations/openai.py index 98e83607dd..78fcdd49e2 100644 --- a/sentry_sdk/integrations/openai.py +++ b/sentry_sdk/integrations/openai.py @@ -183,7 +183,7 @@ def _set_input_data(span, kwargs, operation, integration): # Input attributes: Optional kwargs_keys_to_attributes = { "model": SPANDATA.GEN_AI_REQUEST_MODEL, - "stream": SPANDATA.AI_STREAMING, + "stream": SPANDATA.GEN_AI_RESPONSE_STREAMING, "max_tokens": SPANDATA.GEN_AI_REQUEST_MAX_TOKENS, "presence_penalty": SPANDATA.GEN_AI_REQUEST_PRESENCE_PENALTY, "frequency_penalty": SPANDATA.GEN_AI_REQUEST_FREQUENCY_PENALTY, diff --git a/tests/integrations/openai/test_openai.py b/tests/integrations/openai/test_openai.py index fe282d0853..dfac08d762 100644 --- a/tests/integrations/openai/test_openai.py +++ b/tests/integrations/openai/test_openai.py @@ -1159,11 +1159,11 @@ async def test_ai_client_span_streaming_responses_async_api( assert spans[0]["op"] == "gen_ai.responses" assert spans[0]["origin"] == "auto.ai.openai" assert spans[0]["data"] == { - "ai.streaming": True, "gen_ai.operation.name": "responses", "gen_ai.request.messages": "How do I check if a Python object is an instance of a class?", "gen_ai.request.model": "gpt-4o", "gen_ai.response.model": "response-model-id", + "gen_ai.response.streaming": True, "gen_ai.system": "openai", "gen_ai.usage.input_tokens": 20, "gen_ai.usage.input_tokens.cached": 5,