Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 107 additions & 0 deletions docs/platforms/javascript/common/configuration/integrations/openai.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
---
title: OpenAI
description: "Adds instrumentation for OpenAI API."
supported:
- javascript.node
- javascript.aws-lambda
- javascript.azure-functions
- javascript.connect
- javascript.express
- javascript.fastify
- javascript.gcp-functions
- javascript.hapi
- javascript.hono
- javascript.koa
- javascript.nestjs
- javascript.electron
- javascript.nextjs
- javascript.nuxt
- javascript.solidstart
- javascript.sveltekit
- javascript.react-router
- javascript.remix
- javascript.astro
- javascript.bun
- javascript.tanstackstart-react
---

<Alert>

This integration only works in the Node.js runtime. Requires SDK version `9.44.0` or higher.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
This integration only works in the Node.js runtime. Requires SDK version `9.44.0` or higher.
This integration only works in the Node.js runtime, and requires SDK version `9.44.0` or higher.


</Alert>

_Import name: `Sentry.openAIIntegration`_

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.

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:

```javascript
Sentry.init({
dsn: "____PUBLIC_DSN____",
tracesSampleRate: 1.0,
integrations: [
Sentry.openAIIntegration({
recordInputs: true,
recordOutputs: true,
}),
],
});
```

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

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.

</PlatformSection>

<PlatformSection>
## Options

### `recordInputs`

Requires SDK version `9.44.0` or higher.
Copy link
Contributor

Choose a reason for hiding this comment

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

Since you outlined the SDK requirement at the top, I'd recommend removing it from the options section.


_Type: `boolean`_

Records inputs to OpenAI API method calls (such as prompts and messages).

Defaults to `true` if `sendDefaultPii` is `true`.

```javascript
Sentry.init({
integrations: [Sentry.openAIIntegration({ recordInputs: true })],
});
```

### `recordOutputs`

Requires SDK version `9.44.0` or higher.

_Type: `boolean`_

Records outputs from OpenAI API method calls (such as generated text and responses).

Defaults to `true` if `sendDefaultPii` is `true`.

```javascript
Sentry.init({
integrations: [Sentry.openAIIntegration({ recordOutputs: true })],
});
```

</PlatformSection>

## Configuration

By default this integration adds tracing support to OpenAI API method calls including:

- `chat.completions.create()` - Chat completion requests
- `responses.create()` - Response API requests

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

## Supported Versions

- `openai`: `>=4.0.0 <6`
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,4 @@ Depending on whether an integration enhances the functionality of a particular r
| [`localVariablesIntegration`](./localvariables) | | ✓ | | |
| [`nodeProfilingIntegration`](./nodeprofiling) | | | ✓ | |
| [`trpcMiddleware`](./trpc) | | ✓ | ✓ | ✓ |
| [`openAIIntegration`](./openai) | ✓ | | ✓ | |
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
| [`onUnhandledRejectionIntegration`](./unhandledrejection) | ✓ | ✓ | | |
| [`childProcessIntegration`](./childProcess) | ✓ | | | ✓ |
| [`vercelAiIntegration`](./vercelai) | ✓ | | ✓ | |
| [`openAIIntegration`](./openai) | ✓ | | ✓ | |
| [`amqplibIntegration`](./amqplib) | | | ✓ | |
| [`anrIntegration`](./anr) | | ✓ | | |
| [`captureConsoleIntegration`](./captureconsole) | | | | ✓ |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
| [`tediousIntegration`](./tedious) | ✓ | | ✓ | |
| [`prismaIntegration`](./prisma) | ✓ | | ✓ | |
| [`vercelAiIntegration`](./vercelai) | ✓ | | ✓ | |
| [`openAIIntegration`](./openai) | ✓ | | ✓ | |
| [`captureConsoleIntegration`](./captureconsole) | | | | ✓ |
| [`dataloaderIntegration`](./dataloader) | | | ✓ | |
| [`extraErrorDataIntegration`](./extraerrordata) | | | | ✓ |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
| [`childProcessIntegration`](./childProcess) | ✓ | | | ✓ |
| [`rewriteFramesIntegration`](./rewriteframes) | ✓ | ✓ | | |
| [`vercelAiIntegration`](./vercelai) | ✓ | | ✓ | |
| [`openAIIntegration`](./openai) | ✓ | | ✓ | |
| [`anrIntegration`](./anr) | | ✓ | | |
| [`captureConsoleIntegration`](./captureconsole) | | | | ✓ |
| [`eventLoopBlockIntegration`](./event-loop-block) | | ✓ | | |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
| [`childProcessIntegration`](./childProcess) | ✓ | | | ✓ |
| [`prismaIntegration`](./prisma) | ✓ | | ✓ | |
| [`vercelAiIntegration`](./vercelai) | ✓ | | ✓ | |
| [`openAIIntegration`](./openai) | ✓ | | ✓ | |
| [`anrIntegration`](./anr) | | ✓ | | |
| [`captureConsoleIntegration`](./captureconsole) | | | | ✓ |
| [`eventLoopBlockIntegration`](./event-loop-block) | | ✓ | | |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
| [`onUnhandledRejectionIntegration`](./unhandledrejection) | ✓ | ✓ | | |
| [`childProcessIntegration`](./childProcess) | ✓ | | | ✓ |
| [`vercelAiIntegration`](./vercelai) | ✓ | | ✓ | |
| [`openAIIntegration`](./openai) | ✓ | | ✓ | |
| [`amqplibIntegration`](./amqplib) | | | ✓ | |
| [`anrIntegration`](./anr) | | ✓ | | |
| [`captureConsoleIntegration`](./captureconsole) | | | | ✓ |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
| [`childProcessIntegration`](./childProcess) | ✓ | | | ✓ |
| [`prismaIntegration`](./prisma) | ✓ | | ✓ | |
| [`vercelAiIntegration`](./vercelai) | ✓ | | ✓ | |
| [`openAIIntegration`](./openai) | ✓ | | ✓ | |
| [`anrIntegration`](./anr) | | ✓ | | |
| [`captureConsoleIntegration`](./captureconsole) | | | | ✓ |
| [`eventLoopBlockIntegration`](./event-loop-block) | | ✓ | | |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,4 @@
| [`supabaseIntegration`](./supabase) | | ✓ | ✓ | |
| [`trpcMiddleware`](./trpc) | | ✓ | ✓ | ✓ |
| [`unleashIntegration`](./unleash) | | | | ✓ |
| [`openAIIntegration`](./openai) | ✓ | | ✓ | |
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ Depending on whether an integration enhances the functionality of a particular r
| [`nodeProfilingIntegration`](./nodeprofiling) | | | ✓ | |
| [`trpcMiddleware`](./trpc) | | ✓ | ✓ | ✓ |
| [`vercelAiIntegration`](./vercelai) | ✓ | | ✓ | ✓ |
| [`openAIIntegration`](./openai) | ✓ | | ✓ | |

### Edge Integrations

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@
| [`supabaseIntegration`](./supabase) | | ✓ | ✓ | |
| [`tediousIntegration`](./tedious) | ✓ | | ✓ | |
| [`trpcMiddleware`](./trpc) | | ✓ | ✓ | ✓ |
| [`openAIIntegration`](./openai) | ✓ | | ✓ | |
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,4 @@ Depending on whether an integration enhances the functionality of a particular r
| [`localVariablesIntegration`](./localvariables) | | ✓ | | |
| [`nodeProfilingIntegration`](./nodeprofiling) | | | ✓ | |
| [`trpcMiddleware`](./trpc) | | ✓ | ✓ | ✓ |
| [`openAIIntegration`](./openai) | ✓ | | ✓ | |
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,4 @@ Depending on whether an integration enhances the functionality of a particular r
| [`localVariablesIntegration`](./localvariables) | | ✓ | | |
| [`nodeProfilingIntegration`](./nodeprofiling) | | | ✓ | |
| [`trpcMiddleware`](./trpc) | | ✓ | ✓ | ✓ |
| [`openAIIntegration`](./openai) | ✓ | | ✓ | |
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,4 @@ Depending on whether an integration enhances the functionality of a particular r
| [`localVariablesIntegration`](./localvariables) | | ✓ | | |
| [`nodeProfilingIntegration`](./nodeprofiling) | | | ✓ | |
| [`trpcMiddleware`](./trpc) | | ✓ | ✓ | ✓ |
| [`openAIIntegration`](./openai) | ✓ | | ✓ | |
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,4 @@ Depending on whether an integration enhances the functionality of a particular r
| [`nodeProfilingIntegration`](./nodeprofiling) | | | ✓ | |
| [`supabaseIntegration`](./supabase) | | ✓ | ✓ | |
| [`trpcMiddleware`](./trpc) | | ✓ | ✓ | ✓ |
| [`openAIIntegration`](./openai) | ✓ | | ✓ | |