Skip to content

Conversation

@RulaKhaled
Copy link
Member

When Sentry instruments the OpenAI client, we return an instrumented promise. The OpenAI SDK returns a custom promise-like object with extra methods like .withResponse(), so returning a plain Promise breaks those methods.

We added wrapPromiseWithMethods() to proxy SDK methods back onto the instrumented promise. However, for streaming calls, .withResponse() returned the original uninstrumented stream, so we fixed it by intercepting .withResponse() in the proxy:

  • call original .withResponse() to get metadata (response, request_id)
  • await the instrumented promise
  • return the same wrapper but swap data to the instrumented stream

Closes #19073

@linear
Copy link

linear bot commented Feb 2, 2026

@github-actions
Copy link
Contributor

github-actions bot commented Feb 2, 2026

Codecov Results 📊


Generated by Codecov Action

@github-actions
Copy link
Contributor

github-actions bot commented Feb 2, 2026

size-limit report 📦

Path Size % Change Change
@sentry/browser 25.43 kB - -
@sentry/browser - with treeshaking flags 23.89 kB - -
@sentry/browser (incl. Tracing) 42.27 kB - -
@sentry/browser (incl. Tracing, Profiling) 46.92 kB - -
@sentry/browser (incl. Tracing, Replay) 80.89 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 70.49 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 85.61 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 97.78 kB - -
@sentry/browser (incl. Feedback) 42.15 kB - -
@sentry/browser (incl. sendFeedback) 30.11 kB - -
@sentry/browser (incl. FeedbackAsync) 35.12 kB - -
@sentry/browser (incl. Metrics) 26.54 kB - -
@sentry/browser (incl. Logs) 26.69 kB - -
@sentry/browser (incl. Metrics & Logs) 27.35 kB - -
@sentry/react 27.15 kB - -
⛔️ @sentry/react (incl. Tracing) (max: 44.5 kB) 44.52 kB - -
@sentry/vue 29.86 kB - -
@sentry/vue (incl. Tracing) 44.08 kB - -
@sentry/svelte 25.45 kB - -
CDN Bundle 27.97 kB - -
CDN Bundle (incl. Tracing) 43.04 kB - -
CDN Bundle (incl. Logs, Metrics) 28.81 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 43.86 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 67.76 kB - -
CDN Bundle (incl. Tracing, Replay) 79.78 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 80.67 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 85.22 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 86.14 kB - -
CDN Bundle - uncompressed 81.8 kB - -
CDN Bundle (incl. Tracing) - uncompressed 127.51 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 84.63 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 130.34 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 208.02 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 244.11 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 246.93 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 256.91 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 259.72 kB - -
@sentry/nextjs (client) 46.87 kB - -
@sentry/sveltekit (client) 42.65 kB - -
@sentry/node-core 52.18 kB -0.01% -1 B 🔽
@sentry/node 166.34 kB +0.09% +147 B 🔺
@sentry/node - without tracing 93.96 kB -0.01% -1 B 🔽
@sentry/aws-serverless 109.48 kB -0.01% -1 B 🔽

View base workflow run

@github-actions
Copy link
Contributor

github-actions bot commented Feb 2, 2026

node-overhead report 🧳

Note: This is a synthetic benchmark with a minimal express app and does not necessarily reflect the real-world performance impact in an application.

Scenario Requests/s % of Baseline Prev. Requests/s Change %
GET Baseline 11,361 - 9,086 +25%
GET With Sentry 1,973 17% 1,653 +19%
GET With Sentry (error only) 7,663 67% 6,094 +26%
POST Baseline 1,159 - 1,166 -1%
POST With Sentry 595 51% 539 +10%
POST With Sentry (error only) 1,043 90% 1,027 +2%
MYSQL Baseline 4,049 - 3,282 +23%
MYSQL With Sentry 539 13% 393 +37%
MYSQL With Sentry (error only) 3,335 82% 2,680 +24%

View base workflow run

Copy link

@cursor cursor bot left a comment

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.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

const result = client.chat.completions.create({
model: 'gpt-4',
messages: [{ role: 'user', content: 'Test withResponse' }],
});
Copy link

Choose a reason for hiding this comment

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

Test doesn't cover streaming .withResponse() regression

Low Severity

The PR description states the fix is specifically for streaming calls where .withResponse() returned the original uninstrumented stream. However, the test scenario only tests non-streaming calls (no stream: true parameter). According to the review rules for fix PRs, tests should verify the specific regression being fixed. A streaming test case with .withResponse() would provide confidence that the core bug is actually fixed. Flagging this because the review rules file specifies that fix PRs should include tests for the specific regression.

Fix in Cursor Fix in Web

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 OpenAI Instrumentation breaks withResponse()

2 participants