Table of Contents

Class WorkflowFoundryOpenTelemetryExtensions

Namespace
WorkflowForge.Extensions.Observability.OpenTelemetry
Assembly
WorkflowForge.Extensions.Observability.OpenTelemetry.dll

Extension methods that add comprehensive OpenTelemetry observability capabilities to WorkflowFoundry. Provides both distributed tracing and metrics in a unified experience.

public static class WorkflowFoundryOpenTelemetryExtensions
Inheritance
WorkflowFoundryOpenTelemetryExtensions
Inherited Members

Methods

CreateCounter<T>(IWorkflowFoundry, string, string?, string?)

Creates a custom counter metric through the OpenTelemetry service.

public static Counter<T>? CreateCounter<T>(this IWorkflowFoundry foundry, string name, string? unit = null, string? description = null) where T : struct

Parameters

foundry IWorkflowFoundry

The workflow foundry.

name string

The counter name.

unit string

The unit of measurement.

description string

The counter description.

Returns

Counter<T>

The counter instrument or null if OpenTelemetry is not available.

Type Parameters

T

The counter value type.

Exceptions

ArgumentNullException

Thrown when foundry is null.

CreateHistogram<T>(IWorkflowFoundry, string, string?, string?)

Creates a custom histogram metric through the OpenTelemetry service.

public static Histogram<T>? CreateHistogram<T>(this IWorkflowFoundry foundry, string name, string? unit = null, string? description = null) where T : struct

Parameters

foundry IWorkflowFoundry

The workflow foundry.

name string

The histogram name.

unit string

The unit of measurement.

description string

The histogram description.

Returns

Histogram<T>

The histogram instrument or null if OpenTelemetry is not available.

Type Parameters

T

The histogram value type.

Exceptions

ArgumentNullException

Thrown when foundry is null.

CreateOpenTelemetryWorkflowMiddleware(IWorkflowFoundry)

Creates the workflow-level middleware that parents the per-operation spans. Register it with smith.AddWorkflowMiddleware(...).

public static OpenTelemetryWorkflowMiddleware? CreateOpenTelemetryWorkflowMiddleware(this IWorkflowFoundry foundry)

Parameters

foundry IWorkflowFoundry

The workflow foundry.

Returns

OpenTelemetryWorkflowMiddleware

The middleware, or null when OpenTelemetry is not enabled for the foundry.

Exceptions

ArgumentNullException

Thrown when foundry is null.

DecrementActiveOperations(IWorkflowFoundry, string, params (string Key, object? Value)[])

Decrements the active operations counter when operations complete.

public static void DecrementActiveOperations(this IWorkflowFoundry foundry, string operationName, params (string Key, object? Value)[] tags)

Parameters

foundry IWorkflowFoundry

The workflow foundry.

operationName string

The name of the operation.

tags (string Key, object Value)[]

Additional tags for the metric.

Exceptions

ArgumentNullException

Thrown when foundry is null.

DisableOpenTelemetry(IWorkflowFoundry)

Disables OpenTelemetry observability for the foundry and unregisters its operation middleware, so a later EnableOpenTelemetry(IWorkflowFoundry, WorkflowForgeOpenTelemetryOptions?) call does not accumulate a second middleware instance in the pipeline.

public static bool DisableOpenTelemetry(this IWorkflowFoundry foundry)

Parameters

foundry IWorkflowFoundry

The workflow foundry.

Returns

bool

True if OpenTelemetry was disabled successfully; otherwise, false.

Exceptions

ArgumentNullException

Thrown when foundry is null.

EnableOpenTelemetry(IWorkflowFoundry, WorkflowForgeOpenTelemetryOptions?)

Enables OpenTelemetry observability for the foundry and registers the middleware that emits one span and one set of metrics per operation. The consumer owns the OpenTelemetry SDK and subscribes with .AddSource(serviceName) and .AddMeter(serviceName).

public static bool EnableOpenTelemetry(this IWorkflowFoundry foundry, WorkflowForgeOpenTelemetryOptions? options = null)

Parameters

foundry IWorkflowFoundry

The workflow foundry.

options WorkflowForgeOpenTelemetryOptions

Configuration options for OpenTelemetry.

Returns

bool

True if OpenTelemetry was enabled successfully; otherwise, false.

Exceptions

ArgumentNullException

Thrown when foundry is null.

GetOpenTelemetryService(IWorkflowFoundry)

Gets the OpenTelemetry service from the foundry.

public static WorkflowForgeOpenTelemetryService? GetOpenTelemetryService(this IWorkflowFoundry foundry)

Parameters

foundry IWorkflowFoundry

The workflow foundry.

Returns

WorkflowForgeOpenTelemetryService

The OpenTelemetry service or null if not available.

Exceptions

ArgumentNullException

Thrown when foundry is null.

IncrementActiveOperations(IWorkflowFoundry, string, params (string Key, object? Value)[])

Increments the active operations counter for tracking concurrent operations.

public static void IncrementActiveOperations(this IWorkflowFoundry foundry, string operationName, params (string Key, object? Value)[] tags)

Parameters

foundry IWorkflowFoundry

The workflow foundry.

operationName string

The name of the operation.

tags (string Key, object Value)[]

Additional tags for the metric.

Exceptions

ArgumentNullException

Thrown when foundry is null.

IsOpenTelemetryEnabled(IWorkflowFoundry)

Checks if OpenTelemetry observability is currently enabled for the foundry.

public static bool IsOpenTelemetryEnabled(this IWorkflowFoundry foundry)

Parameters

foundry IWorkflowFoundry

The workflow foundry.

Returns

bool

True if OpenTelemetry is enabled; otherwise, false.

Exceptions

ArgumentNullException

Thrown when foundry is null.

RecordOperationMetrics(IWorkflowFoundry, string, TimeSpan, bool, long, params (string Key, object? Value)[])

Records comprehensive metrics for an operation execution.

public static void RecordOperationMetrics(this IWorkflowFoundry foundry, string operationName, TimeSpan duration, bool success, long memoryAllocated = 0, params (string Key, object? Value)[] tags)

Parameters

foundry IWorkflowFoundry

The workflow foundry.

operationName string

The name of the operation.

duration TimeSpan

The operation duration.

success bool

Whether the operation was successful.

memoryAllocated long

Memory allocated during the operation.

tags (string Key, object Value)[]

Additional tags for the metrics.

Exceptions

ArgumentNullException

Thrown when foundry is null.

StartActivity(IWorkflowFoundry, string, ActivityKind)

Starts a new distributed tracing activity (span) for an operation.

public static Activity? StartActivity(this IWorkflowFoundry foundry, string operationName, ActivityKind kind = ActivityKind.Internal)

Parameters

foundry IWorkflowFoundry

The workflow foundry.

operationName string

The name of the operation.

kind ActivityKind

The activity kind.

Returns

Activity

The started activity or null if tracing is not available.

Exceptions

ArgumentNullException

Thrown when foundry is null.