You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This feature is currently in beta while Vercel rolls out official telemetry support.
12
-
:::
13
-
14
-
You can use LangSmith to trace runs from the [Vercel AI SDK](https://sdk.vercel.ai/docs/introduction) using
15
-
the special `wrapAISDKModel` method. The important detail is that you must wrap the Vercel model wrapper
16
-
rather than of the top-level `generateText` or `generateStream` calls.
17
-
18
-
This guide will walk through an example.
13
+
You can use LangSmith to trace runs from the [Vercel AI SDK](https://sdk.vercel.ai/docs/introduction) with our built-in `AISDKExporter` OpenTelemetry trace exporter. This guide will walk through an example.
19
14
20
15
:::note
21
-
The `wrapAISDKModel` method is only available in `langsmith` JS SDK version `>=0.1.40`.
16
+
The `AISDKExporter` class is only available in `langsmith` JS SDK version `>=0.2.1`.
22
17
:::
23
18
24
-
###0. Installation
19
+
## 0. Installation
25
20
26
21
Install the Vercel AI SDK. We use their OpenAI integration for the code snippets below, but you can use any of their
27
22
other options as well.
@@ -33,71 +28,183 @@ other options as well.
33
28
value: "typescript",
34
29
label: "yarn",
35
30
language: "bash",
36
-
content: `yarn add ai @ai-sdk/openai`,
31
+
content: `yarn add ai @ai-sdk/openai zod`,
37
32
},
38
33
{
39
34
value: "npm",
40
35
label: "npm",
41
36
language: "bash",
42
-
content: `npm install ai @ai-sdk/openai`,
37
+
content: `npm install ai @ai-sdk/openai zod`,
43
38
},
44
39
{
45
40
value: "pnpm",
46
41
label: "pnpm",
47
42
language: "bash",
48
-
content: `pnpm add ai @ai-sdk/openai`,
43
+
content: `pnpm add ai @ai-sdk/openai zod`,
49
44
},
50
45
]}
51
46
/>
52
47
53
-
###1. Configure your environment
48
+
## 1. Configure your environment
54
49
55
50
<ConfigureSDKEnvironmentCodeTabs />
56
51
57
-
###2. Log a trace
52
+
## 2. Log a trace
58
53
59
-
Once you've set up your environment, wrap an initialized Vercel model as shown below:
54
+
### Next.js
55
+
56
+
First, create a `instrumentation.js` file in your project root. Learn more how to setup OpenTelemetry instrumentation within your Next.js app [here](https://nextjs.org/docs/app/api-reference/file-conventions/instrumentation).
57
+
58
+
```ts
59
+
import { registerOTel } from"@vercel/otel";
60
+
import { AISDKExporter } from"langsmith/vercel";
61
+
62
+
exportfunction register() {
63
+
registerOTel({
64
+
serviceName: "langsmith-vercel-ai-sdk-example",
65
+
// highlight-next-line
66
+
traceExporter: newAISDKExporter(),
67
+
});
68
+
}
69
+
```
70
+
71
+
Afterwards, add the `experimental_telemetry` argument to your AI SDK calls that you want to trace. For convenience, we've included the `AISDKExporter.getSettings()` method which appends additional metadata for LangSmith.
72
+
73
+
```ts
74
+
import { AISDKExporter } from"langsmith/vercel";
75
+
76
+
awaitstreamText({
77
+
model: openai("gpt-4o-mini"),
78
+
prompt: "Write a vegetarian lasagna recipe for 4 people.",
You can customize the run ID by passing the `runId` argument to the `AISDKExporter.getSettings()` method. This is especially useful if you want to know the run ID before the run has been completed.
146
+
147
+
```ts
148
+
import { AISDKExporter } from"langsmith/vercel";
149
+
150
+
awaitgenerateText({
151
+
model: openai("gpt-4o-mini"),
152
+
prompt: "Write a vegetarian lasagna recipe for 4 people.",
The `wrapAISDKModel` method is deprecated and will be removed in a future release.
193
+
:::
194
+
195
+
The `wrapAISDKModel` method wraps the Vercel model wrapper and intercept model invocation to send traces to LangSmith. This method is useful if you are using an older version of LangSmith or if you are using `streamUI` / Vercel AI RSC, which currently does not support `experimental_telemetry`.
0 commit comments