Open MercatoDocsSearch docsAPI reference

Framework

Exporting agent traces to OpenTelemetry

To investigate an agent run alongside application requests, export it to the same OpenTelemetry backend. Decide whether the destination should receive timing and identifiers alone or any captured content as well.

Agent Orchestrator can send persisted runs to any backend that accepts OTLP over HTTP with JSON or protobuf (Jaeger, Grafana Tempo, Langfuse, Datadog, a vendor collector). Spans use the OpenTelemetry GenAI semantic conventions (gen_ai.*, version 1.43) plus om.* attributes for platform concepts. Export is opt-in, fail-open and never affects a run.

Enabling export

Export happens only when all of these hold:

  1. Deployment switch: OM_AGENT_OTEL_EXPORT=on, with a usable http(s) endpoint and a supported protocol (http/json or http/protobuf). Alternatively, tenants can send to their own endpoint, see Tenant destinations; that path needs the switch on and OM_AGENT_OTEL_EXPORT_TENANT_ENDPOINTS=allow, but no deployment endpoint.
  2. Tenant opt-in: the tenant enables export on /backend/settings/otel-export.
  3. Allowlist: if the tenant set an agent allowlist, the run's agent is on it. No allowlist exports every agent.
  4. Source: the run's source is listed in OM_AGENT_OTEL_EXPORT_SOURCES (default runtime,eval).

Tenant settings are stored in module config agent_orchestrator/otel_export: enabled, content (none or full), exportUserIds and agentAllowlist and destination (deployment or integration). A malformed or unreadable record disables export for the tenant. Saving needs agent_orchestrator.agents.manage. Saving content = full additionally needs agent_orchestrator.trace.view_content and a deployment that allows content (OM_AGENT_OTEL_EXPORT_CONTENT=allow); otherwise it is refused with 422: content_export_not_allowed.

Environment variables

VariableDefaultPurpose
OM_AGENT_OTEL_EXPORToffDeployment master switch.
OM_AGENT_OTEL_EXPORT_ENDPOINTnoneOTLP traces URL. Falls back to OTEL_EXPORTER_OTLP_TRACES_ENDPOINT, then OTEL_EXPORTER_OTLP_ENDPOINT plus /v1/traces.
OM_AGENT_OTEL_EXPORT_HEADERSnoneRequest headers as key=value pairs (URL-encoded values). Falls back to OTEL_EXPORTER_OTLP_HEADERS.
OM_AGENT_OTEL_EXPORT_PROTOCOLhttp/jsonhttp/json or http/protobuf; anything else disables deployment-endpoint export.
OM_AGENT_OTEL_EXPORT_CONTENTdenyallow lets tenants opt into prompt and response content export.
OM_AGENT_OTEL_EXPORT_TENANT_ENDPOINTSdenyallow lets organizations export to their own endpoint through the agent_orchestrator_otel_export integration.
OM_AGENT_OTEL_EXPORT_PRIVATE_HOSTSnoneComma-separated hosts (exact or dot-boundary suffix) that tenant endpoints may resolve to private addresses, for example an in-cluster collector. Empty denies every private address.
OM_AGENT_OTEL_EXPORT_DELAY_MS30000Delay between run completion and export, so late spans are included. Maximum 24 hours.
OM_AGENT_OTEL_SERVICE_NAMEopen-mercato-agentsservice.name resource attribute.
OM_AGENT_OTEL_EXPORT_SOURCESruntime,evalRun sources that may be exported.
OM_AGENT_OTEL_TRACE_URL_TEMPLATEnoneLink template for the run page. Must contain the token {traceId}.
RATE_LIMIT_AGENT_ORCH_OTEL_EXPORT_TEST_POINTS1Test-span requests allowed per window, per tenant.
RATE_LIMIT_AGENT_ORCH_OTEL_EXPORT_TEST_DURATION10Window in seconds.
RATE_LIMIT_AGENT_ORCH_OTEL_EXPORT_TEST_BLOCK_DURATIONnoneOptional block time in seconds after the limit is hit.

The endpoint and headers stay server-side. They are never logged, returned by the API or shown in the UI, and the HTTP client does not follow redirects, so credentials never leave the configured host.

What is exported

Per run: the run span, its LLM, tool and agent spans with the attributes from Trace capture policy and step metadata, proposal dispositions, guardrail checks as span events, evaluation results, and the workflow span for runs that belong to a workflow. Resource attributes carry the service name, version, deployment environment, tenant and organization ids and the GenAI semconv version.

What is never exported

String attributes pass through a redaction step that masks email addresses, authorization schemes and secret-looking keys before they are sent.

Content export

Prompt and response content is exported only when all three locks are open:

  1. Deployment: OM_AGENT_OTEL_EXPORT_CONTENT=allow.
  2. Tenant: the tenant setting content = full. Only users with agent_orchestrator.trace.view_content can opt in (the settings API, the command and its undo all check it).
  3. Run: the run was captured with om.capture = full (see Trace capture policy). Runs captured at a lower level export no content.

With the locks open, the worker reads the stored request and response artifacts of each LLM span and adds one gen_ai.client.inference.operation.details event to the span with these attributes: gen_ai.system_instructions, gen_ai.input.messages, gen_ai.output.messages and gen_ai.tool.definitions. Messages follow the GenAI message schema (text, reasoning, tool call and tool call response parts); binary parts become file metadata (modality, MIME type, size, sha256) and never carry bytes or file names. Every string passes a second redaction pass on top of the one applied at capture time, with the same rules: secret-looking values are always removed, and personal data (emails, IBANs, card numbers, phone numbers) is removed when the run was captured with Redact personal data (redactPii) on. With it off, exported content keeps the personal data that the stored trace keeps.

Limits: each content attribute is capped at 64 KiB and marked om.truncated when cut; a run reads at most 4 MiB of stored content; export requests are split so no body exceeds 4 MiB (a single oversized span is sent alone).

Each LLM span carries om.content.export_status:

ValueMeaning
exportedAll content keys of the span loaded.
unavailableStorage failed or the content could not be read.
expiredRetention removed the content.
over_budgetThe 4 MiB run budget was exhausted.
not_capturedThe span has no stored content.

Every artifact read for export is recorded in the content access log, like a manual read through the run page, including reads dropped for budget. Tool call arguments and results are exported only for tool spans that carry a gen_ai.tool.call.id matching the LLM content; native and OpenCode runs do not record that id yet, so tool spans currently export no content. The otel:export --dry-run backfill maps runs without content and never prints it.

Protobuf

Set OM_AGENT_OTEL_EXPORT_PROTOCOL=http/protobuf to send application/x-protobuf bodies. The encoder is hand-written, with no OpenTelemetry SDK dependency, and normalizes ids, timestamps and value types exactly like the JSON encoder. Integers beyond signed 64-bit are sent as decimal strings. Tenant destinations choose their own protocol.

Tenant destinations

An organization can send its runs to its own OTLP endpoint instead of the deployment endpoint:

  1. The deployment sets OM_AGENT_OTEL_EXPORT=on and OM_AGENT_OTEL_EXPORT_TENANT_ENDPOINTS=allow.
  2. An administrator configures the agent_orchestrator_otel_export integration for the organization (credentials: endpoint, optional headers as URL-encoded key=value pairs, protocol) and enables it. Credentials are stored per organization, encrypted, and never returned by the API or shown again.
  3. The tenant sets destination = integration on /backend/settings/otel-export.

Endpoints are vetted before every export and by the integration health check: http(s) only, no credentials in the URL, and every DNS answer must be a public address (loopback, link-local and metadata, private, CGNAT, multicast and mapped or transition addresses are refused) unless the host is listed in OM_AGENT_OTEL_EXPORT_PRIVATE_HOSTS. The connection is pinned to the vetted addresses so a DNS change cannot redirect it, the hostname is kept for Host, SNI and certificate checks, and redirects are not followed. The endpoint, headers and the block reason are never logged or returned.

The destination fails closed: when it cannot be resolved, nothing is sent and the deployment endpoint is never used as a fallback. Failures are reported with these codes in export health, test span responses and backfill skips:

CodeCause
deployment_unconfiguredDestination is deployment but the switch is off or the endpoint is missing or unusable.
integration_unconfiguredNo valid credentials for the organization.
integration_disabledCredentials exist but the integration is not enabled.
tenant_endpoints_deniedThe deployment does not allow tenant endpoints.
endpoint_blockedThe endpoint failed the SSRF checks.

Deterministic ids

Trace, run, span, workflow and disposition ids are derived by hashing stable identifiers, not generated randomly. The trace id is anchored on the workflow instance when there is one, otherwise on the root run, so every run of a workflow lands in one trace. Re-exporting a run produces the same ids, which lets a backend merge repeated exports of the same spans, and the run page can show the trace id and a deep link without extra storage.

Delivery guarantees

Delivery is at-least-once. The queue has no job-id deduplication, so a retry after an ambiguous failure, or a manual backfill, can deliver a run twice. Because ids are deterministic, backends that deduplicate on span id collapse the copies; others may show duplicates.

A persistent subscriber on agent_orchestrator.run.completed and agent_orchestrator.run.ingested enqueues a job on the agent-orchestrator-otel-export queue, delayed by OM_AGENT_OTEL_EXPORT_DELAY_MS. The worker re-checks the gate, builds the payload and sends it:

Failures are reported through the error reporter and recorded as export health; they never fail the run. Enqueueing is best-effort: if a subscriber cannot enqueue the job, it reports the error and carries on without failing the event, so other subscribers of the same event are not re-run. A queue outage at that moment can therefore drop an export; backfill the window with otel:export.

The invoke_workflow root span is built only from the process instance, so every run of the execution exports the same span. It is included only once the process reaches a terminal status; runs exported earlier already point to its span id. Because a process can finish after its last run was exported (a user task, an approval or a non-agent step at the end), the subscribers that mark a workflow instance completed, failed or cancelled also enqueue a re-export of the latest exportable top-level run of that execution, scoped to its tenant and organization. Ids are deterministic, so the repeated run spans merge and the export now carries the root. A process without agent runs exports nothing.

Health and test span

The settings page shows the last success and last error code for the tenant, and the system health panel has an OTel export line (down when the deployment is off, unknown before the first attempt, degraded after an error, ok otherwise).

Use Send test span (POST /api/agent_orchestrator/otel-export/test) to send one synthetic om.export.test span. A backend rejection returns ok: false with a normal response; a disabled deployment returns 409, and exceeding the rate limit returns 429.

Set OM_AGENT_OTEL_TRACE_URL_TEMPLATE to your backend's trace URL with the {traceId} token, for example http://127.0.0.1:16686/trace/{traceId}. When the run passes the same gate as the exporter (deployment switch, tenant opt-in, agent allowlist and run source), the run page shows the trace id and an Open in tracing backend link. Templates that do not resolve to an http(s) URL are ignored.

Backfill CLI

Replay persisted runs, for example after enabling export or after an outage:

# Inspect the OTLP payload of one run, no network and no queue (NDJSON on stdout)
yarn mercato agent_orchestrator otel:export --run RUN_ID --dry-run

# Enqueue every run in a window for one tenant
yarn mercato agent_orchestrator otel:export --since 2026-10-01T00:00:00Z --until 2026-10-08T00:00:00Z --tenant TENANT_ID --limit 500

Options: --run, or --since with optional --until; --tenant; --limit (1 to 1000); --dry-run. Without --dry-run the deployment switch must be on, and each run still has to pass the tenant gate. The command prints how many runs were enqueued and why others were skipped.

Local collector and Jaeger

A compose profile starts an OTLP collector that forwards to Jaeger:

docker compose --project-directory . -f starters/docker/compose.agent-otel.yml --profile agent-otel up

Then set:

OM_AGENT_OTEL_EXPORT=on
OM_AGENT_OTEL_EXPORT_ENDPOINT=http://127.0.0.1:4318/v1/traces
OM_AGENT_OTEL_TRACE_URL_TEMPLATE=http://127.0.0.1:16686/trace/{traceId}

Open the Jaeger UI at http://127.0.0.1:16686.

Langfuse

Langfuse accepts OTLP over HTTP (JSON or protobuf, gzip) on its OpenTelemetry endpoint. Authentication is HTTP Basic with the project's public key as user name and secret key as password:

OM_AGENT_OTEL_EXPORT=on
OM_AGENT_OTEL_EXPORT_ENDPOINT=https://cloud.langfuse.com/api/public/otel/v1/traces
OM_AGENT_OTEL_EXPORT_HEADERS="Authorization=Basic%20$(printf '%s:%s' "$LANGFUSE_PUBLIC_KEY" "$LANGFUSE_SECRET_KEY" | base64 | tr -d '\n')"

The value must be a single line: GNU base64 wraps long output, and a header value with a line break is skipped, which leaves the request unauthenticated (401). Other regions use https://us.cloud.langfuse.com, https://jp.cloud.langfuse.com or https://hipaa.cloud.langfuse.com with the same /api/public/otel/v1/traces path; a self-hosted instance uses its own host. Header values are URL-encoded, so the space after Basic is written as %20; base64 padding (=) needs no encoding. A tenant destination takes the same endpoint and header list in the integration credentials. A self-hosted Langfuse on a private network must be listed in OM_AGENT_OTEL_EXPORT_PRIVATE_HOSTS to be used as a tenant destination.

How a run appears in Langfuse:

Exported spanLangfuse observation
invoke_agent <agent>Agent
chat <model>Generation, with model and input/output token usage
execute_tool <tool>Tool
invoke_workflow, om.* spansSpan

With content export on, the gen_ai.client.inference.operation.details event becomes the generation's input (system instructions first) and output, and tool spans that carry call content show the arguments as input and the result as output. Without content, generations show model, usage and timing only. Resource attributes, including om.tenant.id and om.organization.id, and the om.* span attributes appear as observation metadata. A wrong key is answered with 401 and the export is dropped, not retried.

Verified against a self-hosted Langfuse 4.81.0 with both http/json and http/protobuf.

Datadog

Datadog's OTLP traces intake accepts http/json and http/protobuf (not gRPC) and answers a successful export with 200 or 202, both treated as delivered. Agent Observability (LLM Observability) only converts spans when conversion is switched on, which the exporter does through the DD-LLMObs-Enabled header:

OM_AGENT_OTEL_EXPORT=on
OM_AGENT_OTEL_EXPORT_ENDPOINT=https://otlp.datadoghq.com/v1/traces
OM_AGENT_OTEL_EXPORT_PROTOCOL=http/protobuf
OM_AGENT_OTEL_EXPORT_HEADERS="dd-api-key=$DD_API_KEY,dd-otlp-source=llmobs,DD-LLMObs-Enabled=true"

Use the endpoint of your Datadog site (for example https://otlp.us3.datadoghq.com/v1/traces or https://otlp.datadoghq.eu/v1/traces); a wrong site or an invalid API key is answered with 403, and the export is dropped, not retried. Without DD-LLMObs-Enabled=true the spans still arrive in APM but not in Agent Observability; the exporter does not set the alternative dd_llmobs_enabled resource attribute.

How a run appears in Agent Observability:

Verified against Datadog (EU site) with both http/json and http/protobuf: a real agent run showed up in Agent Observability as an agent span with an LLM span carrying the prompt, completion, model and token usage (Datadog added a cost estimate), and tool spans carried their arguments and results. The contract test otel-vendor-compat.test.ts pins the fields this relies on.

Integration tests

TC-AGENT-OTEL-001 and TC-AGENT-OTEL-002 contain delivery cases that need a fake OTLP receiver on port 4319. They run only when the app under test is started with export on and pointed at that port, and skip with a reason otherwise. CI does not set these variables, so the delivery cases run locally:

OM_AGENT_OTEL_EXPORT=on \
OM_AGENT_OTEL_EXPORT_ENDPOINT=http://127.0.0.1:4319/v1/traces \
OM_AGENT_OTEL_EXPORT_DELAY_MS=0 \
OM_AGENT_OTEL_TRACE_URL_TEMPLATE='http://127.0.0.1:16686/trace/{traceId}' \
yarn test:integration:ephemeral:start

Not included yet

Live streaming, tool call content for native and OpenCode runs (no call id is recorded yet), and export of chat or copilot runs are not part of this release.

Previous: Trace capture policy and step metadata · Next: AI Agents