diff --git a/sentry_sdk/consts.py b/sentry_sdk/consts.py index 641d095ca6..a3d328274c 100644 --- a/sentry_sdk/consts.py +++ b/sentry_sdk/consts.py @@ -465,6 +465,12 @@ class SPANDATA: Example: "The weather in Paris is rainy and overcast, with temperatures around 57°F" """ + GEN_AI_EMBEDDINGS_INPUT = "gen_ai.embeddings.input" + """ + The input to the embeddings operation. + Example: "Hello!" + """ + GEN_AI_OPERATION_NAME = "gen_ai.operation.name" """ The name of the operation being performed. diff --git a/sentry_sdk/integrations/openai.py b/sentry_sdk/integrations/openai.py index 549b3504a6..40064e5c72 100644 --- a/sentry_sdk/integrations/openai.py +++ b/sentry_sdk/integrations/openai.py @@ -195,9 +195,15 @@ def _set_input_data(span, kwargs, operation, integration): scope = sentry_sdk.get_current_scope() messages_data = truncate_and_annotate_messages(normalized_messages, span, scope) if messages_data is not None: - set_data_normalized( - span, SPANDATA.GEN_AI_REQUEST_MESSAGES, messages_data, unpack=False - ) + # Use appropriate field based on operation type + if operation == "embeddings": + set_data_normalized( + span, SPANDATA.GEN_AI_EMBEDDINGS_INPUT, messages_data, unpack=False + ) + else: + set_data_normalized( + span, SPANDATA.GEN_AI_REQUEST_MESSAGES, messages_data, unpack=False + ) # Input attributes: Common set_data_normalized(span, SPANDATA.GEN_AI_SYSTEM, "openai") diff --git a/tests/integrations/openai/test_openai.py b/tests/integrations/openai/test_openai.py index ccef4f336e..febec5a80d 100644 --- a/tests/integrations/openai/test_openai.py +++ b/tests/integrations/openai/test_openai.py @@ -501,9 +501,9 @@ def test_embeddings_create( span = tx["spans"][0] assert span["op"] == "gen_ai.embeddings" if send_default_pii and include_prompts: - assert "hello" in span["data"][SPANDATA.GEN_AI_REQUEST_MESSAGES] + assert "hello" in span["data"][SPANDATA.GEN_AI_EMBEDDINGS_INPUT] else: - assert SPANDATA.GEN_AI_REQUEST_MESSAGES not in span["data"] + assert SPANDATA.GEN_AI_EMBEDDINGS_INPUT not in span["data"] assert span["data"]["gen_ai.usage.input_tokens"] == 20 assert span["data"]["gen_ai.usage.total_tokens"] == 30 @@ -549,9 +549,9 @@ async def test_embeddings_create_async( span = tx["spans"][0] assert span["op"] == "gen_ai.embeddings" if send_default_pii and include_prompts: - assert "hello" in span["data"][SPANDATA.GEN_AI_REQUEST_MESSAGES] + assert "hello" in span["data"][SPANDATA.GEN_AI_EMBEDDINGS_INPUT] else: - assert SPANDATA.GEN_AI_REQUEST_MESSAGES not in span["data"] + assert SPANDATA.GEN_AI_EMBEDDINGS_INPUT not in span["data"] assert span["data"]["gen_ai.usage.input_tokens"] == 20 assert span["data"]["gen_ai.usage.total_tokens"] == 30