---
title: Send traces to Arize
description: "Six steps to agent traces in Arize AX or Phoenix, through OpenInference's span processor."
# The page ends with its own "Next" card; the sidebar neighbours would say something else.
pagination: false
sidebar:
  label: Arize
---

<RememberBackend name="Arize" />

:::note[Not run by us]
Written from Arize's docs, the `@arizeai/openinference-vercel` package (3.3.6) and Phoenix's source on 2026-11-25.
:::

Six steps, from the packages to one trace per turn in Arize: the same six on every backend's page. The framework
picker above the code picks your routes; the backend stays picked for the pages after this one.

<div class="install-steps">

## Install the packages

The telemetry layer and its OpenTelemetry packages, plus OpenInference's converter and the protobuf exporter: Arize reads OpenInference attributes, and `@arizeai/openinference-vercel` converts the AI SDK's spans to them (version 3 is for `ai@7`, whose `gen_ai.*` spans this library emits by default).

```package-install
npm install @webmcp-agents/telemetry @opentelemetry/api @opentelemetry/sdk-trace @ai-sdk/otel @arizeai/openinference-vercel @opentelemetry/exporter-trace-otlp-proto
```

## Set the environment

The example reads `ARIZE_SPACE_ID` and `ARIZE_API_KEY`. Arize AX and Phoenix differ in where and how:

**Arize AX**

- `https://otlp.arize.com/v1/traces` (EU: `https://otlp.eu-west-1a.arize.com/v1/traces`)
- `arize-space-id` and `arize-api-key` headers
- Protobuf in every example; JSON not stated

**Phoenix**

- `http://<host>:6006/v1/traces` (the UI's port); Phoenix Cloud: the hostname in Settings
- `Authorization: Bearer <PHOENIX_API_KEY>`
- Protobuf only: anything else gets `415`

Both file traces under the resource attribute `openinference.project.name`, which the layer sets in step 3.

## Add the server layer

OpenInference's span processor around a protobuf exporter, the project, and the key Arize groups a session by:

```ts title="lib/observability.ts"
import * as openinference from "@arizeai/openinference-vercel";
import * as proto from "@opentelemetry/exporter-trace-otlp-proto";
import { defineObservability } from "@webmcp-agents/telemetry/server";

// Arize AX. For Phoenix: url "http://localhost:6006/v1/traces"
// and an `authorization: Bearer <PHOENIX_API_KEY>` header.
const exporter = new proto.OTLPTraceExporter({
  url: "https://otlp.arize.com/v1/traces",
  headers: {
    "arize-space-id": process.env.ARIZE_SPACE_ID ?? "",
    "arize-api-key": process.env.ARIZE_API_KEY ?? "",
  },
});

export const observability = defineObservability({
  spanProcessors: [
    new openinference.OpenInferenceBatchSpanProcessor({
      exporter,
    }),
  ],
  // Arize files traces under this project.
  resourceAttributes: { "openinference.project.name": "field-store" },
  metadataMapping: { "webmcp.conversation.id": "session.id" },
});
```

In Astro, `process.env` does not hold `.env.local` in development: read the variables with `getSecret` from `astro:env/server` and pass them as `env`, as the Astro view of the [generic layer](/docs/observability/installation/otlp#add-the-server-layer) does. The chat route passes the layer to the handler:

**Vite**

```ts title="api/chat.ts" {3,6}
import { createChatHandler } from "@webmcp-agents/chat/server";

import { observability } from "../src/lib/observability";
import { agents } from "../src/agents";

const handler = createChatHandler({ agents, observability });

export const GET = handler;
export const POST = handler;
```

**Next.js**

```ts title="app/api/chat/route.ts" {4,6}
import { createChatHandler } from "@webmcp-agents/chat/server";

import { agents } from "@/agents";
import { observability } from "@/lib/observability";

const handler = createChatHandler({ agents, observability });

export const GET = handler;
export const POST = handler;
```

**TanStack Start**

```ts title="src/routes/api/chat.ts" {5,7}
import { createFileRoute } from "@tanstack/react-router";
import { createChatHandler } from "@webmcp-agents/chat/server";

import { agents } from "@/agents";
import { observability } from "@/lib/observability";

const handler = createChatHandler({ agents, observability });

export const Route = createFileRoute("/api/chat")({
  server: {
    handlers: {
      GET: ({ request }) => handler(request),
      POST: ({ request }) => handler(request),
    },
  },
});
```

**Astro**

```ts title="src/pages/api/chat.ts" {6,12}
import type { APIRoute } from "astro";
import { getSecret } from "astro:env/server";
import { createChatHandler } from "@webmcp-agents/chat/server";

import { agents } from "@/agents";
import { observability } from "@/lib/observability";

export const prerender = false;

const handler = createChatHandler({
  agents,
  observability,
  env: {
    ANTHROPIC_API_KEY: getSecret("ANTHROPIC_API_KEY"),
    WEB_AGENTS_MODEL: getSecret("WEB_AGENTS_MODEL"),
  },
});

export const GET: APIRoute = ({ request }) => handler(request);
export const POST: APIRoute = ({ request }) => handler(request);
```

## Add the relay route

The page's spans come to your own endpoint, so the backend's key never reaches the browser. The relay refuses other origins and requests with no `Origin` (a script, not a page); the `guard` is the per-IP limit for the rest. Keep its counts in a shared store in production, as for the chat ([Limits and budgets](/docs/security/limits)).

**Vite**

```ts title="api/telemetry.ts"
import { observability } from "../src/lib/observability";

// The page's spans arrive here. The relay checks and redacts them,
// then sends them where the server's spans go. It refuses a request
// from another origin, or with no Origin at all (a script, not a page).

// Everything it accepts reaches your backend, so limit each visitor.
// Here in memory, per instance; in production count in a shared store
// (Upstash, Redis), as for the chat: see Limits and budgets.
const seen = new Map<string, { since: number; count: number }>();
const perIp = (req: Request) => {
  const who = req.headers.get("x-forwarded-for") ?? "local";
  const now = Date.now();
  const last = seen.get(who);
  const entry =
    last && now - last.since < 60_000 ? last : { since: now, count: 0 };
  entry.count++;
  seen.set(who, entry);
  // about one batch per run: 60 a minute is plenty for a person
  if (entry.count <= 60) return undefined;
  return new Response(null, { status: 429 });
};

export const POST = observability.relay({ guard: perIp });
```

**Next.js**

```ts title="app/api/telemetry/route.ts"
import { observability } from "@/lib/observability";

// The page's spans arrive here. The relay checks and redacts them,
// then sends them where the server's spans go. It refuses a request
// from another origin, or with no Origin at all (a script, not a page).

// Everything it accepts reaches your backend, so limit each visitor.
// Here in memory, per instance; in production count in a shared store
// (Upstash, Redis), as for the chat: see Limits and budgets.
const seen = new Map<string, { since: number; count: number }>();
const perIp = (req: Request) => {
  const who = req.headers.get("x-forwarded-for") ?? "local";
  const now = Date.now();
  const last = seen.get(who);
  const entry =
    last && now - last.since < 60_000 ? last : { since: now, count: 0 };
  entry.count++;
  seen.set(who, entry);
  // about one batch per run: 60 a minute is plenty for a person
  if (entry.count <= 60) return undefined;
  return new Response(null, { status: 429 });
};

export const POST = observability.relay({ guard: perIp });
```

**TanStack Start**

```ts title="src/routes/api/telemetry.ts"
import { createFileRoute } from "@tanstack/react-router";

import { observability } from "@/lib/observability";

// The page's spans arrive here. The relay checks and redacts them,
// then sends them where the server's spans go. It refuses a request
// from another origin, or with no Origin at all (a script, not a page).

// Everything it accepts reaches your backend, so limit each visitor.
// Here in memory, per instance; in production count in a shared store
// (Upstash, Redis), as for the chat: see Limits and budgets.
const seen = new Map<string, { since: number; count: number }>();
const perIp = (req: Request) => {
  const who = req.headers.get("x-forwarded-for") ?? "local";
  const now = Date.now();
  const last = seen.get(who);
  const entry =
    last && now - last.since < 60_000 ? last : { since: now, count: 0 };
  entry.count++;
  seen.set(who, entry);
  // about one batch per run: 60 a minute is plenty for a person
  if (entry.count <= 60) return undefined;
  return new Response(null, { status: 429 });
};

const relay = observability.relay({ guard: perIp });

export const Route = createFileRoute("/api/telemetry")({
  server: {
    handlers: {
      POST: ({ request }) => relay(request),
    },
  },
});
```

**Astro**

```ts title="src/pages/api/telemetry.ts"
import type { APIRoute } from "astro";

import { observability } from "@/lib/observability";

export const prerender = false;

// The page's spans arrive here. The relay checks and redacts them,
// then sends them where the server's spans go. It refuses a request
// from another origin, or with no Origin at all (a script, not a page).

// Everything it accepts reaches your backend, so limit each visitor.
// Here in memory, per instance; in production count in a shared store
// (Upstash, Redis), as for the chat: see Limits and budgets.
const seen = new Map<string, { since: number; count: number }>();
const perIp = (req: Request) => {
  const who = req.headers.get("x-forwarded-for") ?? "local";
  const now = Date.now();
  const last = seen.get(who);
  const entry =
    last && now - last.since < 60_000 ? last : { since: now, count: 0 };
  entry.count++;
  seen.set(who, entry);
  // about one batch per run: 60 a minute is plenty for a person
  if (entry.count <= 60) return undefined;
  return new Response(null, { status: 429 });
};

const relay = observability.relay({ guard: perIp });

export const POST: APIRoute = ({ request }) => relay(request);
```

## Observe the page

One component turns each run and tool call on the page into spans and posts them to the relay. Render it once, inside `<WebAgentsProvider>`, next to the chat. Without React, call [`observeAgents()`](/docs/observability/observe-agents) once instead.

**Vite**

```tsx title="src/components/observe-runs.tsx"
import { ObserveAgents } from "@webmcp-agents/telemetry/react";

import { consent } from "@/lib/consent";

// Render it once, inside <WebAgentsProvider>. Each run the person
// agreed to becomes spans, posted to /api/telemetry.
export function ObserveRuns() {
  return <ObserveAgents enabled={() => consent.analytics} />;
}
```

**Next.js**

```tsx title="components/observe-runs.tsx"
"use client";

import { ObserveAgents } from "@webmcp-agents/telemetry/react";

import { consent } from "@/lib/consent";

// Render it once, inside <WebAgentsProvider>. Each run the person
// agreed to becomes spans, posted to /api/telemetry.
export function ObserveRuns() {
  return <ObserveAgents enabled={() => consent.analytics} />;
}
```

**TanStack Start**

```tsx title="src/components/observe-runs.tsx"
import { ObserveAgents } from "@webmcp-agents/telemetry/react";

import { consent } from "@/lib/consent";

// Render it once, inside <WebAgentsProvider>. Each run the person
// agreed to becomes spans, posted to /api/telemetry.
export function ObserveRuns() {
  return <ObserveAgents enabled={() => consent.analytics} />;
}
```

**Astro**

```tsx title="src/components/observe-runs.tsx"
import { ObserveAgents } from "@webmcp-agents/telemetry/react";

import { consent } from "@/lib/consent";

// Render it once, inside <WebAgentsProvider>. Each run the person
// agreed to becomes spans, posted to /api/telemetry.
export function ObserveRuns() {
  return <ObserveAgents enabled={() => consent.analytics} />;
}
```

## Check it in Arize

Start the app and send one message in the chat. The trace appears under the project the layer names (`field-store`). Arize AX and Phoenix both group sessions by `session.id`, which the layer maps from the conversation id.

![Phoenix's trace view: invoke_agent shopper selected, its span tree with two chat steps and execute_tool get_cart, and its attributes](/blume-assets/content/_/ce1b5abba9f58607.png)

*A real trace from Field Store on Next.js in a local Phoenix, captured with `pnpm capture:backend phoenix`. It reached Phoenix
through a Collector, as plain OTLP, not through the OpenInference processor of step 3; the model was a scripted
stand-in.*

</div>

**Sources, and what was not confirmed**

- [Configure your tracer (AX)](https://arize.com/docs/ax/instrument/configure-your-tracer.md): endpoint, headers, project
- [Vercel AI SDK tracing (AX)](https://arize.com/docs/ax/integrations/ts-js-agent-frameworks/vercel/vercel-ai-sdk-tracing.md)
- [Vercel AI SDK tracing (Phoenix)](https://www.arize.com/docs/phoenix/integrations/typescript/vercel/vercel-ai-sdk-tracing-js.md)
- [Phoenix sessions](https://arize.com/docs/phoenix/tracing/how-to-tracing/setup-tracing/setup-sessions): `session.id`
- [Phoenix's OTLP route](https://github.com/Arize-ai/phoenix/blob/main/src/phoenix/server/api/routers/v1/traces.py): protobuf only

Not confirmed: OTLP JSON on AX.

## Next

**[The telemetry APIs](/docs/observability/apis?backend=arize)**

What you just set up, one API per page: the layer, where spans go, the relay, the page's observer, sampling and
the conversation key, each showing what differs for Arize.
