Skip to content

fix(core): Instrument Anthropic client in place instead of via a deep proxy#22305

Open
logaretm wants to merge 1 commit into
developfrom
fix/anthropic-instrumentation-transparency
Open

fix(core): Instrument Anthropic client in place instead of via a deep proxy#22305
logaretm wants to merge 1 commit into
developfrom
fix/anthropic-instrumentation-transparency

Conversation

@logaretm

@logaretm logaretm commented Jul 15, 2026

Copy link
Copy Markdown
Member

Instruments the Anthropic client's methods in place instead of wrapping the client in a deep Proxy, so our instrumentation stops changing the client's observable behavior.

closes #20291

… proxy

The Anthropic integration wrapped the client in a deep Proxy that ran every
method with the raw object as `this`. That changed the client's observable
semantics: internal delegation (`messages.stream()` calling `this.create()`)
resolved against the raw object, so it escaped any outer wrapper and behaved
differently than an uninstrumented client.

Instrument the registered methods in place instead (own properties shadowing
the prototype), invoking them with the caller's `this`. Instrumentation is now
observationally transparent: private-field access and internal delegation work
as they do on a plain client. A re-entrancy guard keyed on the active streaming
helper span keeps `stream()`'s internal `create()` call from producing a
duplicate span.
@logaretm logaretm marked this pull request as ready for review July 15, 2026 18:43

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 069d7fb. Configure here.

*/
export function instrumentAnthropicAiClient<T extends object>(anthropicAiClient: T, options?: AnthropicAiOptions): T {
return createDeepProxy(anthropicAiClient, '', resolveAIRecordingOptions(options));
return instrumentClientInPlace(anthropicAiClient, resolveAIRecordingOptions(options));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Missing regression test for fix

Medium Severity

Flagged because it was mentioned in the PR review rules file: this is a fix PR, but the diff only changes production code and does not add a unit, integration, or E2E test covering the regression (Proxy-related observable behavior / in-place instrumentation). That coverage should fail without the fix and pass with it.

Fix in Cursor Fix in Web

Triggered by project rule: PR Review Guidelines for Cursor Bot

Reviewed by Cursor Bugbot for commit 069d7fb. Configure here.

@github-actions

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size % Change Change
@sentry/browser 27.67 kB - -
@sentry/browser - with treeshaking flags 26.12 kB - -
@sentry/browser (incl. Tracing) 46.44 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 48.23 kB - -
@sentry/browser (incl. Tracing, Profiling) 51.23 kB - -
@sentry/browser (incl. Tracing, Replay) 85.69 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 75.33 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 90.41 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 103.07 kB - -
@sentry/browser (incl. Feedback) 44.85 kB - -
@sentry/browser (incl. sendFeedback) 32.47 kB - -
@sentry/browser (incl. FeedbackAsync) 37.6 kB - -
@sentry/browser (incl. Metrics) 28.77 kB - -
@sentry/browser (incl. Logs) 29 kB - -
@sentry/browser (incl. Metrics & Logs) 29.68 kB - -
@sentry/react 29.48 kB - -
@sentry/react (incl. Tracing) 48.7 kB - -
@sentry/vue 33.1 kB - -
@sentry/vue (incl. Tracing) 48.42 kB - -
@sentry/svelte 27.7 kB - -
CDN Bundle 30.07 kB - -
CDN Bundle (incl. Tracing) 48.43 kB - -
CDN Bundle (incl. Logs, Metrics) 31.65 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 49.73 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 70.89 kB - -
CDN Bundle (incl. Tracing, Replay) 85.93 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 87.23 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 91.72 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 92.98 kB - -
CDN Bundle - uncompressed 89.7 kB - -
CDN Bundle (incl. Tracing) - uncompressed 146.45 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 94.4 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 150.42 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 219.13 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 265.65 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 269.61 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 279.35 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 283.3 kB - -
@sentry/nextjs (client) 51.25 kB - -
@sentry/sveltekit (client) 46.88 kB - -
@sentry/core/server 78.67 kB +0.17% +128 B 🔺
@sentry/core/browser 65.03 kB +0.22% +138 B 🔺
@sentry/node-core 63.35 kB +0.01% +1 B 🔺
@sentry/node 125.42 kB +0.06% +74 B 🔺
@sentry/node (incl. diagnostics channel injection) 140.49 kB +0.07% +91 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 70.03 kB - -
@sentry/node/light 51.26 kB +0.01% +1 B 🔺
@sentry/node - without tracing 74.65 kB +0.01% +1 B 🔺
@sentry/aws-serverless 83.87 kB -0.01% -1 B 🔽
@sentry/cloudflare (withSentry) - minified 181.91 kB - -
@sentry/cloudflare (withSentry) 450.25 kB - -

View base workflow run

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.

Sentry tracing breaks third-party diagnostics_channel TracingChannel stream instrumentation

1 participant