Skip to content

Commit 8cf904d

Browse files
ref(google-genai): Drop send_default_pii support (#7739)
Remove `send_default_pii` branches from the integration. Add the `data_collection` option to all tests for the integration, with `gen_ai` options enabled if `send_default_pii=True` previously, and `gen_ai` options disabled if `send_default_pii=False` previously. When `send_default_pii` was not previously supplied to `sentry_init()`, provide `data_collection={}`. Split tests that were parametrized on `send_default_pii` into two tests with `gen_ai` options enabled and disabled (the latter suffixed with `_no_sensitive_data`). Remove cases of `_data_collection`-suffixed tests that are now exercised by existing tests. Closes #7596
1 parent 944a204 commit 8cf904d

3 files changed

Lines changed: 360 additions & 498 deletions

File tree

‎sentry_sdk/integrations/google_genai/streaming.py‎

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33
import sentry_sdk
44
from sentry_sdk.ai.utils import set_data_normalized
55
from sentry_sdk.consts import SPANDATA
6-
from sentry_sdk.scope import should_send_default_pii
76
from sentry_sdk.traces import Span
87
from sentry_sdk.utils import (
9-
has_data_collection_enabled,
108
safe_serialize,
119
)
1210

@@ -154,28 +152,14 @@ def set_span_data_for_streaming_response(
154152
)
155153

156154
if accumulated_response.get("tool_calls"):
157-
if has_data_collection_enabled(client.options):
158-
if client.options["data_collection"]["gen_ai"]["outputs"]:
159-
span.set_attribute(
160-
SPANDATA.GEN_AI_RESPONSE_TOOL_CALLS,
161-
safe_serialize(accumulated_response["tool_calls"]),
162-
)
163-
else:
164-
# Before data collection was introduced this was unconditionally set
155+
if client.options["data_collection"]["gen_ai"]["outputs"]:
165156
span.set_attribute(
166157
SPANDATA.GEN_AI_RESPONSE_TOOL_CALLS,
167158
safe_serialize(accumulated_response["tool_calls"]),
168159
)
169160

170161
if accumulated_response.get("text"):
171-
if has_data_collection_enabled(client.options):
172-
if client.options["data_collection"]["gen_ai"]["outputs"]:
173-
span.set_attribute(
174-
SPANDATA.GEN_AI_RESPONSE_TEXT,
175-
safe_serialize([accumulated_response["text"]]),
176-
)
177-
178-
elif should_send_default_pii():
162+
if client.options["data_collection"]["gen_ai"]["outputs"]:
179163
span.set_attribute(
180164
SPANDATA.GEN_AI_RESPONSE_TEXT,
181165
safe_serialize([accumulated_response["text"]]),

‎sentry_sdk/integrations/google_genai/utils.py‎

Lines changed: 5 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,9 @@
2727
transform_google_content_part,
2828
)
2929
from sentry_sdk.consts import OP, SPANDATA
30-
from sentry_sdk.scope import should_send_default_pii
3130
from sentry_sdk.utils import (
3231
capture_internal_exceptions,
3332
event_from_exception,
34-
has_data_collection_enabled,
3533
safe_serialize,
3634
)
3735

@@ -919,16 +917,7 @@ def set_span_data_for_request(
919917
if tools:
920918
formatted_tools = _format_tools_for_span(tools)
921919
if formatted_tools:
922-
if has_data_collection_enabled(client.options):
923-
if client.options["data_collection"]["gen_ai"]["inputs"]:
924-
set_data_normalized(
925-
span,
926-
SPANDATA.GEN_AI_REQUEST_AVAILABLE_TOOLS,
927-
formatted_tools,
928-
unpack=False,
929-
)
930-
else:
931-
# To remove once data collection has been fully rolled out
920+
if client.options["data_collection"]["gen_ai"]["inputs"]:
932921
set_data_normalized(
933922
span,
934923
SPANDATA.GEN_AI_REQUEST_AVAILABLE_TOOLS,
@@ -937,10 +926,7 @@ def set_span_data_for_request(
937926
)
938927

939928
record_inputs = False
940-
if has_data_collection_enabled(client.options):
941-
if client.options["data_collection"]["gen_ai"]["inputs"]:
942-
record_inputs = True
943-
elif should_send_default_pii():
929+
if client.options["data_collection"]["gen_ai"]["inputs"]:
944930
record_inputs = True
945931

946932
if record_inputs:
@@ -1043,29 +1029,14 @@ def set_span_data_for_response(
10431029

10441030
tool_calls = extract_tool_calls(response)
10451031
if tool_calls:
1046-
if has_data_collection_enabled(client.options):
1047-
if client.options["data_collection"]["gen_ai"]["outputs"]:
1048-
span.set_attribute(
1049-
SPANDATA.GEN_AI_RESPONSE_TOOL_CALLS, safe_serialize(tool_calls)
1050-
)
1051-
else:
1052-
# Before data collection was introduced, this was set unconditionally
1032+
if client.options["data_collection"]["gen_ai"]["outputs"]:
10531033
span.set_attribute(
10541034
SPANDATA.GEN_AI_RESPONSE_TOOL_CALLS, safe_serialize(tool_calls)
10551035
)
10561036

1057-
if has_data_collection_enabled(client.options):
1058-
if client.options["data_collection"]["gen_ai"]["outputs"]:
1059-
response_texts = _extract_response_text(response)
1060-
if response_texts:
1061-
span.set_attribute(
1062-
SPANDATA.GEN_AI_RESPONSE_TEXT, safe_serialize(response_texts)
1063-
)
1064-
elif should_send_default_pii():
1065-
# TODO: Delete this block once data collection has been completely rolled out
1037+
if client.options["data_collection"]["gen_ai"]["outputs"]:
10661038
response_texts = _extract_response_text(response)
10671039
if response_texts:
1068-
# Format as JSON string array as per documentation
10691040
span.set_attribute(
10701041
SPANDATA.GEN_AI_RESPONSE_TEXT, safe_serialize(response_texts)
10711042
)
@@ -1111,14 +1082,7 @@ def set_span_data_for_embed_request(
11111082
"""Set span data for embedding request."""
11121083
client = sentry_sdk.get_client()
11131084

1114-
record_inputs = False
1115-
if has_data_collection_enabled(client.options):
1116-
if client.options["data_collection"]["gen_ai"]["inputs"]:
1117-
record_inputs = True
1118-
elif should_send_default_pii():
1119-
record_inputs = True
1120-
1121-
if record_inputs:
1085+
if client.options["data_collection"]["gen_ai"]["inputs"]:
11221086
if contents:
11231087
# For embeddings, contents is typically a list of strings/texts
11241088
input_texts = []

0 commit comments

Comments
 (0)