Class WorkflowFoundryOpenTelemetryExtensions
- 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
foundryIWorkflowFoundryThe workflow foundry.
namestringThe counter name.
unitstringThe unit of measurement.
descriptionstringThe counter description.
Returns
- Counter<T>
The counter instrument or null if OpenTelemetry is not available.
Type Parameters
TThe 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
foundryIWorkflowFoundryThe workflow foundry.
namestringThe histogram name.
unitstringThe unit of measurement.
descriptionstringThe histogram description.
Returns
- Histogram<T>
The histogram instrument or null if OpenTelemetry is not available.
Type Parameters
TThe 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
foundryIWorkflowFoundryThe 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
foundryIWorkflowFoundryThe workflow foundry.
operationNamestringThe 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
foundryIWorkflowFoundryThe 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
foundryIWorkflowFoundryThe workflow foundry.
optionsWorkflowForgeOpenTelemetryOptionsConfiguration 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
foundryIWorkflowFoundryThe 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
foundryIWorkflowFoundryThe workflow foundry.
operationNamestringThe 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
foundryIWorkflowFoundryThe 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
foundryIWorkflowFoundryThe workflow foundry.
operationNamestringThe name of the operation.
durationTimeSpanThe operation duration.
successboolWhether the operation was successful.
memoryAllocatedlongMemory 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
foundryIWorkflowFoundryThe workflow foundry.
operationNamestringThe name of the operation.
kindActivityKindThe activity kind.
Returns
- Activity
The started activity or null if tracing is not available.
Exceptions
- ArgumentNullException
Thrown when foundry is null.