Skip to content

6.6. OpenTelemetry

Mikołaj Milewski edited this page Nov 12, 2026 · 1 revision

OpenTelemetry

Stateflows.Extensions.OpenTelemetry instruments State Machine, Activity, Action, and Entity execution for OpenTelemetry. It registers Stateflows observers and interceptors, an ActivitySource, and a Meter; the host remains responsible for choosing and configuring exporters.

Register the extension as part of Stateflows setup:

services.AddStateflows(stateflows => stateflows
    .AddOpenTelemetry()
    .AddStateMachines(machines => machines
        .AddStateMachine<Order>()));

The extension integrates its meter and trace source with the .NET OpenTelemetry SDK. Configure exporters and any additional resource attributes using the application's usual OpenTelemetry setup. Add a listener/exporter for the Stateflows activity source to collect traces.

The Stateflows meter reports resource execution counts, execution duration, and active/waiting execution gauges. Trace spans describe State Machine event processing and its transitions, and the other behavior tracers cover their respective behavior executions. Events marked [NoTracing] or carrying the NoTracing header can opt out of tracing.

The source also registers the Stateflows.Orleans meter name to make Orleans runtime instruments observable through the SDK when that runtime is used. This package adds instrumentation only; it does not configure a backend or exporter. See the extension source.

Configure an exporter

For local diagnostics, install OpenTelemetry.Exporter.Console and add exporters to the same service collection:

using OpenTelemetry.Metrics;
using OpenTelemetry.Trace;

services.AddOpenTelemetry()
    .WithTracing(tracing => tracing.AddConsoleExporter())
    .WithMetrics(metrics => metrics.AddConsoleExporter());

This supplements the Stateflows extension registration above: its AddSource and AddMeter configuration is already registered. The host controls export destinations, sampling, resource attributes, and production credentials; console export is a local demonstration, not a production backend configuration.

Clone this wiki locally