Skip to content

[Instrumentation.Hangfire] Add metrics support#3258

Merged
Kielek merged 55 commits into
open-telemetry:mainfrom
gorbach:feature/2075-hangfire-telemetry
Nov 24, 2025
Merged

[Instrumentation.Hangfire] Add metrics support#3258
Kielek merged 55 commits into
open-telemetry:mainfrom
gorbach:feature/2075-hangfire-telemetry

Conversation

@gorbach
Copy link
Copy Markdown
Contributor

@gorbach gorbach commented Oct 21, 2025

Fixes #2075

Changes

Adds OpenTelemetry metrics support to Hangfire instrumentation following workflow semantic conventions.

Implemented metrics:

  • workflow.execution.count - Counter for task executions
  • workflow.execution.duration - Histogram for execution duration
  • workflow.execution.status - UpDownCounter for state transitions
  • workflow.execution.errors - Counter for execution errors
  • hangfire.queue.latency - Optional histogram for queue wait time

Merge requirement checklist

  • CONTRIBUTING guidelines followed
  • Unit tests added/updated
  • CHANGELOG.md updated
  • Changes in public API reviewed

@gorbach gorbach requested a review from a team as a code owner October 21, 2025 18:51
@linux-foundation-easycla
Copy link
Copy Markdown

linux-foundation-easycla Bot commented Oct 21, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

@github-actions github-actions Bot requested a review from fred2u October 21, 2025 18:51
@github-actions github-actions Bot added the comp:instrumentation.hangfire Things related to OpenTelemetry.Instrumentation.Hangfire label Oct 21, 2025
@gorbach gorbach force-pushed the feature/2075-hangfire-telemetry branch from 289b75d to 5655113 Compare October 21, 2025 19:55
Copy link
Copy Markdown
Contributor

@thompson-tomo thompson-tomo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks to be a good step forward and I have suggested a couple of changes here as well as to the sem conv based on the learnings.

Comment thread src/OpenTelemetry.Instrumentation.Hangfire/Implementation/HangfireMetrics.cs Outdated
Comment thread src/OpenTelemetry.Instrumentation.Hangfire/Implementation/HangfireTagBuilder.cs Outdated
@Kielek
Copy link
Copy Markdown
Member

Kielek commented Oct 22, 2025

@gorbach, please check this comment #2075 (comment)

The second point is technical requirements to separate metrics/traces signal. It will be great to rename classes in the separate PR and then merge it/rebase here.

@gorbach gorbach requested a review from thompson-tomo October 22, 2025 22:41
Implements OpenTelemetry workflow semantic conventions for Hangfire metrics.

Fixes open-telemetry#2075
…ve trigger.type to workflow-level metrics, add workflow.count
@gorbach gorbach force-pushed the feature/2075-hangfire-telemetry branch from dd6e74a to d43ee2c Compare October 22, 2025 22:42
Copy link
Copy Markdown
Contributor

@thompson-tomo thompson-tomo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good. Only 1 design question #3258 (comment) which when resolved would mean I approve.

Comment thread src/OpenTelemetry.Instrumentation.Hangfire/Implementation/HangfireTagBuilder.cs Outdated
Copy link
Copy Markdown
Contributor

@thompson-tomo thompson-tomo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have left a bunch of nits for things which could be improved/simplified.

Comment thread src/OpenTelemetry.Instrumentation.Hangfire/Implementation/HangfireTagBuilder.cs Outdated
Comment thread src/OpenTelemetry.Instrumentation.Hangfire/Implementation/HangfireTagBuilder.cs Outdated
gorbach and others added 9 commits October 26, 2025 08:45
…fireMetricsErrorFilterAttribute.cs

Co-authored-by: James Thompson <thompson.tomo@outlook.com>
…fireMetricsInstrumentation.cs

Co-authored-by: James Thompson <thompson.tomo@outlook.com>
…fireMetricsStateFilter.cs

Co-authored-by: James Thompson <thompson.tomo@outlook.com>
…fireMetricsStateFilter.cs

Co-authored-by: James Thompson <thompson.tomo@outlook.com>
…fireTagBuilder.cs

Co-authored-by: James Thompson <thompson.tomo@outlook.com>
…fireMetricsStateFilter.cs

Co-authored-by: James Thompson <thompson.tomo@outlook.com>
…fireMetricsErrorFilterAttribute.cs

Co-authored-by: James Thompson <thompson.tomo@outlook.com>
…fireTagBuilder.cs

Co-authored-by: James Thompson <thompson.tomo@outlook.com>
…fireMetricsStateFilter.cs

Co-authored-by: James Thompson <thompson.tomo@outlook.com>
@gorbach
Copy link
Copy Markdown
Contributor Author

gorbach commented Nov 18, 2025

I beleive I've fixed all linter warnings, compilation errors (in release) and ran dotnet format for tests and code.

@codecov
Copy link
Copy Markdown

codecov Bot commented Nov 19, 2025

Codecov Report

❌ Patch coverage is 85.76159% with 43 lines in your changes missing coverage. Please review.
✅ Project coverage is 71.21%. Comparing base (55aa86e) to head (aa2d422).
⚠️ Report is 2 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...entation.Hangfire/Implementation/TypeExtensions.cs 33.33% 16 Missing ⚠️
...gfire/Implementation/HangfireMetricsStateFilter.cs 77.96% 13 Missing ⚠️
...tion.Hangfire/Implementation/HangfireTagBuilder.cs 89.47% 8 Missing ⚠️
...entation/HangfirePendingDurationFilterAttribute.cs 84.61% 4 Missing ⚠️
...mplementation/HangfireMetricsJobFilterAttribute.cs 92.85% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3258      +/-   ##
==========================================
+ Coverage   70.80%   71.21%   +0.40%     
==========================================
  Files         440      442       +2     
  Lines       17265    17516     +251     
==========================================
+ Hits        12225    12474     +249     
- Misses       5040     5042       +2     
Flag Coverage Δ
unittests-Instrumentation.Cassandra ?
unittests-Instrumentation.Hangfire 86.05% <85.76%> (+1.43%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
....Hangfire/HangfireMetricsInstrumentationOptions.cs 100.00% <100.00%> (ø)
...ntation.Hangfire/Implementation/HangfireMetrics.cs 100.00% <100.00%> (ø)
...lementation/HangfireMetricsErrorFilterAttribute.cs 100.00% <100.00%> (ø)
...e/Implementation/HangfireMetricsInstrumentation.cs 100.00% <100.00%> (ø)
...ion.Hangfire/Implementation/HangfireStateMapper.cs 100.00% <100.00%> (ø)
...tation.Hangfire/Implementation/JobNameFormatter.cs 100.00% <100.00%> (ø)
...ntation.Hangfire/MeterProviderBuilderExtensions.cs 100.00% <100.00%> (ø)
...mplementation/HangfireMetricsJobFilterAttribute.cs 92.85% <92.85%> (ø)
...entation/HangfirePendingDurationFilterAttribute.cs 84.61% <84.61%> (ø)
...tion.Hangfire/Implementation/HangfireTagBuilder.cs 89.47% <89.47%> (ø)
... and 2 more

... and 11 files with indirect coverage changes

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Contributor

@thompson-tomo thompson-tomo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note these changes would be necessary once #3545 is merged so might be better to merge them now. Could a maintainer commit my suggestions?

Comment thread src/OpenTelemetry.Instrumentation.Hangfire/README.md Outdated
Comment thread src/OpenTelemetry.Instrumentation.Hangfire/README.md Outdated
Comment thread src/OpenTelemetry.Instrumentation.Hangfire/README.md Outdated
Comment thread src/OpenTelemetry.Instrumentation.Hangfire/README.md Outdated
Comment thread src/OpenTelemetry.Instrumentation.Hangfire/README.md Outdated
Comment thread src/OpenTelemetry.Instrumentation.Hangfire/README.md Outdated
Comment thread src/OpenTelemetry.Instrumentation.Hangfire/README.md Outdated
Comment thread src/OpenTelemetry.Instrumentation.Hangfire/README.md Outdated
Comment thread src/OpenTelemetry.Instrumentation.Hangfire/README.md Outdated
Comment thread src/OpenTelemetry.Instrumentation.Hangfire/README.md Outdated
gorbach and others added 12 commits November 20, 2025 09:27
Co-authored-by: James Thompson <thompson.tomo@outlook.com>
Co-authored-by: James Thompson <thompson.tomo@outlook.com>
Co-authored-by: James Thompson <thompson.tomo@outlook.com>
Co-authored-by: James Thompson <thompson.tomo@outlook.com>
Co-authored-by: James Thompson <thompson.tomo@outlook.com>
Co-authored-by: James Thompson <thompson.tomo@outlook.com>
Co-authored-by: James Thompson <thompson.tomo@outlook.com>
Co-authored-by: James Thompson <thompson.tomo@outlook.com>
Co-authored-by: James Thompson <thompson.tomo@outlook.com>
Co-authored-by: James Thompson <thompson.tomo@outlook.com>
@Kielek Kielek force-pushed the feature/2075-hangfire-telemetry branch from 261c8c5 to aa2d422 Compare November 21, 2025 07:54
Copy link
Copy Markdown
Member

@Kielek Kielek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTMRS

@Kielek Kielek added this pull request to the merge queue Nov 24, 2025
Merged via the queue into open-telemetry:main with commit 6199c63 Nov 24, 2025
67 checks passed
@problesal-sacyr
Copy link
Copy Markdown

Hi, when's this hitting NuGet? Thanks!

@Kielek
Copy link
Copy Markdown
Member

Kielek commented Jan 14, 2026

Someone needs to create https://github.com/open-telemetry/opentelemetry-dotnet-contrib/issues/new?template=release_request.yml. Probably 1.14.0-beta.2 version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp:instrumentation.hangfire Things related to OpenTelemetry.Instrumentation.Hangfire

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for metrics in OpenTelemetry.Instrumentation.Hangfire

5 participants