sentry-javascript
sentry-javascript copied to clipboard
fix(core): Preserve OpenAI APIPromise methods like withResponse()
Summary
The OpenAI SDK returns APIPromise objects with additional methods like .withResponse().
The previous async/await instrumentation converted these to regular Promises, losing those methods.
This PR uses Proxy + handleCallbackErrors pattern (matching anthropic-ai) to preserve the original return type.
Changes
- Use
Proxyinstead ofasync functionwrapper - Use
handleCallbackErrorsfor non-streaming responses (preserves Promise subclass) - Add
handleStreamingErrorhelper for consistency - Add tests for
APIPromise.withResponse()preservation
Test Plan
- [x]
yarn build:devpasses - [x]
yarn testpasses - [x]
yarn lintpasses - [x] Added tests for APIPromise preservation