Under heavy development
StitchAPI
GuidesObservability

OTLP export

Export traces as OpenTelemetry spans for your existing observability stack.

Reach for OTLP export when you want a stitch's events as OpenTelemetry spans in the observability stack you already run — each call's event stream maps to one CLIENT span, so a stitch drops into your existing OTel collector with no new plumbing. It is just another trace sink, teed alongside the console/JSONL sink rather than replacing it.

Example

The zero-code path is an env toggle: set STITCH_EXPORT=otlp and every stitch also fans its events to an OTLP collector (default http://localhost:4318/v1/traces, or OTEL_EXPORTER_OTLP_ENDPOINT).

STITCH_EXPORT=otlp OTEL_EXPORTER_OTLP_ENDPOINT=https://api.example.com node app.js

To wire it yourself — to set headers, or to tee OTLP next to your own sink — build the sink with otlpTrace() and combine sinks with multiplex:

import { , ,  } from 'stitchapi';

const  = (
    ({ : true }),
    ({
        : 'https://api.example.com',
        : { : 'Bearer token' },
    }),
);

Options

STITCH_EXPORT=otlp is the toggle (a comma list, e.g. console,otlp); OTEL_EXPORTER_OTLP_ENDPOINT sets the collector base URL.

otlpTrace(opts?) returns a sink. OtlpOptions carries endpoint (OTLP/HTTP base URL), headers (extra headers on the POST, e.g. auth), and exporter (a custom SpanExporter destination, defaulting to the built-in HTTP exporter).

otlpHttpExporter({ endpoint?, headers? }) is that default exporter — it POSTs OTLP/JSON to ${endpoint}/v1/traces. toOtlpJson(spans) serializes collected spans to the OTLP/JSON ResourceSpans shape a collector accepts, if you ship them some other way.

See Reference → Helpers for the helper signatures and Reference → Events for the event types each span is built from.

Export is fire-and-forget: a missing collector or network error drops the batch and never breaks a stitch call.

See also

On this page