Skip to content

Commit 24da6c3

Browse files
authored
fix(docs): Add Next.js Node.js runtime instrumentation guidance (#15771)
<!-- Use this checklist to make sure your PR is ready for merge. You may delete any sections you don't need. --> ## DESCRIBE YOUR PR Automatic instrumentation of the OpenAI SDK may not work as expected with Next.js. This PR adds guidance for users to use manual instrumentation via `instrumentOpenAiClient` as the recommended approach. ## IS YOUR CHANGE URGENT? Help us prioritize incoming PRs by letting us know when the change needs to go live. - [ ] Urgent deadline (GA date, etc.): <!-- ENTER DATE HERE --> - [X] Other deadline: Dec 12th - [ ] None: Not urgent, can wait up to 1 week+ ## SLA - Teamwork makes the dream work, so please add a reviewer to your PRs. - Please give the docs team up to 1 week to review your PR unless you've added an urgent due date to it. Thanks in advance for your help! ## PRE-MERGE CHECKLIST *Make sure you've checked the following before merging your changes:* - [X] Checked Vercel preview for correctness, including links - [ ] PR was reviewed and approved by any necessary SMEs (subject matter experts) - [ ] PR was reviewed and approved by a member of the [Sentry docs team](https://github.com/orgs/getsentry/teams/docs) ## LEGAL BOILERPLATE <!-- Sentry employees and contractors can delete or ignore this section. --> Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. and is gonna need some rights from me in order to utilize my contributions in this here PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms. ## EXTRA RESOURCES - [Sentry Docs contributor guide](https://docs.sentry.io/contributing/)
1 parent 7af593c commit 24da6c3

File tree

1 file changed

+24
-27
lines changed
  • docs/platforms/javascript/common/configuration/integrations

1 file changed

+24
-27
lines changed

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

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ This integration works in the Node.js, Cloudflare Workers, Vercel Edge Functions
3535

3636
_Import name: `Sentry.openAIIntegration`_
3737

38-
The `openAIIntegration` adds instrumentation for the `openai` API to capture spans by automatically wrapping OpenAI client calls and recording LLM interactions with configurable input/output recording.
38+
The `openAIIntegration` adds instrumentation for the `openai` API to capture spans by wrapping OpenAI client calls and recording LLM interactions with configurable input/output recording.
3939

4040
<PlatformSection notSupported={["javascript.cloudflare", "javascript.nextjs", "javascript"]}>
4141
It is enabled by default and will automatically capture spans for OpenAI API method calls. You can opt-in to capture inputs and outputs by setting `recordInputs` and `recordOutputs` in the integration config:
@@ -77,6 +77,28 @@ const response = await client.chat.completions.create({
7777

7878
</PlatformSection>
7979

80+
<PlatformSection supported={["javascript.nextjs"]}>
81+
For Next.js applications, you need to manually instrument the OpenAI client using the `instrumentOpenAiClient` helper:
82+
83+
```javascript
84+
import * as Sentry from "@sentry/nextjs";
85+
import OpenAI from "openai";
86+
87+
const openai = new OpenAI();
88+
const client = Sentry.instrumentOpenAiClient(openai, {
89+
recordInputs: true,
90+
recordOutputs: true,
91+
});
92+
93+
// Use the wrapped client instead of the original openai instance
94+
const response = await client.chat.completions.create({
95+
model: "gpt-4o",
96+
messages: [{ role: "user", content: "Hello!" }],
97+
});
98+
```
99+
100+
</PlatformSection>
101+
80102
<PlatformSection supported={["javascript"]}>
81103
For browser applications, you need to manually instrument the OpenAI client using the `instrumentOpenAiClient` helper:
82104

@@ -138,31 +160,6 @@ By default this integration adds tracing support to OpenAI API method calls incl
138160

139161
The integration will automatically detect streaming vs non-streaming requests and handle them appropriately.
140162

141-
<PlatformSection supported={['javascript.nextjs']}>
142-
143-
## Edge runtime
144-
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:
146-
147-
```javascript
148-
import * as Sentry from "@sentry/nextjs";
149-
import OpenAI from "openai";
150-
151-
const openai = new OpenAI();
152-
const client = Sentry.instrumentOpenAiClient(openai, {
153-
recordInputs: true,
154-
recordOutputs: true,
155-
});
156-
157-
// Use the wrapped client instead of the original openai instance
158-
const response = await client.chat.completions.create({
159-
model: "gpt-4o",
160-
messages: [{ role: "user", content: "Hello!" }],
161-
});
162-
```
163-
164-
</PlatformSection>
165-
166163
## Supported Versions
167164

168-
- `openai`: `>=4.0.0 <6`
165+
- `openai`: `>=4.0.0 <7`

0 commit comments

Comments
 (0)