Export durable observations
Export persisted run events, completed steps, and wait-token transitions with checkpoints and graceful shutdown.
Use @runlane/observability to export sanitized durable facts independently of task execution. The exporter scans the storage observation stream in bounded batches and advances a consumer checkpoint only after the sink accepts a batch.
Durable observation storage is opt-in because it adds a sanitized record for every observed fact and advances one shared stream head. Set observability: { durable: true } on every runtime that writes to the exported environment. The default comes from contractDefaults.observability.durable. When durable observations are disabled, canonical run history, steps, and wait tokens remain durable, and live observers and runtime telemetry still emit. See defaults.
Use the same setting across all producer and worker replicas for an environment. An exporter can only read facts written by runtimes with durable observations enabled.
Your lane needs persistent storage for export to survive a process restart. A separate exporter process must connect to the same storage and environment as the workers. The local lane keeps observations in dev's memory and requires runlane dev. They disappear when dev stops. Use createTestLane() for in-process exporter tests without dev.
Create an exporter
Install Runlane and the OpenTelemetry packages your application will own:
npm install @runlane/observability @opentelemetry/api@^1.10.0
npm install @opentelemetry/core@^3.0.0 @opentelemetry/resources@^3.0.0 @opentelemetry/sdk-logs@^3.0.0
npm install @opentelemetry/exporter-logs-otlp-http@~0.300.0This example uses SDK 3.x and the matching OTLP exporter. Configure a Collector or backend that accepts OTLP/HTTP logs, then create an exporter using your runtime's storage:
import { OTLPLogExporter } from '@opentelemetry/exporter-logs-otlp-http'
import { createRunlaneObservationExportSource, type RunlaneRuntime } from '@runlane/core'
import { createRunlaneObservationExporter, RunlaneObservationSinkOwnership } from '@runlane/observability'
import { openTelemetryObservationSink } from '@runlane/observability/opentelemetry'
export function createObservationExport(runtime: RunlaneRuntime, logsEndpoint: string) {
return createRunlaneObservationExporter({
consumer: 'primary-observation-export',
environment: runtime.environment,
source: createRunlaneObservationExportSource(runtime.lane.storage),
sink: openTelemetryObservationSink({
exporter: new OTLPLogExporter({ url: logsEndpoint }),
resourceAttributes: { 'service.name': 'runlane-observations' },
}),
sinkOwnership: RunlaneObservationSinkOwnership.Exporter,
})
}Pass the complete logs URL, such as http://localhost:4318/v1/logs. Set headers for authentication and timeoutMillis on OTLPLogExporter when needed. The sink owns this dedicated exporter and does not require a global SDK. It accepts any OpenTelemetry LogRecordExporter through openTelemetryObservationSink({ exporter, resourceAttributes }).
The sink allows one active export and waits for its callback, even after cancellation. This keeps batches ordered without an exporter concurrencyLimit setting. Runlane ships no OpenTelemetry SDK or exporter; your application chooses and installs them.
In your process supervisor, keep the promise returned by exporter.start() and handle its rejection. For a scheduled bounded job, use await exporter.exportOnce() and inspect its status: exported, idle, failed, or aborted. A failed tick returns its error; the polling loop retries retryable failures and rejects terminal structured errors.
Retry failures and restart
backoff accepts the same value as RetryPolicy.backoff. Use a duration string such as backoff: '2s' for fixed waits. For exponential waits, use an object:
import { RetryBackoffType } from '@runlane/core'
import { createRunlaneObservationExporter, type RunlaneObservationExporterOptions } from '@runlane/observability'
export function createExporter(options: RunlaneObservationExporterOptions) {
return createRunlaneObservationExporter({
...options,
backoff: { type: RetryBackoffType.Exponential, delay: '2s', maxDelay: '2m' },
})
}The default is contractDefaults.observability.exporter.backoff: exponential waits starting at 1 second, capped at 1 minute. It uses the same retryBackoffSchema and getRetryDelayMilliseconds that @runlane/core exports for task and hook retries. For retry number n, exponential waits have a ceiling of min(maxDelay, delay * 2 ** (n - 1)); fixed waits have the same ceiling each time. Downward jitter picks a whole-millisecond wait between half that ceiling, rounded up, and the ceiling. A successful batch or idle scan resets the next wait to the base delay.
Retryable failures keep retrying until the destination recovers. There is no maxRetries option. Because retries have no budget, exponential backoff requires maxDelay. The base delay, cap, and idle polling interval must each fit a Node.js timer (at most 2,147,483,647 ms). Invalid options reject with configuration_invalid.
A non-retryable error rejects start(). After fixing the cause, call start() again on the same exporter. It reads the saved checkpoint and skips batches already acknowledged there. For example, if batch A was checkpointed and batch B failed, the next start() begins with batch B. Keep the same consumer and environment. Only close() permanently stops reuse.
Shut down gracefully
Call await exporter.close() before closing storage. It stops new scans, interrupts idle polling or retry backoff, waits for the current sink export and successful checkpoint, and closes the sink when sinkOwnership is Exporter. It leaves unprocessed backlog for the next exporter using the same consumer id.
Repeated close() calls return the same promise. Shutdown rejects if the active operation or owned sink cleanup fails. New start() and exportOnce() calls reject after shutdown. A sink or storage call that never settles can delay shutdown; configure provider timeouts.
The default ownership comes from contractDefaults.observability.exporter.sinkOwnership. Choose Application for a shared sink and close it yourself after every user stops. openTelemetryObservationSink.close() shuts down its underlying log exporter, so use a dedicated provider exporter or coordinate its lifetime with all its users. Observation export never closes storage or the application's telemetry SDK.
start({ signal }) still supports cancellation. Aborting a signal may interrupt a sink call and leave the batch for replay. It does not close the sink or permanently close the exporter. Prefer close() when you want the current export to finish.
Check delivery and replay
Run one active exporter for each consumer id and environment. Checkpoints use compare-and-set, but two exporters can both send a batch before one loses the checkpoint race. Use a different consumer id for an independent destination.
Delivery is at least once: a crash after sink acceptance but before checkpoint persistence can replay the same records. Deduplicate by observation record id when your destination requires it. OTLP log ingestion does not itself promise deduplication.
Trigger and execute a task, then inspect exporter.getStats(). After a successful batch, recordsExported and checkpointAdvances increase and lastCheckpointCursor is set. During a sink outage, failures increase while the checkpoint stays unchanged. Restart with the same consumer and environment to resume after its saved checkpoint.
Pass telemetry: openTelemetryRunlaneTelemetry() to the exporter options to record its batch, record, failure, checkpoint, and lag metrics through an initialized application SDK. Lag is measured when a batch succeeds; it is not an independent backlog age probe during an outage.
Exported data
| Observation | Fields |
|---|---|
run_event | Environment, run id, event id, sequence, event type, time, and optional W3C trace context. |
run_step | Environment, run id, attempt, step key, step token, and completion time. |
wait_token_transition | Environment, token id, transition id, status, and transition time. |
Each durable record also carries a stable record id, source identity, recorded time, and opaque stream position. Payloads, task outputs, token outputs, metadata, completion actors, baggage, and arbitrary propagation headers are excluded. Run-event logs can join a trace through traceparent and tracestate; step and token observations carry no trace carrier.
Live observability.observers receive sanitized observations after the canonical transition persists, regardless of the durable setting. Their callbacks are awaited and can delay the caller. Failures go to onObserverError without rolling back the persisted fact. Use durable export when you need checkpointed delivery.