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

fix(core): Preserve OpenAI APIPromise methods like withResponse()

Open Sai-Tom opened this issue 1 month ago • 0 comments

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 Proxy instead of async function wrapper
  • Use handleCallbackErrors for non-streaming responses (preserves Promise subclass)
  • Add handleStreamingError helper for consistency
  • Add tests for APIPromise.withResponse() preservation

Test Plan

  • [x] yarn build:dev passes
  • [x] yarn test passes
  • [x] yarn lint passes
  • [x] Added tests for APIPromise preservation

Sai-Tom avatar Dec 04 '25 09:12 Sai-Tom