Skip to content

Commit 29f62c1

Browse files
committed
fix(docs): Add Next.js Node.js runtime instrumentation guidance
1 parent 7af593c commit 29f62c1

File tree

1 file changed

+30
-2
lines changed
  • docs/platforms/javascript/common/configuration/integrations

1 file changed

+30
-2
lines changed

docs/platforms/javascript/common/configuration/integrations/openai.mdx

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,37 @@ The integration will automatically detect streaming vs non-streaming requests an
140140

141141
<PlatformSection supported={['javascript.nextjs']}>
142142

143-
## Edge runtime
143+
## Node.js Runtime
144144

145-
This integration is automatically instrumented in the Node.js runtime. For Next.js applications using the Edge runtime, you need to manually instrument the OpenAI client:
145+
Automatic instrumentation of the OpenAI SDK may not work as expected with certain Next.js configurations (especially with Turbopack and in Next.js 16). In these cases, manual instrumentation via `instrumentOpenAiClient` is recommended.
146+
147+
For projects using Next.js 15 or earlier with Webpack, the following configuration can be applied in your `next.config.js` to ensure proper instrumentation:
148+
149+
```javascript
150+
module.exports = {
151+
webpack(config, { isServer }) {
152+
if (isServer) {
153+
// Force 'openai' to be required dynamically (not bundled)
154+
// This allows Sentry to instrument the OpenAI SDK at runtime
155+
config.externals = config.externals || [];
156+
config.externals.push("openai");
157+
}
158+
return config;
159+
},
160+
};
161+
```
162+
163+
This ensures the package is externalized at runtime.
164+
165+
<Note>
166+
167+
This cannot be achieved using `serverExternalPackages: ['openai']`.
168+
169+
</Note>
170+
171+
## Edge Runtime
172+
173+
For Next.js applications using the Edge runtime, you need to manually instrument the OpenAI client:
146174

147175
```javascript
148176
import * as Sentry from "@sentry/nextjs";

0 commit comments

Comments
 (0)