Skip to content
WebMCP Agents
Esc
↑↓navigate↵open⌘Jpreview
On this page

otlp

One OTLP destination in code for defineObservability's exporters: a base or exact URL, a protocol, headers and a timeout.

otlp() describes one OTLP destination for defineObservability’s exporters. You need it only when the environment is not enough: a second destination, a URL with a tenant in its path, or values that come from your own config. For a single backend, the OTEL_EXPORTER_OTLP_* variables describe the same thing with no code.

Import

import { otlp } from "@webmcp-agents/telemetry/server";
import type { OtlpTarget } from "@webmcp-agents/telemetry/server";

Example

Two destinations, each with its own URL and key:

import {
  defineObservability,
  otlp,
} from "@webmcp-agents/telemetry/server";

// Two destinations, each with its own URL and key. The env's headers
// never reach a target that has its own URL.
export const observability = defineObservability({
  exporters: [
    otlp({
      endpoint: "https://otel.example.com",
      headers: { "x-api-key": process.env.OTEL_KEY ?? "" },
    }),
    otlp({
      endpoints: {
        traces: "https://traces.example.com/ingest?tenant=acme",
      },
      protocol: "http/protobuf",
    }),
  ],
});

Give a base endpoint (/v1/traces is appended) or exact endpoints.traces (used as given, query string and tenant path included), never both. What a target leaves out comes from the environment.

Options

PropType
protocol?"http/json" | "http/protobuf" | "grpc"

The wire format. `"http/json"` (default) needs no dependency and runs on the edge and in the browser; `"http/protobuf"` loads `@opentelemetry/exporter-trace-otlp-proto` and `"grpc"` loads `@opentelemetry/exporter-trace-otlp-grpc` (optional installs, server only). Default: `OTEL_EXPORTER_OTLP_PROTOCOL`, else `"http/json"`.

Type"http/json" | "http/protobuf" | "grpc"
headers?Record<string, string>

Headers sent with every export (an API key, a project). Merged over `OTEL_EXPORTER_OTLP_HEADERS` only when the URL also comes from the env (no `endpoint` / `endpoints`): a target with its own URL gets only these, so the env's key never reaches another backend. Server side only: never put a key in the page.

TypeRecord<string, string>
timeout?number

How long one export may take before it is dropped, in ms. Default `OTEL_EXPORTER_OTLP_TIMEOUT`, else 30000.

Typenumber
Option Type Default
endpoint string OTEL_EXPORTER_OTLP_ENDPOINT
endpoints { traces: string } OTEL_EXPORTER_OTLP_TRACES_ENDPOINT

Returns

The OtlpTarget, as given (copied).

Notes

Headers stay with their own URL

headers are merged over OTEL_EXPORTER_OTLP_HEADERS only when the URL also comes from the environment. A target with its own endpoint or endpoints gets only its own headers, so the environment’s key never reaches another backend.

A protocol needs its package

http/json needs nothing and runs on the edge. http/protobuf loads @opentelemetry/exporter-trace-otlp-proto, grpc loads @opentelemetry/exporter-trace-otlp-grpc. A protocol whose package is not installed turns that target off with one error naming the package; the other targets still export.

endpoint and endpoints together

A type error. At run time that target is off with an error, and the other targets still export.

In the browser

observeAgents takes an OTLP target too, http/json only, with no environment to fall back on: whatever headers it carries are in the page.

More than one backend

Each exporter adds a request at the end of every turn, and its key lives in your app. To send to two backends, prefer one Collector that fans out.

Next

Was this page helpful?