feat(langgraph): Gate prompt/response collection on data_collection option - #7175
feat(langgraph): Gate prompt/response collection on data_collection option#7175ericapisani wants to merge 4 commits into
Conversation
…ption Modify the LangGraph integration to respect the data_collection config for controlling whether prompts, responses, tool calls, and available tools are captured in spans. When data collection is enabled, the gen_ai.inputs flag controls request messages, tool calls, and available tools, while gen_ai.outputs controls the response text. Tool calls are gated on inputs because they are fed back to the model as input. Available tools are only gated once data collection is configured, since they were never gated on the legacy PII settings. When data collection is not configured, falls back to legacy send_default_pii and include_prompts settings for compatibility. Refs PY-2588 Refs #6748
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit f54e39e. Configure here.
Rename the data collection tests and the invoke span helper so the names state what is being verified, and drop the now-redundant docstrings.
Codecov Results 📊✅ 112702 passed | ❌ 1 failed | ⏭️ 6759 skipped | Total: 119462 | Pass Rate: 94.34% | Execution Time: 412m 32s 📊 Comparison with Base Branch
➕ New Tests (1)View new tests
❌ Failed Tests
|
| File | Patch % | Lines |
|---|---|---|
| sentry_sdk/integrations/langgraph.py | 98.00% |
Coverage diff
@@ Coverage Diff @@
## main #PR +/-##
==========================================
- Coverage 90.21% 90.19% -0.02%
==========================================
Files 193 193 —
Lines 25361 25374 +13
Branches 9302 9320 +18
==========================================
+ Hits 22880 22886 +6
- Misses 2481 2488 +7
- Partials 1436 1439 +3Generated by Codecov Action
|
This integration sucks 😞 . |
|
@alexander-alderman-webb Got it sorted - the changes I had introduced broke the message deltas. Have moved where the input gate is so it doesn't affect that and added regression tests for this scenario 🚀 |
sentrivana
left a comment
There was a problem hiding this comment.
Looks good, left some suggestions
| SPANDATA.GEN_AI_REQUEST_MESSAGES, | ||
| messages_data, | ||
| unpack=False, | ||
| if _should_record_inputs(integration): |
There was a problem hiding this comment.
We could move this check above, to line 215, and combine it with the len(args) check so that we only do the input messages manipulation if necessary. Cheap way to save some cycles and remove one level of nesting.
| SPANDATA.GEN_AI_REQUEST_MESSAGES, | ||
| messages_data, | ||
| unpack=False, | ||
| if _should_record_inputs(integration): |
There was a problem hiding this comment.
Same here, we could combine this with the args check on L258.
| SPANDATA.GEN_AI_REQUEST_MESSAGES, | ||
| messages_data, | ||
| unpack=False, | ||
| if _should_record_inputs(integration): |
| SPANDATA.GEN_AI_REQUEST_MESSAGES, | ||
| messages_data, | ||
| unpack=False, | ||
| if _should_record_inputs(integration): |
There was a problem hiding this comment.
And here (goodness this integration is a mess)
There was a problem hiding this comment.
goodness this integration is a mess
Yeah, it needs a good overhaul 😭 😅

Modify the LangGraph integration to respect the data_collection config for controlling whether prompts, responses, tool calls, and available tools are captured in spans.
When data collection is enabled, the gen_ai.inputs flag controls request messages, tool calls, and available tools, while gen_ai.outputs controls the response text. Tool calls are gated on inputs because they are fed back to the model as input. Available tools are only gated once data collection is configured, since they were never gated on the legacy PII settings.
When data collection is not configured, falls back to legacy send_default_pii and include_prompts settings for compatibility.
Refs #6748
Refs #6748