Skip to content

Commit 38d71b2

Browse files
fix: Stringify gen_ai.tool.output attribute
1 parent fe7e848 commit 38d71b2

3 files changed

Lines changed: 8 additions & 5 deletions

File tree

sentry_sdk/integrations/langchain.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from sentry_sdk.integrations import DidNotEnable, Integration
2222
from sentry_sdk.scope import should_send_default_pii
2323
from sentry_sdk.tracing_utils import _get_value, set_span_errored
24-
from sentry_sdk.utils import capture_internal_exceptions, logger
24+
from sentry_sdk.utils import capture_internal_exceptions, logger, safe_repr
2525

2626
if TYPE_CHECKING:
2727
from typing import (
@@ -688,7 +688,9 @@ def on_tool_end(
688688
span = span_data.span
689689

690690
if should_send_default_pii() and self.include_prompts:
691-
set_data_normalized(span, SPANDATA.GEN_AI_TOOL_OUTPUT, output)
691+
set_data_normalized(
692+
span, SPANDATA.GEN_AI_TOOL_OUTPUT, safe_repr(output)
693+
)
692694

693695
self._exit_span(span_data, run_id)
694696

sentry_sdk/integrations/openai_agents/spans/execute_tool.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import sentry_sdk
22
from sentry_sdk.consts import OP, SPANDATA, SPANSTATUS
33
from sentry_sdk.scope import should_send_default_pii
4+
from sentry_sdk.utils import safe_repr
45

56
from ..consts import SPAN_ORIGIN
67
from ..utils import _set_agent_data
@@ -47,7 +48,7 @@ def update_execute_tool_span(
4748
span.set_status(SPANSTATUS.INTERNAL_ERROR)
4849

4950
if should_send_default_pii():
50-
span.set_data(SPANDATA.GEN_AI_TOOL_OUTPUT, result)
51+
span.set_data(SPANDATA.GEN_AI_TOOL_OUTPUT, safe_repr(result))
5152

5253
# Add conversation ID from agent
5354
conv_id = getattr(agent, "_sentry_conversation_id", None)

sentry_sdk/integrations/openai_agents/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from sentry_sdk.integrations import DidNotEnable
1313
from sentry_sdk.scope import should_send_default_pii
1414
from sentry_sdk.tracing_utils import set_span_errored
15-
from sentry_sdk.utils import event_from_exception, safe_serialize
15+
from sentry_sdk.utils import event_from_exception, safe_serialize, safe_repr
1616
from sentry_sdk.ai._openai_completions_api import _transform_system_instructions
1717
from sentry_sdk.ai._openai_responses_api import (
1818
_is_system_instruction,
@@ -231,7 +231,7 @@ def _create_mcp_execute_tool_spans(
231231
SPANDATA.GEN_AI_TOOL_INPUT, output.arguments
232232
)
233233
execute_tool_span.set_data(
234-
SPANDATA.GEN_AI_TOOL_OUTPUT, output.output
234+
SPANDATA.GEN_AI_TOOL_OUTPUT, safe_repr(output.output)
235235
)
236236
if output.error:
237237
execute_tool_span.set_status(SPANSTATUS.INTERNAL_ERROR)

0 commit comments

Comments
 (0)