Skip to content

Commit 5e437a9

Browse files
committed
also export from vercel edge
1 parent 12e2246 commit 5e437a9

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

packages/vercel-edge/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,5 +98,6 @@ export { VercelEdgeClient } from './client';
9898
export { getDefaultIntegrations, init } from './sdk';
9999

100100
export { winterCGFetchIntegration } from './integrations/wintercg-fetch';
101+
export { vercelAIIntegration } from './integrations/tracing/vercelai';
101102

102103
export * as logger from './logs/exports';
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/**
2+
* This is a copy of the Vercel AI integration from the node SDK.
3+
*
4+
* The only difference is that it does not use `@opentelemetry/instrumentation`
5+
* because Cloudflare Workers do not support it.
6+
*
7+
* Therefore, we cannot automatically patch setting `experimental_telemetry: { isEnabled: true }`
8+
* and users have to manually set this to get spans.
9+
*/
10+
11+
import type { IntegrationFn } from '@sentry/core';
12+
import { addVercelAiProcessors, defineIntegration } from '@sentry/core';
13+
14+
const INTEGRATION_NAME = 'VercelAI';
15+
16+
const _vercelAIIntegration = (() => {
17+
return {
18+
name: INTEGRATION_NAME,
19+
setup(client) {
20+
addVercelAiProcessors(client);
21+
},
22+
};
23+
}) satisfies IntegrationFn;
24+
25+
/**
26+
* Adds Sentry tracing instrumentation for the [ai](https://www.npmjs.com/package/ai) library.
27+
* This integration is not enabled by default, you need to manually add it.
28+
*
29+
* For more information, see the [`ai` documentation](https://sdk.vercel.ai/docs/ai-sdk-core/telemetry).
30+
*
31+
* You need to enable collecting spans for a specific call by setting
32+
* `experimental_telemetry.isEnabled` to `true` in the first argument of the function call.
33+
*
34+
* ```javascript
35+
* const result = await generateText({
36+
* model: openai('gpt-4-turbo'),
37+
* experimental_telemetry: { isEnabled: true },
38+
* });
39+
* ```
40+
*
41+
* If you want to collect inputs and outputs for a specific call, you must specifically opt-in to each
42+
* function call by setting `experimental_telemetry.recordInputs` and `experimental_telemetry.recordOutputs`
43+
* to `true`.
44+
*
45+
* ```javascript
46+
* const result = await generateText({
47+
* model: openai('gpt-4-turbo'),
48+
* experimental_telemetry: { isEnabled: true, recordInputs: true, recordOutputs: true },
49+
* });
50+
*/
51+
export const vercelAIIntegration = defineIntegration(_vercelAIIntegration);

0 commit comments

Comments
 (0)