getsentry / getsentry/sentry-javascript
AI integration deep proxies return new function references on every property access
- Dominant language
- TypeScript
- Stars
- 8.7k
- Forks
- 1.8k
- Avg merge
- 1d 17h
- Merged PRs (30d)
- 515
Description
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` 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
Contributor guide
Research direction
Start at createDeepProxy in packages/core/src/tracing/openai/index.ts, packages/core/src/tracing/anthropic-ai/index.ts, and packages/core/src/tracing/google-genai/index.ts. Trace the get trap and the instrumentMethod or bind paths, then verify that repeated access to the same method returns the same reference while preserving instrumentation behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- observability
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100