Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
44 changes: 31 additions & 13 deletions docs/ai/monitoring/agents/naming.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ Sentry uses the `gen_ai.agent.name` span attribute to identify agents in the [AI

## Quick Reference

| Framework | Platform | How to Name |
| ----------------------- | -------- | ------------------------------------------------------------------ |
| OpenAI Agents SDK | Python | `Agent(name="...")` |
| Pydantic AI | Python | `Agent(..., name="...")` |
| LangChain | Python | `create_agent(model, tools, name="...")` |
| LangGraph | Python | `.compile(name="...")` or `create_react_agent(..., name="...")` |
| Vercel AI SDK | JS | `experimental_telemetry: { functionId: "..." }` |
| LangGraph | JS | `.compile({ name: "..." })` or `createReactAgent({ name: "..." })` |
| LangChain | JS | `createAgent({ name: "..." })` |
| Mastra | JS | `Agent({ id: "...", name: "..." })` |
| .NET (M.E.AI) | .NET | `options.Experimental.AgentName = "..."` |
| Other / raw LLM clients | Any | [Manual instrumentation](#manual-instrumentation) |
| Framework | Platform | How to Name |
| ----------------------- | -------- | ------------------------------------------------------------------------------------ |
| OpenAI Agents SDK | Python | `Agent(name="...")` |
| Pydantic AI | Python | `Agent(..., name="...")` |
| LangChain | Python | `create_agent(model, tools, name="...")` |
| LangGraph | Python | `.compile(name="...")` or `create_react_agent(..., name="...")` |
| Vercel AI SDK | JS | `experimental_telemetry: { functionId: "..." }` on `generateText` or `ToolLoopAgent` |
| LangGraph | JS | `.compile({ name: "..." })` or `createReactAgent({ name: "..." })` |
| LangChain | JS | `createAgent({ name: "..." })` |
| Mastra | JS | `Agent({ id: "...", name: "..." })` |
| .NET (M.E.AI) | .NET | `options.Experimental.AgentName = "..."` |
| Other / raw LLM clients | Any | [Manual instrumentation](#manual-instrumentation) |

## Framework Integrations

Expand Down Expand Up @@ -113,7 +113,7 @@ agent = create_react_agent(model, tools, name="dice_agent")

#### Vercel AI SDK

Vercel AI SDK doesn't have a dedicated agent name field. Instead, set `functionId` in `experimental_telemetry` — Sentry uses this as the agent identifier.
Set `functionId` in `experimental_telemetry` — Sentry uses this as the agent identifier. This works for both `generateText` and `ToolLoopAgent`:

```javascript
import { generateText } from "ai";
Expand All @@ -129,6 +129,24 @@ const result = await generateText({
});
```

For the `ToolLoopAgent` class, set `functionId` in the constructor:

```javascript
import { ToolLoopAgent } from "ai";
import { openai } from "@ai-sdk/openai";

const agent = new ToolLoopAgent({
model: openai("gpt-4o"),
tools: {
/* ... */
},
experimental_telemetry: {
isEnabled: true,
functionId: "weather_agent",
},
});
```

<PlatformLink
platform="javascript.node"
to="/configuration/integrations/vercelai/"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ Sentry.init({
</PlatformSection>

<PlatformSection supported={['javascript.cloudflare', 'javascript.nextjs']}>
To correctly capture spans, pass the `experimental_telemetry` object with `isEnabled: true` to every `generateText`, `generateObject`, and `streamText` function call. For more details, see the [AI SDK Telemetry Metadata docs](https://sdk.vercel.ai/docs/ai-sdk-core/telemetry#telemetry-metadata).
To correctly capture spans, pass the `experimental_telemetry` object with `isEnabled: true` to every `generateText`, `generateObject`, `streamText`, and `ToolLoopAgent` call. For more details, see the [AI SDK Telemetry Metadata docs](https://sdk.vercel.ai/docs/ai-sdk-core/telemetry#telemetry-metadata).

```javascript
const result = await generateText({
Expand Down Expand Up @@ -160,6 +160,34 @@ Sentry.init({

</PlatformSection>

## ToolLoopAgent

The integration also captures spans for the [`ToolLoopAgent`](https://ai-sdk.dev/docs/agents/overview#toolloopagent-class) class. Each call to `generate()` or `stream()` creates an agent span with individual LLM requests and tool executions as child spans.

<PlatformSection notSupported={["javascript.cloudflare", "javascript.nextjs"]}>

No additional configuration is needed — `ToolLoopAgent` spans are captured automatically.

</PlatformSection>

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

Pass `experimental_telemetry` with `isEnabled: true` to the `ToolLoopAgent` constructor to correctly capture spans:

</PlatformSection>

```javascript
const agent = new ToolLoopAgent({
model: openai("gpt-4o"),
tools: { /* ... */ },
experimental_telemetry: { isEnabled: true },
});

const result = await agent.generate({
prompt: "What is the weather in San Francisco?",
});
```

## Identifying functions

In order to make it easier to correlate captured spans with the function calls we recommend setting `functionId` in `experimental_telemetry` in all generation function calls:
Expand All @@ -174,6 +202,19 @@ const result = await generateText({
});
```

For `ToolLoopAgent`, set `functionId` in the constructor:

```javascript
const agent = new ToolLoopAgent({
model: openai("gpt-4o"),
tools: { /* ... */ },
experimental_telemetry: {
isEnabled: true,
functionId: "weather-agent",
},
});
```

## Configuration

By default this integration adds tracing support to all `ai` function callsites. If you need to disable span collection for a specific call, you can do so by setting `experimental_telemetry.isEnabled` to `false` in the first argument of the function call.
Expand Down
Loading