instrumentation.ts
instrumentation.ts is the single home for telemetry, auto-discovered and run
once at startup before the first agent turn. Add it when you want an external
telemetry sink or explicit content-capture controls.
Minimal Example
import { defineInstrumentation } from "@assemblyline-agents/core";
import { createOtlpSinkFromEnv } from "@assemblyline-agents/otlp";
export default defineInstrumentation({
serviceName: "starter-agent",
captureContent: "usage",
setup: ({ env }) => createOtlpSinkFromEnv(env)
});
Full Options
| Field | Type / values | Default | Effect |
|---|---|---|---|
serviceName | string | agent name | Service name stamped on spans. |
setup | ({ agentName, manifest, env }) => sink | — | Runs once at startup; return a telemetry sink to export spans. |
captureContent | level string | policy object | "usage" | Content-capture detail; a bare level is shorthand for { level }. |
recordInputs / recordOutputs | boolean | false | Record run inputs/outputs on spans. |
captureContent also accepts a policy object:
| Field | Type / values | Default | Effect |
|---|---|---|---|
level | off | usage | content | full | — | Capture level (required in object form). |
maxChars | number | ~8000 (relaxed at full) | Per-field character cap before truncation. |
redact | boolean | true (even at full) | Key-based redaction of sensitive values. |
redactKeys | string[] | built-in set | Extra sensitive key names to redact. |
sampleRate | number 0..1 | 1 | Per-trace sampling of content; usage/metadata always export. |
includeToolIO | boolean | true at content/full | Capture tool arguments and results. |
Agent Runs
Agent Runs-style observability is available without instrumentation.ts through
run, event, tool, checkpoint, delivery, usage, subagent, and timeline query
contracts. The Node host exposes authenticated inspection endpoints under
/runs.
OTLP Export
@assemblyline-agents/otlp provides:
createOtlpSink(options)createOtlpSinkFromEnv(env)
createOtlpSinkFromEnv reads OTEL_EXPORTER_OTLP_ENDPOINT,
OTEL_EXPORTER_OTLP_HEADERS, OTEL_SERVICE_NAME,
OTEL_EXPORTER_OTLP_TIMEOUT, ASSEMBLY_LINE_OTLP_BATCH_MAX, and
ASSEMBLY_LINE_OTLP_FLUSH_MS. Any OTLP backend works: Langfuse, Phoenix, Grafana,
and others.
Capture Levels
| Level | Records |
|---|---|
off | No span content. |
usage | Token usage, cost, model, provider, finish reason, and tool-call spans. No message bodies. |
content | Adds bounded prompt, completion, and tool IO previews with redaction. |
full | More complete prompt, completion, and tool IO capture; use only in trusted environments. |
Conventions
- Prefer
usagein production unless operators have an explicit reason to capture content and the product privacy materials account for it. - Host- or gateway-supplied instrumentation overrides win over
instrumentation.ts.