---
title: Send traces to IBM Instana
description: "Six steps to agent traces in IBM Instana and its GenAI views, agentless or through the host agent."
# The page ends with its own "Next" card; the sidebar neighbours would say something else.
pagination: false
sidebar:
  label: IBM Instana
---

<RememberBackend name="IBM Instana" />

:::note[Not run by us]
No Instana tenant and no host agent. Written from IBM's Instana docs on 2026-11-25. The generic path it uses (`http/protobuf` with headers from the environment, resource attributes) was run against a local Collector.
:::

Six steps, from the packages to one trace per turn in IBM Instana: 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 the protobuf exporter: IBM's docs do not say whether OTLP JSON is accepted, so this setup sends protobuf. There is no Instana code, type or package in this library.

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

## Set the environment

**Agentless**

Straight to the Instana backend's OTLP acceptor:

**`.env`**

```bash title=".env"
# Instana agentless. REGION: blue, red, green, orange, coral, teal,
# mizu or pumpkin, as your tenant's URL says.
OTEL_EXPORTER_OTLP_ENDPOINT=https://otlp-http-REGION-saas.instana.io:443
OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf
OTEL_EXPORTER_OTLP_HEADERS=x-instana-key=<agent key>,x-instana-host=field-store
OTEL_SERVICE_NAME=field-store
OTEL_RESOURCE_ATTRIBUTES=INSTANA_PLUGIN=genai
```

**Through the host agent**

The agent's own OTLP receiver (4318 for HTTP, 4317 for gRPC) holds the key. In Kubernetes its service is `instana-agent` in the namespace `instana-agent`; the Helm chart and the Operator turn OTLP ingestion on by default.

**`.env`**

```bash title=".env"
# Instana host agent: its own OTLP receiver; the agent holds the key.
# In Kubernetes: http://instana-agent.instana-agent:4318
OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318
OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf
OTEL_SERVICE_NAME=field-store
OTEL_RESOURCE_ATTRIBUTES=INSTANA_PLUGIN=genai
```

**Endpoint forms**

The current SaaS table lists `https://otlp-http-<region>-saas.instana.io:443` (and `otlp-grpc-<region>-saas.instana.io:443`) for the regions blue, red, green, orange, coral, teal, mizu and pumpkin. The same page's examples also use `https://otlp-<region>-saas.instana.io:4318`. Self-hosted Instana uses `otlp-http.<base domain>` on 443.

**Identity**

Agentless data must be tied to an entity: the `x-instana-key` header (the agent key) plus a `host.id`, `faas.id` or `device.id` resource attribute, or else the `x-instana-host` header. IBM's page is not consistent on whether `host.name` also counts. On serverless hosts set one explicitly, as both examples do.

**On an edge runtime**

Where the protobuf package does not load, send to a Collector or to the host agent instead.

## Add the server layer

The layer reads the environment from step 2.

**Vite**

```ts title="src/lib/observability.ts"
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",
});
```

**Next.js**

```ts title="lib/observability.ts"
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",
});
```

**TanStack Start**

```ts title="src/lib/observability.ts"
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",
});
```

**Astro**

```ts title="src/lib/observability.ts"
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:

**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);
```

**Written out in code**

The agentless setup without the environment:

```ts title="lib/observability.ts"
import {
  defineObservability,
  otlp,
} from "@webmcp-agents/telemetry/server";

// Instana agentless, written out. REGION is your tenant's region.
const region = process.env.INSTANA_REGION ?? "blue";

export const observability = defineObservability({
  exporters: [
    otlp({
      endpoint: `https://otlp-http-${region}-saas.instana.io:443`,
      protocol: "http/protobuf",
      headers: { "x-instana-key": process.env.INSTANA_AGENT_KEY ?? "" },
    }),
  ],
  resourceAttributes: {
    // An identity Instana ties the data to (here: the function).
    "faas.id": process.env.VERCEL_URL ?? "field-store",
    // Shows the traces in Instana's GenAI views.
    INSTANA_PLUGIN: "genai",
  },
});
```

## 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 IBM Instana

Start the app and send one message in the chat. Instana's GenAI views are built on OpenLLMetry and need the resource attribute `INSTANA_PLUGIN=genai`, which both examples set; they read `gen_ai.*` attributes, so keep the default `conventions: "genai"`. A `403` usually means a host for another region than your tenant's; data that is accepted but never shows up is the usual sign of a missing identity. Instana's own website monitoring (EUM) is separate and can run beside the relay.

</div>

**Sources, and what was not confirmed**

- [Sending OpenTelemetry data to the Instana backend](https://www.ibm.com/docs/en/instana-observability/saas?topic=instana-backend): endpoints, regions, headers, identity
- [IBM Community: OTLP 403 on /v1/traces](https://community.ibm.com/community/user/discussion/otlp-error-403-forbidden-v1traces)

Not confirmed: OTLP JSON acceptance; what happens without an identity; which attributes each GenAI view reads (if one stays empty, map what it needs in a Collector `transform` processor rather than in the app).

## Next

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

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 IBM Instana.
