> ## Documentation Index
> Fetch the complete documentation index at: https://docs.agnost.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Trigger.dev

> Capture AI agent tasks running on Trigger.dev with a custom OTLP exporter

## Choose a setup method

| Method | Use it when |
| - | - |
| **Agnost AI skill** | You want your coding agent to inspect the app, make the change, and verify it. |
| **Agnost AI SDK** | You want explicit control over the interaction boundaries and fields. |
| **OpenTelemetry** | The framework already emits useful spans or you operate an OTel pipeline. |

Start with one method for a call path. Combining SDK tracking with framework
OpenTelemetry on the same call can create duplicate interactions.

## Recommended: Agnost AI skill

> [!NOTE]
>
> **Recommended.** Choose this path when you want your coding agent to inspect the
> project, select a supported transport, make the smallest instrumentation change,
> send a test event, and verify that it reached Agnost AI.

Install the skill once in your coding-agent environment:

```bash theme={null}
npx skills add AgnostAI/skills --skill agnost-ai
```

Run the framework-specific prompt below from the application root. Review the
resulting diff before deploying it.

```text theme={null}
Use the agnost-ai skill to add Agnost AI analytics to this Trigger.dev project.
Org ID: your-org-id
Instrument the real task that calls the Vercel AI SDK and verify one fresh run.
```

## Manual setup: Agnost AI SDK

Use the SDK when a task calls a model through anything other than the Vercel AI
SDK, or when you want one Agnost AI event per task run.

```bash theme={null}
npm install agnostai
```

```typescript theme={null}
// src/trigger/support.ts
import { task } from "@trigger.dev/sdk";
import { anthropic } from "@ai-sdk/anthropic";
import { generateText } from "ai";
import * as agnost from "agnostai";

agnost.init(process.env.AGNOST_ORG_ID!);

export const supportAgent = task({
  id: "support-agent",
  run: async (payload: { userId: string; conversationId: string; message: string }) => {
    const interaction = agnost.begin({
      userId: payload.userId,
      agentName: "trigger-support",
      input: payload.message,
      conversationId: payload.conversationId,
    });
    if (!interaction) throw new Error("Agnost is not initialized. Call agnost.init() first.");
    try {
      const { text } = await generateText({
        model: anthropic("claude-haiku-4-5"),
        prompt: payload.message,
      });
      interaction.end(text);
      return { reply: text };
    } catch (error) {
      interaction.end(String(error), false);
      throw error;
    } finally {
      await agnost.flush();
    }
  },
});
```

`await agnost.flush()` sends the event before the run returns. Trigger.dev can
pause, checkpoint, or reuse the worker process after a run, so do not rely on a
later flush. Do not call `agnost.shutdown()` inside `run`: a reused worker would
stop sending events for later runs. Set `AGNOST_ORG_ID` in your Trigger.dev
project's environment variables.

## Manual setup: OpenTelemetry

Trigger.dev runs every task inside its own OpenTelemetry tracer. Add an OTLP
exporter to `telemetry.exporters` in `trigger.config.ts` and Trigger.dev sends a
copy of every run's spans to Agnost AI. The Vercel AI SDK spans inside a task
(model calls, agent steps, and tool calls) carry GenAI attributes, so Agnost AI
turns them into events. Trigger.dev's own run and attempt spans are not
ingested.

### 1. Install

```bash theme={null}
npm install ai @ai-sdk/otel @opentelemetry/exporter-trace-otlp-proto@0.219.0
```

Match the exporter to the OpenTelemetry release your `@trigger.dev/sdk` uses.
`@trigger.dev/sdk` 4.8 pins `@opentelemetry/api` 1.9.1 and the 0.219 exporters.
The newest exporters need `@opentelemetry/api` 1.10 and fail to install next to
it. To check your version, run `npm ls @opentelemetry/exporter-trace-otlp-http`
and use the same number for `@opentelemetry/exporter-trace-otlp-proto`.

Skip `@ai-sdk/otel` on AI SDK 5 or 6.

### 2. Add the Agnost AI exporter to `trigger.config.ts`

```typescript theme={null}
import { defineConfig } from "@trigger.dev/sdk";
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-proto";

export default defineConfig({
  project: "<project ref>",
  dirs: ["./src/trigger"],
  maxDuration: 300,
  telemetry: {
    exporters: [
      new OTLPTraceExporter({
        url: "https://otel.agnost.ai/v1/traces",
        headers: { "X-Agnost-Org-ID": process.env.AGNOST_ORG_ID! },
      }),
    ],
  },
});
```

**Already exporting to another backend?** Add the Agnost AI exporter to the
existing `exporters` array. Trigger.dev sends spans to every exporter in the list.

Pass the exporter options in the constructor. Trigger.dev does not support
configuring exporters with `OTEL_*` environment variables, because they conflict
with its internal telemetry.

### 3. Trace AI SDK calls with user and session IDs

AI SDK 7 emits spans only through the `@ai-sdk/otel` adapter. Register it once
at the top of the task file, then pass the user and conversation IDs as runtime
context:

```typescript theme={null}
// src/trigger/support.ts
import { task } from "@trigger.dev/sdk";
import { anthropic } from "@ai-sdk/anthropic";
import { OpenTelemetry } from "@ai-sdk/otel";
import { generateText, registerTelemetry, stepCountIs, tool } from "ai";
import { z } from "zod";

registerTelemetry(new OpenTelemetry({ runtimeContext: true }));

export const supportAgent = task({
  id: "support-agent",
  run: async (payload: { userId: string; conversationId: string; message: string }) => {
    const result = await generateText({
      model: anthropic("claude-haiku-4-5"),
      prompt: payload.message,
      tools: {
        getOrderStatus: tool({
          description: "Look up the status of an order",
          inputSchema: z.object({ orderId: z.string() }),
          execute: async ({ orderId }) => ({ orderId, status: "shipped" }),
        }),
      },
      stopWhen: stepCountIs(3),
      runtimeContext: {
        userId: payload.userId,
        sessionId: payload.conversationId,
      },
      telemetry: {
        isEnabled: true,
        includeRuntimeContext: { userId: true, sessionId: true },
      },
    });

    return { reply: result.text };
  },
});
```

AI SDK 7 leaves runtime context out of spans unless each field is listed in
`includeRuntimeContext`. Keep secrets out of that list.

**On AI SDK 5 or 6**, `ai` emits the spans itself. Do not register
`@ai-sdk/otel`. Pass the IDs as telemetry metadata instead:

```typescript theme={null}
experimental_telemetry: {
  isEnabled: true,
  metadata: { userId: payload.userId, sessionId: payload.conversationId },
},
```

### What appears in Agnost AI

* **Conversations** grouped by `sessionId`. Runs that share a `sessionId` land in
  one conversation.
* **User-level analytics** grouped by `userId`.
* **Events** for each AI SDK agent call, agent step, and model call, plus one tool
  event per tool call with its arguments and result.

### Verify

Trigger one run of the task from the Trigger.dev dashboard or with
`tasks.trigger("support-agent", payload)`. Then open **Events** in Agnost AI and
confirm the model and tool events arrived with your user ID. Open
**Conversations** and confirm the run is grouped under the `conversationId` you
passed.

### Troubleshooting

* **No events, but the run trace shows AI spans:** confirm the exporter is in
  `telemetry.exporters` and `AGNOST_ORG_ID` is set in the Trigger.dev
  environment the task runs in (dev, staging, or prod).
* **No AI spans anywhere:** on AI SDK 7, confirm `registerTelemetry(new
  OpenTelemetry(...))` runs in a file the task imports. On AI SDK 5 or 6, confirm
  `experimental_telemetry.isEnabled` is `true`.
* **Events arrive without a user or conversation:** on AI SDK 7, list `userId`
  and `sessionId` in `includeRuntimeContext` and create the adapter with
  `runtimeContext: true`.
* **`npm install` fails with an `@opentelemetry/api` peer conflict:** install the
  exporter version that matches `@trigger.dev/sdk` (see step 1).
* Use `@opentelemetry/exporter-trace-otlp-proto` with the full
  `/v1/traces` URL.
* Model calls made with a provider's own SDK or raw `fetch` produce no AI spans.
  Use the Agnost AI SDK path for those tasks.

### References

* [Trigger.dev telemetry exporters](https://trigger.dev/docs/config/config-file#telemetry-exporters)
* [Trigger.dev LLM observability](https://trigger.dev/docs/ai/observability)
* [Vercel AI SDK telemetry](https://ai-sdk.dev/docs/ai-sdk-core/telemetry)

## Next steps

* [Conversations](https://docs.agnost.ai/using-conversations.md): review the complete Trigger.dev run.
* [Events](https://docs.agnost.ai/using-events.md): inspect model, step, and tool events from each run.
* [Patterns](https://docs.agnost.ai/using-patterns.md): organize production conversations by what users wanted.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.