Send traces to any OTLP backend
Six steps to one trace per turn in any backend that accepts OTLP: Grafana, Honeycomb, SigNoz, Axiom, Jaeger or your own Collector.
Six steps, from the packages to one trace per turn in Any OTLP backend: 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.
Install the packages
The telemetry layer, and the three OpenTelemetry packages it loads on the server’s first request; the page needs none of them. For a backend that wants protobuf (Grafana beyond testing, SigNoz), add @opentelemetry/exporter-trace-otlp-proto and set OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf.
npm install @webmcp-agents/telemetry @opentelemetry/api @opentelemetry/sdk-trace @ai-sdk/otelpnpm add @webmcp-agents/telemetry @opentelemetry/api @opentelemetry/sdk-trace @ai-sdk/otelyarn add @webmcp-agents/telemetry @opentelemetry/api @opentelemetry/sdk-trace @ai-sdk/otelbun add @webmcp-agents/telemetry @opentelemetry/api @opentelemetry/sdk-trace @ai-sdk/otelnub add @webmcp-agents/telemetry @opentelemetry/api @opentelemetry/sdk-trace @ai-sdk/otelaube add @webmcp-agents/telemetry @opentelemetry/api @opentelemetry/sdk-trace @ai-sdk/otelSet the environment
Where spans go is the standard OpenTelemetry environment: the backend’s URL and its auth header. To try it on your machine first, run a Collector that prints what it receives (the Collector page has the file and the command):
# A Collector on this machine (docker run … otel/opentelemetry-collector)
OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318
OTEL_SERVICE_NAME=field-storeFor a hosted backend, its URL and header instead. Honeycomb, for example:
# Honeycomb (US; EU: https://api.eu1.honeycomb.io)
OTEL_EXPORTER_OTLP_ENDPOINT=https://api.honeycomb.io
OTEL_EXPORTER_OTLP_HEADERS=x-honeycomb-team=<API_KEY>
OTEL_SERVICE_NAME=field-storeHeader values are percent-encoded: a space is %20 (authorization=Bearer%20<key>).
Grafana Cloud
- Endpoint:
https://otlp-gateway-<zone>.grafana.net/otlp - Auth: Basic auth, as the OTLP tile of your stack shows it
- JSON: accepted; Grafana recommends protobuf beyond testing
Honeycomb
- Endpoint:
https://api.honeycomb.io(EUhttps://api.eu1.honeycomb.io) - Auth:
x-honeycomb-team: <key> - JSON: accepted
SigNoz Cloud
- Endpoint:
https://ingest.<region>.signoz.cloud:443 - Auth:
signoz-ingestion-key: <key> - JSON: not stated, so use protobuf
Axiom
- Endpoint:
https://<your Axiom domain>/v1/traces, the exact traces URL - Auth:
Authorization: Bearer <token>andX-Axiom-Dataset: <dataset> - JSON: accepted
Jaeger, or your own Collector
- Endpoint:
http://<host>:4318 - Auth: none for Jaeger; as you configure it for a Collector
- JSON: accepted
Add the server layer
The layer names no backend: it reads the environment from step 2. With no variable set it is off and costs nothing.
import { defineObservability } from "@webmcp-agents/telemetry/server";
// One layer for the server: the chat handler exports each model
// step, the relay forwards the page's spans. Where spans go is the
// standard OTEL_* environment (or nothing: then it is off).
export const observability = defineObservability({
serviceName: "field-store",
});import { defineObservability } from "@webmcp-agents/telemetry/server";
// One layer for the server: the chat handler exports each model
// step, the relay forwards the page's spans. Where spans go is the
// standard OTEL_* environment (or nothing: then it is off).
export const observability = defineObservability({
serviceName: "field-store",
});import { defineObservability } from "@webmcp-agents/telemetry/server";
// One layer for the server: the chat handler exports each model
// step, the relay forwards the page's spans. Where spans go is the
// standard OTEL_* environment (or nothing: then it is off).
export const observability = defineObservability({
serviceName: "field-store",
});import { getSecret } from "astro:env/server";
import { defineObservability } from "@webmcp-agents/telemetry/server";
// One layer for the server. getSecret reads .env.local in
// development and the server's environment in production.
export const observability = defineObservability({
serviceName: "field-store",
env: {
OTEL_EXPORTER_OTLP_ENDPOINT: getSecret(
"OTEL_EXPORTER_OTLP_ENDPOINT",
),
OTEL_EXPORTER_OTLP_HEADERS: getSecret("OTEL_EXPORTER_OTLP_HEADERS"),
},
});The chat route passes the layer to the handler:
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;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;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),
},
},
});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).
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 });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 });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),
},
},
});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() once instead.
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} />;
}"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} />;
}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} />;
}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 Any OTLP backend
Start the app and send one message in the chat. The backend shows one trace for the turn: the run (invoke_agent), its tool calls (execute_tool) and its model steps (chat). Every span carries webmcp.conversation.id: group or filter a conversation by it, or map it to your backend’s own key with metadataMapping.
In Jaeger, the turn is one trace: the run, its two model steps and the tool call, with the model step’s provider, model and tokens on Jaeger’s GenAI tab.

The same trace in Grafana’s Tempo, from the all-in-one grafana/otel-lgtm image:

Real traces from Field Store on Next.js, captured locally in Docker with pnpm capture:backend jaeger and pnpm capture:backend lgtm; the model was a
scripted stand-in, so no key was needed.
Sources, and what was not confirmed
- OTLP exporter configuration: the variables, the
/v1/tracesrule, the header format - Grafana Cloud OTLP
- Grafana’s format considerations
- Honeycomb
- SigNoz Cloud
- Axiom
Next
The telemetry APIs
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 Any OTLP backend.