@@ -12,18 +12,18 @@ namespace OpenTelemetry.Instrumentation.Hangfire.Implementation;
1212/// </summary>
1313internal static class HangfireMetrics
1414{
15- private static readonly Assembly Assembly = typeof ( HangfireMetrics ) . Assembly ;
16- private static readonly AssemblyName AssemblyName = Assembly . GetName ( ) ;
17- internal static readonly string MeterName = AssemblyName . Name ! ;
18- private static readonly string InstrumentationVersion = Assembly . GetPackageVersion ( ) ;
19-
2015 // Metric name constants
2116 internal const string ExecutionCountMetricName = "workflow.execution.count" ;
2217 internal const string ExecutionDurationMetricName = "workflow.execution.duration" ;
2318 internal const string ExecutionStatusMetricName = "workflow.execution.status" ;
2419 internal const string ExecutionErrorsMetricName = "workflow.execution.errors" ;
20+ internal const string WorkflowCountMetricName = "workflow.count" ;
2521
26- internal const string QueueLatencyMetricName = "hangfire.queue.latency" ;
22+ internal static readonly Assembly Assembly = typeof ( HangfireMetrics ) . Assembly ;
23+ internal static readonly AssemblyName AssemblyName = Assembly . GetName ( ) ;
24+ internal static readonly string MeterName = AssemblyName . Name ! ;
25+
26+ private static readonly string InstrumentationVersion = Assembly . GetPackageVersion ( ) ;
2727
2828 /// <summary>
2929 /// The meter instance for all Hangfire metrics.
@@ -35,38 +35,52 @@ internal static class HangfireMetrics
3535 /// Follows OpenTelemetry workflow semantic conventions.
3636 /// </summary>
3737 public static readonly Counter < long > ExecutionCount =
38- Meter . CreateCounter < long > ( ExecutionCountMetricName , unit : "{executions}" ,
38+ Meter . CreateCounter < long > (
39+ ExecutionCountMetricName ,
40+ unit : "{executions}" ,
3941 description : "The number of task executions which have been initiated." ) ;
4042
4143 /// <summary>
4244 /// Histogram for duration of an execution grouped by task, type and result.
4345 /// Follows OpenTelemetry workflow semantic conventions.
46+ /// Records duration for different execution phases using workflow.execution.state attribute:
47+ /// - state=pending: Time spent waiting in queue before execution.
48+ /// - state=executing: Time spent in actual execution.
4449 /// </summary>
4550 public static readonly Histogram < double > ExecutionDuration =
46- Meter . CreateHistogram < double > ( ExecutionDurationMetricName , unit : "s" ,
51+ Meter . CreateHistogram < double > (
52+ ExecutionDurationMetricName ,
53+ unit : "s" ,
4754 description : "Duration of an execution grouped by task, type and result." ) ;
4855
4956 /// <summary>
5057 /// UpDownCounter for the number of actively running tasks grouped by task and state.
5158 /// Follows OpenTelemetry workflow semantic conventions.
5259 /// </summary>
5360 public static readonly UpDownCounter < long > ExecutionStatus =
54- Meter . CreateUpDownCounter < long > ( ExecutionStatusMetricName , unit : "{executions}" ,
61+ Meter . CreateUpDownCounter < long > (
62+ ExecutionStatusMetricName ,
63+ unit : "{executions}" ,
5564 description : "The number of actively running tasks grouped by task, type and the current state." ) ;
5665
5766 /// <summary>
5867 /// Counter for the number of errors encountered in task runs (eg. compile, test failures).
5968 /// Follows OpenTelemetry workflow semantic conventions.
6069 /// </summary>
6170 public static readonly Counter < long > ExecutionErrors =
62- Meter . CreateCounter < long > ( ExecutionErrorsMetricName , unit : "{error}" ,
71+ Meter . CreateCounter < long > (
72+ ExecutionErrorsMetricName ,
73+ unit : "{error}" ,
6374 description : "The number of errors encountered in task runs (eg. compile, test failures)." ) ;
6475
6576 /// <summary>
66- /// Histogram for time tasks spend waiting in queue before execution.
67- /// Hangfire-specific metric (not part of standard workflow conventions).
77+ /// Counter for the number of workflow instances which have been initiated.
78+ /// Follows OpenTelemetry workflow semantic conventions.
79+ /// In Hangfire, this tracks individual job completions. For batch workflows, this would track batch completion.
6880 /// </summary>
69- public static readonly Histogram < double > QueueLatency =
70- Meter . CreateHistogram < double > ( QueueLatencyMetricName , unit : "s" ,
71- description : "Time tasks spend waiting in queue before execution starts." ) ;
81+ public static readonly Counter < long > WorkflowCount =
82+ Meter . CreateCounter < long > (
83+ WorkflowCountMetricName ,
84+ unit : "{workflows}" ,
85+ description : "The number of workflow instances which have been initiated." ) ;
7286}
0 commit comments