Skip to content

Commit 2b0db9f

Browse files
authored
feat(anthropic): Gate output collection on data_collection option (#7121)
Output data (text and tool calls) is now gated on the data_collection configuration, mirroring input collection behavior. When data_collection is configured, its gen_ai.outputs setting is respected. When not configured, falls back to the legacy send_default_pii and include_prompts behavior. Refs PY-2588
1 parent d03110e commit 2b0db9f

2 files changed

Lines changed: 908 additions & 7 deletions

File tree

sentry_sdk/integrations/anthropic.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,16 @@ def _set_output_data(
606606
set_on_span(SPANDATA.GEN_AI_RESPONSE_ID, response_id)
607607
if finish_reason is not None:
608608
set_on_span(SPANDATA.GEN_AI_RESPONSE_FINISH_REASONS, [finish_reason])
609-
if should_send_default_pii() and integration.include_prompts:
609+
610+
client = sentry_sdk.get_client()
611+
record_outputs = False
612+
if has_data_collection_enabled(client.options):
613+
if client.options["data_collection"]["gen_ai"]["outputs"]:
614+
record_outputs = True
615+
elif should_send_default_pii() and integration.include_prompts:
616+
record_outputs = True
617+
618+
if record_outputs:
610619
output_messages: "dict[str, list[Any]]" = {
611620
"response": [],
612621
"tool": [],

0 commit comments

Comments
 (0)