Aviary
Observability

Diagnostics channel

Bridge every durable engine lifecycle event onto the node diagnostics-channel bus, so any @OnDiagnostic subscriber sees runs and steps alongside your app's other channels — additive to OTel and Telescope.

@dudousxd/nestjs-durable-diagnostics puts the durable engine on the diagnostics-channel bus. Every EngineEvent the engine emits — run.started, run.failed, step.completed, step.progress and the rest — is re-published on a durable channel, so any @OnDiagnostic('durable', ...) subscriber (or a raw getChannel consumer) observes durable's lifecycle the same way it observes every other channel in your app. It's the lowest-friction way to react to durable events in-process: no exporter, no store polling, no OTel or Telescope dependency.

pnpm add @dudousxd/nestjs-durable-diagnostics

Where this sits

This is a peer of the OpenTelemetry and Telescope integrations, not a replacement. All three subscribe to the same engine event bus independently and additively — attach any combination. Reach for diagnostics when you want to drive your own code off durable events (a metric, an alert, an audit log) rather than ship them to a tracing/inspection UI.

Import DurableDiagnosticsModule.forRoot() once at the app root, next to DurableModule. It resolves the already-constructed WorkflowEngine from the container on bootstrap, attaches the bridge, and detaches it on shutdown — it never constructs or owns the engine:

app.module.ts
import { DurableModule } from '@dudousxd/nestjs-durable';
import { DurableDiagnosticsModule } from '@dudousxd/nestjs-durable-diagnostics';
import { Module } from '@nestjs/common';

@Module({
  imports: [
    DurableModule.forRoot({ store, transport }),
    DurableDiagnosticsModule.forRoot(), // put durable on the diagnostics bus
  ],
})
export class AppModule {}

The module is @Global, so once imported, any provider anywhere can subscribe.

Subscribing to durable events

Durable declaration-merges its channels into the diagnostics ChannelRegistry, so the (lib, event) pair is typed — the payload of @OnDiagnostic('durable', 'run.failed') is inferred as the full EngineEvent, with no cast:

import { OnDiagnostic } from '@dudousxd/nestjs-diagnostics';
import type { EngineEvent } from '@dudousxd/nestjs-durable-core';
import { Injectable } from '@nestjs/common';

@Injectable()
export class RunAlerts {
  @OnDiagnostic('durable', 'run.failed')
  onRunFailed(event: EngineEvent) {
    // The whole EngineEvent is the payload: type, runId, workflow, error, durationMs, …
    this.pager.notify(`durable run ${event.runId} (${event.workflow}) failed: ${event.error?.message}`);
  }

  @OnDiagnostic('durable', 'step.completed')
  onStepDone(event: EngineEvent) {
    this.metrics.observe('durable.step.ms', event.durationMs ?? 0, { step: event.name });
  }
}

Prefer a plain subscription (outside DI, or to fan several events into one handler)? Get the channel directly:

import { getChannel } from '@dudousxd/nestjs-diagnostics';

const off = getChannel('durable', 'run.completed').subscribe((event) => {
  audit.log('run.completed', event.runId, event.durationMs);
});
// off() to unsubscribe

The channels durable publishes are the engine lifecycle events:

Channel eventEmitted when
run.startedA run began executing (first turn).
run.completedA run reached completed.
run.failedA run reached failed.
run.suspendedA run parked (sleep, signal, awaited step/child).
step.startedA step began.
step.completedA step settled successfully (durationMs, queueMs for remote).
step.failedA step settled with an error.
step.progressA live log line / sub-process outcome while a step is still running.

The payload is the verbatim EngineEvent — type, runId, workflow, namespace, seq, name, kind, output, error, durationMs, queueMs, and the at timestamp — so a subscriber has everything the dashboard, OTel and Telescope get, without a store read.

Filtering is the subscriber's job

The bridge forwards every engine event, including the high-frequency step.progress and step.started. That's cheap: emit short-circuits on hasSubscribers, so a channel nobody listens to costs nothing, and a subscriber that throws never propagates back into the engine. Subscribe only to the events you act on.

Running listeners as durable runs

@dudousxd/nestjs-diagnostics (0.9 or later) can hand every @OnDiagnostic listener call to a delivery transport instead of running it inline. With transports.durable(), each listener call for an event becomes a durable run. It's retried when the listener throws, survives a restart, and shows up in the console.

app.module.ts
import { DiagnosticsModule, transports } from '@dudousxd/nestjs-diagnostics/nestjs';
import { DurableModule } from '@dudousxd/nestjs-durable';

@Module({
  imports: [
    DurableModule.forRoot({ store, transport }),
    DiagnosticsModule.forRoot({
      default: 'durable',
      transports: {
        durable: transports.durable({ retries: 5, backoff: 'exp', backoffMs: 1_000 }),
      },
    }),
  ],
})
export class AppModule {}

Diagnostics loads @dudousxd/nestjs-durable-diagnostics/delivery when durable is the selected transport, so the package must be installed and DurableModule imported. Otherwise the app fails to boot with a message that says which one is missing.

What you get:

  • One run per listener and event. The run id is diag:<event id>:<listener id>, where the listener id is <ClassName>#<method>. Handing over the same event twice starts nothing new. The diag: run id prefix is reserved for these runs: don't start your own runs with an id that begins with it, or their lifecycle events are kept off the diagnostics bus.
  • Retries. The listener runs inside a step named handle. retries is the number of attempts (default 3). backoff is 'fixed' or 'exp' (default 'exp'), starting at backoffMs (default 1000) and capped at backoffMaxMs (default 30000). Set jitter: true to spread retries out. When the attempts run out, the run fails. A listener that the running process doesn't have fails at once, with no retries.
  • In the console. The runs are of the durable.diagnostics.listener workflow, tagged diagnostics, lib:<lib>, event:<event> and listener:<listener id>, so you can filter by any of them.

API and worker processes

Set role on DiagnosticsModule when the app runs as separate API and worker processes:

roleWhat the process does
'all' (default)Starts runs for the events it emits, and runs deliveries.
'api'Starts runs for the events it emits. It never runs a listener.
'worker'Starts runs for the events it emits, and runs deliveries.

Every process shares the durable store, so a run started on the API process is picked up by a worker.

api.module.ts
DiagnosticsModule.forRoot({
  default: 'durable',
  role: 'api',
  transports: { durable: transports.durable() },
});

Thin clients

A process that runs durable as a thin client (DurableModule.forRoot({ connection }), no store) can only start runs, so give it role: 'api'. Deliveries then run on processes that have a store.

The lifecycle events of these delivery runs are not forwarded to the durable channels. Otherwise, a listener on durable events would start a new delivery for each delivery it caused.

Attaching manually

If you construct a WorkflowEngine yourself (a script, a test harness, a non-Nest process) use the function the module wraps. attachDurableDiagnostics(engine) subscribes the bridge and returns an unsubscribe function:

import { WorkflowEngine } from '@dudousxd/nestjs-durable-core';
import { attachDurableDiagnostics } from '@dudousxd/nestjs-durable-diagnostics';

const engine = new WorkflowEngine({ store });
const detach = attachDurableDiagnostics(engine); // now on the 'durable' channel

// ...later
detach(); // stop bridging

This is exactly what DurableDiagnosticsModule does on onApplicationBootstrap (attach) and onApplicationShutdown (call the returned detach).

On a control plane

The process that coordinates an action emits its event. With topology: 'control-plane' the module attaches with tenant attribution: every event of a tenant's run, step events included, carries app: <partition> in its payload and on the envelope (emit's app option, which @dudousxd/nestjs-diagnostics 0.12+ stamps and its Telescope watcher tags app:<name>), and is emitted with its run's trace id (runTraceId(runId)). The control plane's own runs are emitted as before. A tenant pod has no local event stream, so the module emits nothing there: the control plane emits for it. Attaching by hand, pass the attribution yourself:

import { controlPlaneAttribution } from '@dudousxd/nestjs-durable-core';

const tenants = controlPlaneAttribution({ topology: 'control-plane' }, (id) => engine.getRun(id));
const detach = attachDurableDiagnostics(engine, { tenants });

See Observability with a control plane.

See also

  • OpenTelemetry — the same events as traces + metrics.
  • Telescope — the same events in the Telescope inspector.
  • Dashboard — the operating surface built on the same engine bus.

On this page