sentry-javascript icon indicating copy to clipboard operation
sentry-javascript copied to clipboard

AI integration deep proxies return new function references on every property access

Open JPeer264 opened this issue 4 months ago • 6 comments

The get trap in AI integration deep proxies always returns a different value instead of memoizing bound/instrumented methods.

For example, console.log(ai.run === ai.run) prints false because each access creates a new function via instrumentMethod(...) or value.bind(obj).

This pattern exists across multiple AI integrations:

  • packages/core/src/tracing/openai/index.ts (createDeepProxy)
  • packages/core/src/tracing/anthropic-ai/index.ts (createDeepProxy)
  • packages/core/src/tracing/google-genai/index.ts (createDeepProxy)

Suggested fix: keep a Map<string | symbol, Function> in the closure to store bound/instrumented methods, rather than creating a new value on every get.

Originally posted by @isaacs in https://github.com/getsentry/sentry-javascript/pull/22119#discussion_r3581015061

JPeer264 avatar Jul 17 '26 09:07 JPeer264

JS-3082

linear-code[bot] avatar Jul 17 '26 09:07 linear-code[bot]

I tightened the title and added the specific files where this deep-proxy pattern lives so the fix is easier to scope.

sentry-pierre[bot] avatar Jul 17 '26 09:07 sentry-pierre[bot]

I'd like to work on this. I'll keep the change scoped to making repeated nested property access return stable references across the affected AI integrations, add focused regression tests, and verify each provider against the current develop branch.

psh4607 avatar Jul 22 '26 02:07 psh4607

@psh4607 Sure sounds good! I see you already opened a PR. Someone from the team will take a look, but might take some time as we are busy preparing the next major. Also we'll update the AI integrations a bit over the coming weeks and it will likely be easier to wait for these changes as these might conflict.

nicohrubec avatar Jul 23 '26 07:07 nicohrubec

@nicohrubec Thank you for the context. I’ll revisit the PR once the upcoming AI integration changes land, then rebase and make any necessary updates.

psh4607 avatar Jul 27 '26 00:07 psh4607

A PR closing this issue has just been released 🚀

This issue was referenced by PR #22474, which was included in the 11.10.0 release.

github-actions[bot] avatar Oct 28 '26 16:10 github-actions[bot]