diff --git a/sentry_sdk/integrations/anthropic.py b/sentry_sdk/integrations/anthropic.py index 862f073cad..74ac71a399 100644 --- a/sentry_sdk/integrations/anthropic.py +++ b/sentry_sdk/integrations/anthropic.py @@ -1,4 +1,5 @@ import sys +import json from collections.abc import Iterable from functools import wraps from typing import TYPE_CHECKING @@ -217,11 +218,9 @@ def _set_input_data( if isinstance(system_instructions, str) or isinstance( system_instructions, Iterable ): - set_data_normalized( - span, + span.set_data( SPANDATA.GEN_AI_SYSTEM_INSTRUCTIONS, - _transform_system_instructions(system_instructions), - unpack=False, + json.dumps(_transform_system_instructions(system_instructions)), ) normalized_messages = [] diff --git a/sentry_sdk/integrations/google_genai/utils.py b/sentry_sdk/integrations/google_genai/utils.py index 9db651182b..b2d6499843 100644 --- a/sentry_sdk/integrations/google_genai/utils.py +++ b/sentry_sdk/integrations/google_genai/utils.py @@ -1,4 +1,5 @@ import copy +import json import inspect from functools import wraps from .consts import ORIGIN, TOOL_ATTRIBUTES_MAP, GEN_AI_SYSTEM @@ -808,11 +809,9 @@ def set_span_data_for_request( system_instructions = config.get("system_instruction") if system_instructions is not None: - set_data_normalized( - span, + span.set_data( SPANDATA.GEN_AI_SYSTEM_INSTRUCTIONS, - _transform_system_instructions(system_instructions), - unpack=False, + json.dumps(_transform_system_instructions(system_instructions)), ) # Extract messages from contents diff --git a/sentry_sdk/integrations/langchain.py b/sentry_sdk/integrations/langchain.py index 831aeeab91..7a5e863e4d 100644 --- a/sentry_sdk/integrations/langchain.py +++ b/sentry_sdk/integrations/langchain.py @@ -1,6 +1,7 @@ import contextvars import itertools import sys +import json import warnings from collections import OrderedDict from functools import wraps @@ -467,11 +468,9 @@ def on_chat_model_start( if should_send_default_pii() and self.include_prompts: system_instructions = _get_system_instructions(messages) if len(system_instructions) > 0: - set_data_normalized( - span, + span.set_data( SPANDATA.GEN_AI_SYSTEM_INSTRUCTIONS, - _transform_system_instructions(system_instructions), - unpack=False, + json.dumps(_transform_system_instructions(system_instructions)), ) normalized_messages = [] diff --git a/sentry_sdk/integrations/openai.py b/sentry_sdk/integrations/openai.py index dc14038d9c..94052b2bad 100644 --- a/sentry_sdk/integrations/openai.py +++ b/sentry_sdk/integrations/openai.py @@ -1,4 +1,5 @@ import sys +import json import time from functools import wraps from collections.abc import Iterable @@ -273,16 +274,16 @@ def _set_responses_api_input_data( and explicit_instructions is not None and _is_given(explicit_instructions) ): - set_data_normalized( - span, + span.set_data( SPANDATA.GEN_AI_SYSTEM_INSTRUCTIONS, - [ - { - "type": "text", - "content": explicit_instructions, - } - ], - unpack=False, + json.dumps( + [ + { + "type": "text", + "content": explicit_instructions, + } + ] + ), ) set_data_normalized(span, SPANDATA.GEN_AI_OPERATION_NAME, "responses") @@ -309,11 +310,9 @@ def _set_responses_api_input_data( instructions_text_parts += _transform_system_instructions(system_instructions) if len(instructions_text_parts) > 0: - set_data_normalized( - span, + span.set_data( SPANDATA.GEN_AI_SYSTEM_INSTRUCTIONS, - instructions_text_parts, - unpack=False, + json.dumps(instructions_text_parts), ) if isinstance(messages, str): @@ -365,11 +364,9 @@ def _set_completions_api_input_data( system_instructions = _get_system_instructions_completions(messages) if len(system_instructions) > 0: - set_data_normalized( - span, + span.set_data( SPANDATA.GEN_AI_SYSTEM_INSTRUCTIONS, - _transform_system_instructions(system_instructions), - unpack=False, + json.dumps(_transform_system_instructions(system_instructions)), ) if isinstance(messages, str): diff --git a/sentry_sdk/integrations/openai_agents/utils.py b/sentry_sdk/integrations/openai_agents/utils.py index 4df76746a9..f3873db886 100644 --- a/sentry_sdk/integrations/openai_agents/utils.py +++ b/sentry_sdk/integrations/openai_agents/utils.py @@ -1,3 +1,5 @@ +import json + import sentry_sdk from sentry_sdk.ai.utils import ( GEN_AI_ALLOWED_MESSAGE_ROLES, @@ -146,11 +148,9 @@ def _set_input_data( instructions_text_parts += _transform_system_instructions(system_instructions) if len(instructions_text_parts) > 0: - set_data_normalized( - span, + span.set_data( SPANDATA.GEN_AI_SYSTEM_INSTRUCTIONS, - instructions_text_parts, - unpack=False, + json.dumps(instructions_text_parts), ) non_system_messages = [ diff --git a/sentry_sdk/integrations/pydantic_ai/spans/ai_client.py b/sentry_sdk/integrations/pydantic_ai/spans/ai_client.py index c7eb712fa6..b2ae15b38f 100644 --- a/sentry_sdk/integrations/pydantic_ai/spans/ai_client.py +++ b/sentry_sdk/integrations/pydantic_ai/spans/ai_client.py @@ -1,3 +1,5 @@ +import json + import sentry_sdk from sentry_sdk._types import BLOB_DATA_SUBSTITUTE from sentry_sdk.ai.utils import ( @@ -101,13 +103,13 @@ def _set_input_messages(span: "sentry_sdk.tracing.Span", messages: "Any") -> Non permanent_instructions, current_instructions = _get_system_instructions(messages) if len(permanent_instructions) > 0 or len(current_instructions) > 0: - set_data_normalized( - span, + span.set_data( SPANDATA.GEN_AI_SYSTEM_INSTRUCTIONS, - _transform_system_instructions( - permanent_instructions, current_instructions + json.dumps( + _transform_system_instructions( + permanent_instructions, current_instructions + ) ), - unpack=False, ) try: