Table of Contents

Class WorkflowForgeOpenTelemetryService

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

Comprehensive OpenTelemetry service providing both distributed tracing and metrics for WorkflowForge applications using industry-standard OpenTelemetry APIs.

public sealed class WorkflowForgeOpenTelemetryService : IDisposable
Inheritance
WorkflowForgeOpenTelemetryService
Implements
Inherited Members

Constructors

WorkflowForgeOpenTelemetryService(string, string, IWorkflowForgeLogger?)

Initializes a new instance of the WorkflowForgeOpenTelemetryService.

public WorkflowForgeOpenTelemetryService(string serviceName, string serviceVersion = "1.0.0", IWorkflowForgeLogger? logger = null)

Parameters

serviceName string

The service name for OpenTelemetry identification.

serviceVersion string

The service version.

logger IWorkflowForgeLogger

The logger instance.

WorkflowForgeOpenTelemetryService(WorkflowForgeOpenTelemetryOptions, IWorkflowForgeLogger?)

Initializes a new instance of the WorkflowForgeOpenTelemetryService from options.

public WorkflowForgeOpenTelemetryService(WorkflowForgeOpenTelemetryOptions options, IWorkflowForgeLogger? logger = null)

Parameters

options WorkflowForgeOpenTelemetryOptions

The telemetry options.

logger IWorkflowForgeLogger

The logger instance.

Exceptions

ArgumentNullException

Thrown when options or its service name is null.

Properties

ActivitySource

Gets the ActivitySource for creating spans and traces.

public ActivitySource ActivitySource { get; }

Property Value

ActivitySource

Meter

Gets the Meter for creating metrics instruments.

public Meter Meter { get; }

Property Value

Meter

Options

Gets the options this service was created with.

public WorkflowForgeOpenTelemetryOptions Options { get; }

Property Value

WorkflowForgeOpenTelemetryOptions

ServiceName

Gets the service name used for OpenTelemetry resource identification.

public string ServiceName { get; }

Property Value

string

SystemMetricsRegistered

Gets whether system metric gauges were registered for this service.

public bool SystemMetricsRegistered { get; }

Property Value

bool

Methods

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

Creates a custom counter metric.

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

Parameters

name string

The counter name.

unit string

The unit of measurement.

description string

The counter description.

Returns

Counter<T>

The counter instrument.

Type Parameters

T

The counter value type.

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

Creates a custom histogram metric.

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

Parameters

name string

The histogram name.

unit string

The unit of measurement.

description string

The histogram description.

Returns

Histogram<T>

The histogram instrument.

Type Parameters

T

The histogram value type.

CreateObservableGauge<T>(string, Func<T>, string?, string?)

Creates a custom observable gauge metric.

public ObservableGauge<T> CreateObservableGauge<T>(string name, Func<T> observeValue, string? unit = null, string? description = null) where T : struct

Parameters

name string

The gauge name.

observeValue Func<T>

The function to observe the value.

unit string

The unit of measurement.

description string

The gauge description.

Returns

ObservableGauge<T>

The observable gauge instrument.

Type Parameters

T

The gauge value type.

CreateUpDownCounter<T>(string, string?, string?)

Creates a custom up-down counter metric.

public UpDownCounter<T> CreateUpDownCounter<T>(string name, string? unit = null, string? description = null) where T : struct

Parameters

name string

The counter name.

unit string

The unit of measurement.

description string

The counter description.

Returns

UpDownCounter<T>

The up-down counter instrument.

Type Parameters

T

The counter value type.

DecrementActiveOperations(string, KeyValuePair<string, object?>[]?)

Decrements the active operations counter.

public void DecrementActiveOperations(string operationName, KeyValuePair<string, object?>[]? tags = null)

Parameters

operationName string

The name of the operation.

tags KeyValuePair<string, object>[]

Additional tags for the metric.

Dispose()

Disposes the OpenTelemetry service and releases resources.

public void Dispose()

IncrementActiveOperations(string, KeyValuePair<string, object?>[]?)

Increments the active operations counter.

public void IncrementActiveOperations(string operationName, KeyValuePair<string, object?>[]? tags = null)

Parameters

operationName string

The name of the operation.

tags KeyValuePair<string, object>[]

Additional tags for the metric.

RecordOperation(string, TimeSpan, bool, long, KeyValuePair<string, object?>[]?)

Records metrics for an operation execution.

public void RecordOperation(string operationName, TimeSpan duration, bool success, long memoryAllocated = 0, KeyValuePair<string, object?>[]? tags = null)

Parameters

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 KeyValuePair<string, object>[]

Additional tags for the metrics.

StartActivity(string, ActivityKind)

Starts a new activity (span) for distributed tracing.

public Activity? StartActivity(string operationName, ActivityKind kind = ActivityKind.Internal)

Parameters

operationName string

The name of the operation.

kind ActivityKind

The activity kind.

Returns

Activity

The started activity or null if not sampled.