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
5 changes: 2 additions & 3 deletions sentry_sdk/integrations/openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -712,10 +712,9 @@ def _set_common_output_data(
}

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"]

if record_inputs or record_outputs:
if record_outputs:
for output in response.output:
if output.type == "function_call":
output_messages["tool"].append(output.dict())
Expand All @@ -729,7 +728,7 @@ def _set_common_output_data(
output_message.dict()
)

if record_inputs and len(output_messages["tool"]) > 0:
if len(output_messages["tool"]) > 0:
set_data_normalized(
span,
SPANDATA.GEN_AI_RESPONSE_TOOL_CALLS,
Expand Down
27 changes: 2 additions & 25 deletions tests/integrations/openai/test_openai.py
Original file line number Diff line number Diff line change
Expand Up @@ -5980,55 +5980,36 @@ def _collect_responses_span_data(
@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",
),
pytest.param(
{"gen_ai": {"inputs": False}},
True,
True,
False,
id="gen-ai-inputs-disabled-drops-tool-calls-only",
),
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(
None,
False,
False,
False,
id="no-gen-ai-data-collection-falls-back-to-send-default-pii",
),
pytest.param(
None,
True,
True,
True,
id="no-gen-ai-data-collection-pii-enabled-collects",
),
],
Expand All @@ -6041,7 +6022,6 @@ def test_responses_api_data_collection_outputs(
data_collection,
send_default_pii,
expect_output,
expect_tool_calls,
stream_gen_ai_spans,
span_streaming,
):
Expand Down Expand Up @@ -6088,12 +6068,9 @@ def test_responses_api_data_collection_outputs(

if expect_output:
assert "the model response" in span_data[SPANDATA.GEN_AI_RESPONSE_TEXT]
else:
assert SPANDATA.GEN_AI_RESPONSE_TEXT not in span_data

if expect_tool_calls:
assert "get_current_weather" in span_data[SPANDATA.GEN_AI_RESPONSE_TOOL_CALLS]
else:
assert SPANDATA.GEN_AI_RESPONSE_TEXT not in span_data
assert SPANDATA.GEN_AI_RESPONSE_TOOL_CALLS not in span_data


Expand Down
Loading