Diagnostics and resilience
Diagnostics and resilience provide the signals and safeguards that keep workflow operation visible and dependable. They collect logs and OpenTelemetry data for live investigation, expose health and trend data through dashboards, and support retry, cache, and schedule controls that reduce avoidable work and recover from temporary faults. See Operations and observability for the wider operating model.
Operational signal flow
The system turns workflow activity and external telemetry into three useful outcomes: live signals for an operator, retained data for later review, and control feedback for the runtime. Redaction and access checks protect diagnostic data before it reaches those outcomes.
This diagram shows how workflow execution and external telemetry move through the diagnostic and reliability layers.
flowchart LR
W[Workflow execution] --> L[Console and structured logs]
T[External OTLP data] --> O[OpenTelemetry ingestion]
L --> R[Redaction and bounded storage]
O --> R
R --> Q[Queries and live feeds]
Q --> D[Diagnostic dashboards]
W --> X[Resilience and scheduling controls]
X --> W
R --> P[Operational findings]
Diagnostic signals
Diagnostic signals describe what the runtime is doing and what an operator can inspect. The system provides raw console output for fast viewing, structured events for filtering and search, and OpenTelemetry data for traces, metrics, logs, and service sources.
Console logs
Console logs provide a live view of raw process output through REST and SignalR. The capture layer keeps a bounded recent view and a bounded queue for each subscriber, so a slow consumer does not create unbounded memory use. It can remove ANSI escape sequences and redact configured sensitive text before operators receive the output.
Use console logs for quick diagnosis when the main question is what a running process wrote. Treat dropped lines and stale or disconnected sources as loss of evidence rather than proof that the workflow succeeded.
References: src/…/ConsoleLogsFeature.cs• L16-46 src/…/ConsoleLogsFeature.cs• L48-66 src/…/ConsoleLogsDashboardContributor.cs• L26-41
Structured logs
Structured logs represent events with fields such as level, source, and time. They support recent queries and live streaming over REST and SignalR, which lets an operator narrow a problem by event data instead of reading a plain text stream.
The service limits recent events and subscriber queues. It redacts sensitive property names and text patterns. A relational storage option writes events through a bounded background buffer and can remove records by age or row count. The storage layer reports dropped writes so the dashboard can show when the record is incomplete.
References: src/…/StructuredLogsFeature.cs• L15-26 src/…/StructuredLogsFeature.cs• L30-86 src/…/StructuredLogWriteBuffer.cs• L12-25 src/…/StructuredLogWriteBuffer.cs• L27-47 src/…/StructuredLogRetentionService.cs• L8-30
OpenTelemetry data
OpenTelemetry diagnostics accept standard telemetry batches and make traces, spans, metric points, log records, and telemetry resources available to the Elsa diagnostic view. The system supports OTLP HTTP ingestion and optional gRPC ingestion, plus a live SignalR feed for authorized users.
Incoming data is redacted before it is stored or published. The default store keeps bounded recent data by signal type and reports dropped items. Trace detail joins a trace with its spans, resources, and related logs so an operator can follow one execution across signal types.
References: src/…/OpenTelemetryFeature.cs• L15-21 src/…/OpenTelemetryFeature.cs• L81-91 src/…/OpenTelemetryIngestor.cs• L6-13 src/…/OpenTelemetryRedactor.cs• L17-26 src/…/InMemoryOpenTelemetryStore.cs• L37-60 src/…/InMemoryOpenTelemetryStore.cs• L100-124
Workflow execution logs
Workflow activity logging adds a start event and a completion event with elapsed time around activity execution when information logging is enabled. This gives the operator a simple timing signal that connects workflow progress to the broader console, structured, or telemetry pipeline used by the host.
References: src/…/LoggingMiddleware.cs• L7-10 src/…/LoggingMiddleware.cs• L27-41
Dashboards and persistence
Diagnostic dashboards turn raw signals into a compact view of capability, source health, recent errors, and data loss. They do not replace the underlying query or storage services; they summarize those services and produce findings when the evidence is unavailable or shows risk.
Dashboard contributions
The workflow dashboard covers runtime state and workflow outcomes. It reports whether the runtime accepts work, is paused, or is draining. It also exposes counts for running, completed, faulted, suspended, interrupted, and incident-bearing workflows, along with trends, recent activity, and workflow hotspots.
The console and structured-log dashboards add source counts and recent error signals to the same operational view. They distinguish access failure from service unavailability and flag stale sources. Structured logs also flag dropped writes and recent error or critical events. These states help an operator separate a quiet system from a system that cannot report.
References: src/…/WorkflowDashboardContributor.cs• L21-53 src/…/WorkflowDashboardContributor.cs• L56-83 src/…/ConsoleLogsDashboardContributor.cs• L14-40 src/…/StructuredLogsDashboardContributor.cs• L16-45
Diagnostic data lifetime
Recent diagnostic data is bounded by capacity and is not a promise of complete history. In-memory telemetry and recent log views support fast investigation. Relational structured-log storage adds a longer-lived query source when the host enables it, while retention limits keep that store within an intended age or row bound.
During shutdown, the structured-log writer tries to flush queued events within its configured timeout. Events that cannot enter the queue or cannot be flushed are counted as dropped. Operators should use those counts when deciding whether a time range is suitable for incident analysis.
References: src/…/OpenTelemetryDiagnosticsOptions.cs• L3-20 src/…/StructuredLogWriteBuffer.cs• L87-149 src/…/StructuredLogWriteBuffer.cs• L152-188 src/…/IStructuredLogStorageDiagnostics.cs• L3-6
Reliability controls
Reliability controls shape how workflow work is retried, reused, and resumed. Resilience handles temporary activity faults, caching reduces repeated reads, and scheduling turns time-based intent into future workflow starts or resumes.
Activity resilience
Activity resilience applies a selected strategy around an activity action. A strategy can come from a configured catalog entry or from an expression evaluated in the activity context. If no strategy is selected, the action runs without an added resilience policy.
When a retry occurs, the system captures the attempt number, delay, outcome, and activity context. It records the applied strategy and retry count with the execution context. This makes recovery behavior visible to workflow diagnostics and the designer instead of hiding it inside a generic exception path.
The resilience API makes this behavior available to operators and tools. One endpoint lists available strategies to authenticated callers, while another returns paged retry attempts for an activity instance under a dedicated view permission. A simulation endpoint produces controlled HTTP responses for recovery-path checks under a dedicated execute permission. Simulation sessions are bounded and scoped to the caller identity.
References: src/…/ResilienceStrategyConfigEvaluator.cs• L10-23 src/…/ConfigurationResilienceStrategySource.cs• L7-17 src/…/ResilientActivityInvoker.cs• L24-59 src/…/ResilientActivityInvoker.cs• L68-80 src/…/RetryTelemetryListener.cs• L8-26 src/…/Endpoint.cs• L9-23 src/…/Endpoint.cs• L9-33 src/…/Endpoint.cs• L14-48 src/…/ResiliencePermissions.cs• L11-33
Workflow caching
Caching keeps frequently read workflow definitions and trigger records close to the runtime for a short period. Cache keys include the tenant where one is active, which prevents one tenant from reading another tenant's cached result.
Workflow definition changes and workflow refresh events trigger eviction. Trigger and definition caches therefore improve read speed without becoming the source of truth. A stale cache is a correctness risk only when its invalidation contract is not kept in step with the corresponding store changes.
References: src/…/CachingOptions.cs• L3-12 src/…/WorkflowDefinitionCacheManager.cs• L9-28 src/…/WorkflowDefinitionCacheManager.cs• L41-54 src/…/CachingWorkflowRuntimeFeature.cs• L11-31 src/…/CachingTriggerStore.cs• L12-24
Workflow scheduling
Scheduling creates future work for two related cases: starting a new workflow instance from a trigger and resuming an existing instance from a bookmark. The default scheduler supports a single instant, a recurring interval, and a cron expression. Delay, start-at, timer, and cron signals use the same workflow scheduling boundary.
The default scheduler is local to the host process. At startup it reads stored triggers and bookmarks and rebuilds their schedules. This restores time-based work after a process restart when the schedule records remain available. A past-due start is treated as catch-up work, while an invalid cron expression is reported and skipped.
This sequence shows how stored workflow timing state becomes a future execution.
sequenceDiagram
participant Store as Trigger or bookmark store
participant Boot as Startup restore
participant Scheduler as Workflow scheduler
participant Runtime as Workflow runtime
Store->>Boot: Read time-based records
Boot->>Scheduler: Register start, delay, timer, or cron work
Scheduler->>Scheduler: Wait for due time
Scheduler->>Runtime: Start or resume workflow
Runtime-->>Scheduler: Complete or replace schedule state
References: src/…/SchedulingFeature.cs• L20-58 src/…/DefaultWorkflowScheduler.cs• L6-60 src/…/CreateSchedulesStartupTask.cs• L13-50 src/…/DefaultTriggerScheduler.cs• L18-92 src/…/DefaultBookmarkScheduler.cs• L24-82
Background activity scheduling
Background activity scheduling separates activity execution from the workflow's current call stack. It creates or enqueues a job and later invokes the activity inside a fresh service scope. The runtime can therefore continue with other work while a background activity waits for its own queue slot.
References: src/…/LocalBackgroundActivityScheduler.cs• L6-20 src/…/LocalBackgroundActivityScheduler.cs• L23-47
Change checklist
When these files or sections are changed, remember to consider these:
- When changing diagnostic event shape or redaction rules, check the live feed, query results, dashboard summaries, and any persisted structured-log mapping together.
- When changing bounded queues or recent-data capacity, keep dropped-event and dropped-write diagnostics aligned with the point where data can be lost.
- When changing dashboard status or finding keys, preserve the distinction between unauthorized access, unavailable data, stale sources, and actual workflow faults.
- When changing resilience strategy serialization or configuration, keep identifier lookup, expression lookup, and execution-context metadata compatible.
- When changing resilience routes or permission descriptors, keep retry and simulation authorization aligned with the permission catalog, and preserve authenticated access for strategy browsing.
- When changing trigger or bookmark payloads, update schedule restoration and unscheduling paths together so a restart does not create duplicate or orphaned work.
- When changing cache keys or invalidation events, preserve tenant isolation and evict every read path affected by definition or trigger refresh.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A diagnostic queue reaches capacity | Recent logs or telemetry are dropped and the investigation view is incomplete | Use bounded-capacity diagnostics and expose dropped counts in the storage or dashboard summary |
| A structured-log flush fails or exceeds shutdown time | Queued events are counted as dropped and may not reach relational storage | Monitor dropped-write findings and allow the configured flush window to complete |
| A diagnostic source stops sending heartbeats | The dashboard marks the source stale or disconnected even if old data remains | Check source health before treating an empty recent view as proof of no activity |
| A caller lacks the required diagnostic permission | Live or queried diagnostic data is not available to that caller | Authenticate the caller and grant the specific read permission required by the diagnostic surface |
| A caller lacks the required permission for a retry or simulation endpoint | Retry-attempt or simulation access is denied, while strategy browsing remains available to authenticated callers | Keep the protected route's required resource and verb aligned with the matching resilience permission descriptor |
| A resilience strategy cannot be resolved | The activity may run without the intended retry policy or fail to apply the selected policy | Keep strategy identifiers, expressions, and serialized strategy definitions compatible |
| A simulation session reaches its active-session limit | The endpoint returns a rate-limit response and cannot produce the next simulated result | Bound sessions and clear inactive sessions before testing recovery paths at scale |
| A local scheduler process restarts without readable trigger or bookmark state | Future starts or resumes are not rebuilt | Preserve the stored schedule records and let startup schedule restoration run |
| A cron payload is empty or malformed | The affected trigger is skipped instead of producing future workflow work | Validate cron payloads and inspect scheduler warnings |
| A cache invalidation event is missed | A tenant can see an old definition or trigger result until cache expiry | Keep tenant-scoped keys and refresh or eviction notifications coupled to store changes |
Key files
| File | Why to read it |
|---|---|
| src/…/ConsoleLogsFeature.cs | Defines the live console-log capability and its safety and buffer controls. |
| src/…/StructuredLogsFeature.cs | Defines structured-log streaming, recent-data limits, and redaction controls. |
| src/…/OpenTelemetryFeature.cs | Shows the OpenTelemetry collection and live-query boundary. |
| src/…/OpenTelemetryIngestor.cs | Shows the order of redaction, storage, and live publication. |
| src/…/StructuredLogsDashboardContributor.cs | Shows how structured-log health and data-loss signals become dashboard findings. |
| src/…/WorkflowDashboardContributor.cs | Shows the main runtime and workflow health view. |
| src/…/ResilientActivityInvoker.cs | Shows how a resilience strategy surrounds activity work and records retries. |
| src/…/Endpoint.cs | Shows the authenticated strategy catalog surface. |
| src/…/Endpoint.cs | Shows how retry-attempt history is exposed for an activity instance. |
| src/…/Endpoint.cs | Shows the bounded, identity-scoped response simulation surface. |
| src/…/ResiliencePermissions.cs | Defines retry and simulation access rules while retaining the strategy permission for existing roles. |
| src/…/WorkflowDefinitionCacheManager.cs | Shows tenant-scoped cache identity and definition eviction. |
| src/…/CreateSchedulesStartupTask.cs | Shows how persisted timing state is restored after startup. |
| src/…/DefaultWorkflowScheduler.cs | Shows the public scheduling forms for starting and resuming workflows. |