Skip to content

Commit b87fd32

Browse files
committed
feat: Document OpenAI integration
1 parent 859be5c commit b87fd32

File tree

15 files changed

+121
-0
lines changed

15 files changed

+121
-0
lines changed
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
---
2+
title: OpenAI
3+
description: "Adds instrumentation for OpenAI API."
4+
supported:
5+
- javascript.node
6+
- javascript.aws-lambda
7+
- javascript.azure-functions
8+
- javascript.connect
9+
- javascript.express
10+
- javascript.fastify
11+
- javascript.gcp-functions
12+
- javascript.hapi
13+
- javascript.hono
14+
- javascript.koa
15+
- javascript.nestjs
16+
- javascript.electron
17+
- javascript.nextjs
18+
- javascript.nuxt
19+
- javascript.solidstart
20+
- javascript.sveltekit
21+
- javascript.react-router
22+
- javascript.remix
23+
- javascript.astro
24+
- javascript.bun
25+
- javascript.tanstackstart-react
26+
---
27+
28+
<Alert>
29+
30+
This integration only works in the Node.js runtime. Requires SDK version `9.42.0` or higher.
31+
32+
</Alert>
33+
34+
_Import name: `Sentry.openAIIntegration`_
35+
36+
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.
37+
38+
It is enabled by default and will automatically capture spans for all OpenAI API method calls. You can opt-in to capture inputs and outputs by setting `recordInputs` and `recordOutputs` in the integration config:
39+
40+
```javascript
41+
Sentry.init({
42+
dsn: "____PUBLIC_DSN____",
43+
tracesSampleRate: 1.0,
44+
integrations: [
45+
Sentry.openAIIntegration({
46+
recordInputs: true,
47+
recordOutputs: true,
48+
}),
49+
],
50+
});
51+
```
52+
53+
<PlatformSection supported={['javascript.nextjs']}>
54+
55+
This integration only works in the Node.js runtime, not in the Edge runtime. For Next.js applications using the Edge runtime, this integration will not be available.
56+
57+
</PlatformSection>
58+
59+
<PlatformSection>
60+
## Options
61+
62+
### `recordInputs`
63+
64+
Requires SDK version `9.42.0` or higher.
65+
66+
_Type: `boolean`_
67+
68+
Records inputs to OpenAI API method calls (such as prompts and messages).
69+
70+
Defaults to `true` if `sendDefaultPii` is `true`.
71+
72+
```javascript
73+
Sentry.init({
74+
integrations: [Sentry.openAIIntegration({ recordInputs: true })],
75+
});
76+
```
77+
78+
### `recordOutputs`
79+
80+
Requires SDK version `9.42.0` or higher.
81+
82+
_Type: `boolean`_
83+
84+
Records outputs from OpenAI API method calls (such as generated text and responses).
85+
86+
Defaults to `true` if `sendDefaultPii` is `true`.
87+
88+
```javascript
89+
Sentry.init({
90+
integrations: [Sentry.openAIIntegration({ recordOutputs: true })],
91+
});
92+
```
93+
94+
</PlatformSection>
95+
96+
## Configuration
97+
98+
By default this integration adds tracing support to OpenAI API method calls including:
99+
100+
- `chat.completions.create()` - Chat completion requests
101+
- `responses.create()` - Response API requests
102+
103+
The integration will automatically detect streaming vs non-streaming requests and handle them appropriately.
104+
105+
## Supported Versions
106+
107+
- `openai`: `>=4.0.0 <6`

platform-includes/configuration/integrations/javascript.astro.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,4 @@ Depending on whether an integration enhances the functionality of a particular r
8181
| [`localVariablesIntegration`](./localvariables) | || | |
8282
| [`nodeProfilingIntegration`](./nodeprofiling) | | || |
8383
| [`trpcMiddleware`](./trpc) | ||||
84+
| [`openAIIntegration`](./openai) || || |

platform-includes/configuration/integrations/javascript.aws-lambda.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
| [`onUnhandledRejectionIntegration`](./unhandledrejection) ||| | |
1919
| [`childProcessIntegration`](./childProcess) || | ||
2020
| [`vercelAiIntegration`](./vercelai) || || |
21+
| [`openAIIntegration`](./openai) || || |
2122
| [`amqplibIntegration`](./amqplib) | | || |
2223
| [`anrIntegration`](./anr) | || | |
2324
| [`captureConsoleIntegration`](./captureconsole) | | | ||

platform-includes/configuration/integrations/javascript.bun.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
| [`tediousIntegration`](./tedious) || || |
3131
| [`prismaIntegration`](./prisma) || || |
3232
| [`vercelAiIntegration`](./vercelai) || || |
33+
| [`openAIIntegration`](./openai) || || |
3334
| [`captureConsoleIntegration`](./captureconsole) | | | ||
3435
| [`dataloaderIntegration`](./dataloader) | | || |
3536
| [`extraErrorDataIntegration`](./extraerrordata) | | | ||

platform-includes/configuration/integrations/javascript.connect.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
| [`childProcessIntegration`](./childProcess) || | ||
3232
| [`rewriteFramesIntegration`](./rewriteframes) ||| | |
3333
| [`vercelAiIntegration`](./vercelai) || || |
34+
| [`openAIIntegration`](./openai) || || |
3435
| [`anrIntegration`](./anr) | || | |
3536
| [`captureConsoleIntegration`](./captureconsole) | | | ||
3637
| [`eventLoopBlockIntegration`](./event-loop-block) | || | |

platform-includes/configuration/integrations/javascript.fastify.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
| [`childProcessIntegration`](./childProcess) || | ||
3232
| [`prismaIntegration`](./prisma) || || |
3333
| [`vercelAiIntegration`](./vercelai) || || |
34+
| [`openAIIntegration`](./openai) || || |
3435
| [`anrIntegration`](./anr) | || | |
3536
| [`captureConsoleIntegration`](./captureconsole) | | | ||
3637
| [`eventLoopBlockIntegration`](./event-loop-block) | || | |

platform-includes/configuration/integrations/javascript.gcp-functions.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
| [`onUnhandledRejectionIntegration`](./unhandledrejection) ||| | |
1919
| [`childProcessIntegration`](./childProcess) || | ||
2020
| [`vercelAiIntegration`](./vercelai) || || |
21+
| [`openAIIntegration`](./openai) || || |
2122
| [`amqplibIntegration`](./amqplib) | | || |
2223
| [`anrIntegration`](./anr) | || | |
2324
| [`captureConsoleIntegration`](./captureconsole) | | | ||

platform-includes/configuration/integrations/javascript.hapi.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
| [`childProcessIntegration`](./childProcess) || | ||
3232
| [`prismaIntegration`](./prisma) || || |
3333
| [`vercelAiIntegration`](./vercelai) || || |
34+
| [`openAIIntegration`](./openai) || || |
3435
| [`anrIntegration`](./anr) | || | |
3536
| [`captureConsoleIntegration`](./captureconsole) | | | ||
3637
| [`eventLoopBlockIntegration`](./event-loop-block) | || | |

platform-includes/configuration/integrations/javascript.nestjs.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,4 @@
4444
| [`supabaseIntegration`](./supabase) | ||| |
4545
| [`trpcMiddleware`](./trpc) | ||||
4646
| [`unleashIntegration`](./unleash) | | | ||
47+
| [`openAIIntegration`](./openai) || || |

platform-includes/configuration/integrations/javascript.nextjs.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ Depending on whether an integration enhances the functionality of a particular r
8787
| [`nodeProfilingIntegration`](./nodeprofiling) | | || |
8888
| [`trpcMiddleware`](./trpc) | ||||
8989
| [`vercelAiIntegration`](./vercelai) || |||
90+
| [`openAIIntegration`](./openai) || || |
9091

9192
### Edge Integrations
9293

0 commit comments

Comments
 (0)