Skip to content

ref!: Stop disabling client integrations when an agent integration is present - #7493

Merged
alexander-alderman-webb merged 13 commits into
major/3.0from
webb/agent-and-clients
Sep 15, 2026
Merged

alexander-alderman-webb merged 13 commits into
major/3.0from
webb/agent-and-clients

Conversation

@alexander-alderman-webb

@alexander-alderman-webb alexander-alderman-webb commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

Description

Use a boolean scope member to suppress chat spans from client libraries that are inside a chat span from an agent framework. Add the traces._AgentFrameworkChatGenerationContext wrapper to ensure the scope member is cleaned up correctly when the agent framework span exits.

Remove logic that disables client library integrations when an agent library is active. Delete the integration_deactivation tox environment that ran the corresponding tests.

Use the context manager in all agent frameworks that create chat generation spans (langchain, pydantic-ai, and openai-agents). Add early returns for chat generation spans in the openai, anthropic, and google-genai client libraries to prevent duplicate generation spans.

Remove embedding patches from the langchain integration. These must now be provided by client libraries like openai, anthropic, etc.

Issues

Closes #5515

Reminders

@alexander-alderman-webb alexander-alderman-webb changed the title ref: Stop disabling client integrations when an agent integration is … ref: Stop disabling client integrations when an agent integration is present Sep 14, 2026
@alexander-alderman-webb
alexander-alderman-webb marked this pull request as ready for review September 14, 2026 09:50
@alexander-alderman-webb
alexander-alderman-webb requested a review from a team as a code owner September 14, 2026 09:50
@github-actions

github-actions Bot commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

Codecov Results 📊

66703 passed | ⏭️ 3050 skipped | Total: 69753 | Pass Rate: 95.63% | Execution Time: 190m 41s

📊 Comparison with Base Branch

Metric Change
Total Tests 📉 -65699
Passed Tests 📉 -61618
Failed Tests
Skipped Tests 📉 -4081

All tests are passing successfully.

✅ Patch coverage is 87.76%. Project has 2262 uncovered lines.
❌ Project coverage is 89.46%. Comparing base (660a4b3) to head (a2107ac).

Files with missing lines (4)
File Patch % Lines
sentry_sdk/integrations/anthropic.py 50.00% ⚠️ 4 Missing and 4 partials
sentry_sdk/integrations/google_genai/init.py 50.00% ⚠️ 4 Missing and 2 partials
sentry_sdk/integrations/langchain.py 88.46% ⚠️ 3 Missing and 3 partials
sentry_sdk/integrations/openai.py 87.50% ⚠️ 1 Missing and 1 partials
Coverage diff
@@            Coverage Diff             @@
##        master       #PR       +/-##
==========================================
- Coverage    90.17%    89.46%    -0.71%
==========================================
  Files          193       180       -13
  Lines        25768     21460     -4308
  Branches      9532      7804     -1728
==========================================
+ Hits         23236     19198     -4038
- Misses        2532      2262      -270
- Partials      1432      1217      -215

Generated by Codecov Action

@sentrivana sentrivana left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this would work.

Why do we want to go via this route in the first place? What do we gain over the current way of doing things?

Comment thread sentry_sdk/traces.py
Comment on lines +124 to +126
@property
def span(self) -> "StreamedSpan":
return self._span

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why have a special property for this and not return the span directly in __enter__? Might be wrong, but from a cursory look we seem to only ever be interacting with the span when using the context manager.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea would be for the agent frameworks to use this wrapper with the context manager protocol since __exit__() sets

self._span._scope._agent_framework_generation_entered = False

@alexander-alderman-webb

alexander-alderman-webb commented Sep 14, 2026

Copy link
Copy Markdown
Contributor Author

Users that use both agent and client frameworks in the same process would benefit.
So, e.g., Seer does a google-genai call to search the docs inside a tool. Seer doesn't use an off-the-shelf framework but generally this seems to be a common pattern that I've seen a few times in users' traces.

@sentrivana sentrivana left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK sounds good!

@alexander-alderman-webb alexander-alderman-webb changed the title ref: Stop disabling client integrations when an agent integration is present ref!: Stop disabling client integrations when an agent integration is present Sep 15, 2026
@alexander-alderman-webb
alexander-alderman-webb merged commit 6bf8ed9 into major/3.0 Sep 15, 2026
147 checks passed
@alexander-alderman-webb
alexander-alderman-webb deleted the webb/agent-and-clients branch September 15, 2026 08:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants