Skip to content

Commit 88fe26b

Browse files
committed
docs(ai): scope AI SDK 7 telemetry setup to the real behavior
AI SDK 7 auto-registration of @ai-sdk/otel only happens for chat agents, so plain tasks must register the OpenTelemetry integration themselves. Also note that chat agents auto-capture only when a prompt is set.
1 parent de558fe commit 88fe26b

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

docs/ai/observability.mdx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,16 @@ export const summarize = task({
3838
Trigger the task and open the run. The `generateText` call appears as a span in the trace. `streamText` and `generateObject` work the same way: add the same `experimental_telemetry` flag to each call you want captured.
3939

4040
<Note>
41-
On AI SDK 7, span emission moved out of the `ai` core into the `@ai-sdk/otel` adapter. Install `@ai-sdk/otel` and Trigger.dev registers it for you at run start. AI SDK 6 emits spans from `ai` directly, so no extra package is needed.
41+
**AI SDK 7** moved span emission out of `ai` core into the `@ai-sdk/otel` adapter. In a task, install `@ai-sdk/otel` and register it once yourself, for example at the top of your task file:
42+
43+
```ts /trigger/summarize.ts
44+
import { registerTelemetry } from "ai";
45+
import { OpenTelemetry } from "@ai-sdk/otel";
46+
47+
registerTelemetry(new OpenTelemetry());
48+
```
49+
50+
A [`chat.agent()`](/ai-chat/overview) run registers the adapter for you at run start, so chat agents need only the install. On AI SDK 5 and 6, `ai` core emits spans directly and no adapter is needed.
4251
</Note>
4352

4453
## What each span shows
@@ -101,7 +110,7 @@ const result = await generateText({
101110
Custom attributes are stored on the span's `metadata`, so you can filter or group by them in TRQL, for example `metadata['task.type']`.
102111

103112
<Note>
104-
When you build an agent with `chat.agent()`, `chat.toStreamTextOptions()` already sets `experimental_telemetry` for you, so generations inside a chat are captured without adding the flag by hand. See [Prompts](/ai/prompts#using-with-chatagent).
113+
When you build an agent with `chat.agent()` and store a prompt with `chat.prompt.set()`, `chat.toStreamTextOptions()` sets `experimental_telemetry` for you, so those generations are captured without adding the flag by hand. Without a stored prompt, set `experimental_telemetry` on the call yourself. See [Prompts](/ai/prompts#using-with-chatagent).
105114
</Note>
106115

107116
## Query usage across runs

0 commit comments

Comments
 (0)