Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions sentry_sdk/integrations/openai_agents/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,16 +209,13 @@ def _set_output_data(
span: "Union[sentry_sdk.tracing.Span, StreamedSpan]", result: "Any"
) -> None:
client = sentry_sdk.get_client()
record_inputs = False
record_outputs = False
if has_data_collection_enabled(client.options):
record_inputs = client.options["data_collection"]["gen_ai"]["inputs"]
record_outputs = client.options["data_collection"]["gen_ai"]["outputs"]
elif should_send_default_pii():
record_inputs = True
record_outputs = True

if not record_inputs and not record_outputs:
if not record_outputs:
return

output_messages: "dict[str, list[Any]]" = {
Expand All @@ -237,7 +234,7 @@ def _set_output_data(
# Unknown output message type, just return the json
output_messages["response"].append(output_message.dict())

if record_inputs and len(output_messages["tool"]) > 0:
if record_outputs and len(output_messages["tool"]) > 0:
if isinstance(span, StreamedSpan):
span.set_attribute(
SPANDATA.GEN_AI_RESPONSE_TOOL_CALLS,
Expand Down
22 changes: 5 additions & 17 deletions tests/integrations/openai_agents/test_openai_agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -1180,55 +1180,48 @@ async def test_data_collection_inputs(
@pytest.mark.parametrize("span_streaming", [True, False])
@pytest.mark.parametrize("stream_gen_ai_spans", [True, False])
@pytest.mark.parametrize(
"data_collection,send_default_pii,expect_output,expect_tool_calls",
"data_collection,send_default_pii,expect_output",
[
pytest.param(
{"gen_ai": {"outputs": True}},
False,
True,
True,
id="gen-ai-outputs-enabled-overrides-pii-disabled",
),
pytest.param(
{"gen_ai": {"outputs": False}},
True,
False,
True,
id="gen-ai-outputs-disabled-still-collects-tool-calls-gated-on-inputs",
id="gen-ai-outputs-disabled-overrides-pii-enabled",
),
pytest.param(
{},
False,
True,
True,
id="gen-ai-omitted-defaults-to-enabled",
),
pytest.param(
{"gen_ai": {"inputs": False, "outputs": False}},
False,
False,
False,
id="gen-ai-inputs-and-outputs-disabled-and-pii-disabled",
),
pytest.param(
{"gen_ai": {"inputs": False}},
False,
True,
False,
id="gen-ai-inputs-disabled-drops-tool-calls-only",
id="gen-ai-inputs-disabled-keeps-outputs-and-tool-calls",
),
pytest.param(
None,
False,
False,
False,
id="no-data-collection-falls-back-to-send-default-pii",
),
pytest.param(
None,
True,
True,
True,
id="no-data-collection-pii-enabled-collects",
),
],
Expand All @@ -1245,7 +1238,6 @@ async def test_data_collection_outputs(
data_collection,
send_default_pii,
expect_output,
expect_tool_calls,
stream_gen_ai_spans,
span_streaming,
):
Expand Down Expand Up @@ -1326,23 +1318,19 @@ async def test_data_collection_outputs(

assert len(chat_span_data) == 2

if expect_tool_calls:
if expect_output:
assert any(
"simple_test_tool" in data.get(SPANDATA.GEN_AI_RESPONSE_TOOL_CALLS, "")
for data in chat_span_data
)
else:
for data in chat_span_data:
assert SPANDATA.GEN_AI_RESPONSE_TOOL_CALLS not in data

if expect_output:
assert any(
"Task completed using the tool"
in str(data.get(SPANDATA.GEN_AI_RESPONSE_TEXT, ""))
for data in chat_span_data
)
else:
for data in chat_span_data:
assert SPANDATA.GEN_AI_RESPONSE_TOOL_CALLS not in data
assert SPANDATA.GEN_AI_RESPONSE_TEXT not in data

# Non-PII data is unaffected by the gate
Expand Down
Loading