Skip to content

Conversation

andreiborza
Copy link
Member

Adds support for OpenAI manual instrumentation in @sentry/cloudflare and @sentry/vercel-edge.

To instrument the OpenAI client, wrap it with Sentry.instrumentOpenAiClient and set recording settings.

import * as Sentry from '@sentry/cloudflare';
import OpenAI from 'openai';

const openai = new OpenAI();
const client = Sentry.instrumentOpenAiClient(openai, { recordInputs: true,
recordOutputs: true });

// use the wrapped client

To instrument the OpenAI client, wrap it with `Sentry.instrumentOpenAiClient`.

```js
import * as Sentry from '@sentry/cloudflare';
import OpenAI from 'openai';

const openai = new OpenAI();
const client = Sentry.instrumentOpenAiClient(openai, { recordInputs: true,
recordOutputs: true });

// use the wrapped client
```
instrumentation directly in cloudflare/vercel-edge
cursor[bot]

This comment was marked as outdated.

},
};

this.responses = {
Copy link
Member

Choose a reason for hiding this comment

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

if you're only testing client.chat?.completions?.create you can get rid of the rest of this file.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks, removed!

* Can be used across Node.js, Cloudflare Workers, and Vercel Edge
*/
export function instrumentOpenAiClient(client: OpenAiClient, options?: OpenAiOptions): OpenAiClient {
export function instrumentOpenAiClient<T extends object>(client: T, options?: OpenAiOptions): T {
Copy link
Member

Choose a reason for hiding this comment

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

🎉

cursor[bot]

This comment was marked as outdated.

@mydea
Copy link
Member

mydea commented Aug 6, 2025

is client the term they are using for this? It's a bit of an overloaded term for us, so if we could avoid the term here it would be nice imho 😅

@andreiborza
Copy link
Member Author

is client the term they are using for this? It's a bit of an overloaded term for us, so if we could avoid the term here it would be nice imho 😅

Yep: https://platform.openai.com/docs/libraries/typescript-javascript-library

Copy link
Member

@RulaKhaled RulaKhaled left a comment

Choose a reason for hiding this comment

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

For now we are removing the vercel edge export until we confirm this works as intended. @andreiborza confirmed it works

@andreiborza
Copy link
Member Author

For now we are removing the vercel edge export until we confirm this works as intended.

Actually, tested this again and it works on vercel-edge too.

@andreiborza andreiborza merged commit ed07836 into develop Aug 6, 2025
359 of 363 checks passed
@andreiborza andreiborza deleted the ab/cf-ve-openai branch August 6, 2025 15:18
RulaKhaled pushed a commit that referenced this pull request Aug 7, 2025
…17338)

Adds support for OpenAI manual instrumentation in `@sentry/cloudflare`
and `@sentry/vercel-edge`.

To instrument the OpenAI client, wrap it with
`Sentry.instrumentOpenAiClient` and set recording settings.

```js
import * as Sentry from '@sentry/cloudflare';
import OpenAI from 'openai';

const openai = new OpenAI();
const client = Sentry.instrumentOpenAiClient(openai, { recordInputs: true,
recordOutputs: true });

// use the wrapped client
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants