Skip to content

Commit 2ed93d8

Browse files
committed
fix(docs): Add Next.js Node.js runtime instrumentation guidance
1 parent 394df25 commit 2ed93d8

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
@@ -117,9 +117,37 @@ The integration will automatically detect streaming vs non-streaming requests an
117117

118118
<PlatformSection supported={['javascript.nextjs']}>
119119

120-
## Edge runtime
120+
## Node.js Runtime
121121

122-
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:
122+
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.
123+
124+
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:
125+
126+
```javascript
127+
module.exports = {
128+
webpack(config, { isServer }) {
129+
if (isServer) {
130+
// Force 'openai' to be required dynamically (not bundled)
131+
// This allows Sentry to instrument the OpenAI SDK at runtime
132+
config.externals = config.externals || [];
133+
config.externals.push("openai");
134+
}
135+
return config;
136+
},
137+
};
138+
```
139+
140+
This ensures the package is externalized at runtime.
141+
142+
<Note>
143+
144+
This cannot be achieved using `serverExternalPackages: ['openai']`.
145+
146+
</Note>
147+
148+
## Edge Runtime
149+
150+
For Next.js applications using the Edge runtime, you need to manually instrument the OpenAI client:
123151

124152
```javascript
125153
import * as Sentry from "@sentry/nextjs";

0 commit comments

Comments
 (0)