feat(anthropic): Gate prompt collection on data_collection option - #7054
feat(anthropic): Gate prompt collection on data_collection option#7054ericapisani wants to merge 1 commit into
Conversation
Replace include_prompts and send_default_pii checks with the new data_collection configuration for controlling whether messages and system instructions are captured. Maintain backwards compatibility: when data_collection is not configured, fall back to the legacy pii/include_prompts behavior. Tools are always collected regardless of the message collection setting. Refs PY-2588
| and "content" in message | ||
| and isinstance(message["content"], (list, tuple)) | ||
| ): | ||
| transformed_content = [] | ||
| for item in message["content"]: |
There was a problem hiding this comment.
Bug: Tool collection is incorrectly gated by the gen_ai.inputs setting, contradicting the PR's goal to always collect them and causing a regression for users migrating to data_collection.
Severity: MEDIUM
Suggested Fix
Move the tool collection logic outside of the conditional check for gen_ai.inputs within the data_collection path. This will make tool collection unconditional, aligning the behavior with the legacy path and the PR's description.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.
Location: sentry_sdk/integrations/anthropic.py#L409-L413
Potential issue: The code in `anthropic.py` gates tool collection behind the
`client.options["data_collection"]["gen_ai"]["inputs"]` setting. This contradicts the
PR's stated goal that "Tools are always collected regardless of the message collection
setting." When users enable the new `data_collection` feature and set `gen_ai.inputs` to
`False`, they will unexpectedly lose tool data that was previously collected by default.
This creates a behavioral inconsistency between the legacy path and the new
`data_collection` path, and represents a regression for migrating users. The tests
confirm this conditional behavior, but they contradict the intended functionality
described in the pull request.
Also affects:
tests/integrations/anthropic/test_anthropic.py:329~336
Did we get this right? 👍 / 👎 to inform future reviews.
Codecov Results 📊✅ 93348 passed | ❌ 168 failed | ⏭️ 4764 skipped | Total: 98280 | Pass Rate: 94.98% | Execution Time: 341m 14s 📊 Comparison with Base Branch
➕ New Tests (168)View new tests
❌ Failed Tests
|
| File | Patch % | Lines |
|---|---|---|
| sentry_sdk/integrations/anthropic.py | 82.46% |
Coverage diff
@@ Coverage Diff @@
## main #PR +/-##
==========================================
- Coverage 89.92% 89.90% -0.02%
==========================================
Files 193 193 —
Lines 24908 24938 +30
Branches 8986 9016 +30
==========================================
+ Hits 22398 22419 +21
- Misses 2510 2519 +9
- Partials 1430 1438 +8Generated by Codecov Action
Replace include_prompts and send_default_pii checks with the new data_collection configuration for controlling whether messages and system instructions are captured. Maintain backwards compatibility: when data_collection is not configured, fall back to the legacy pii/include_prompts behavior. Tools are always collected regardless of the message collection setting.
Refs PY-2588