Skip to content

Add exception handler overloads to ObserveDuration#396

Merged
phnx47 merged 9 commits intomainfrom
observe-duration-exception-handler
Mar 9, 2026
Merged

Add exception handler overloads to ObserveDuration#396
phnx47 merged 9 commits intomainfrom
observe-duration-exception-handler

Conversation

@phnx47
Copy link
Copy Markdown
Member

@phnx47 phnx47 commented Mar 8, 2026

Close: #183

Add onObserveException overloads to ObserveDuration and ObserveDurationAsync, allowing exceptions from Observe to be handled separately from exceptions thrown by the measured code.

  • New overloads accept Action<Exception> onObserveException which is called only when Observe throws
  • Exceptions from the user-provided method always propagate normally
  • Existing overloads unchanged

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 8, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.33%. Comparing base (9f9a6da) to head (cc4dd2d).
⚠️ Report is 12 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #396      +/-   ##
==========================================
+ Coverage   88.83%   90.33%   +1.50%     
==========================================
  Files          48       48              
  Lines        1738     1770      +32     
  Branches      233      234       +1     
==========================================
+ Hits         1544     1599      +55     
+ Misses        141      119      -22     
+ Partials       53       52       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@phnx47 phnx47 force-pushed the observe-duration-exception-handler branch from d3e28a2 to 60f68f4 Compare March 8, 2026 13:35
@phnx47 phnx47 marked this pull request as draft March 8, 2026 13:40
@phnx47 phnx47 marked this pull request as ready for review March 9, 2026 10:18
@phnx47 phnx47 requested a review from Copilot March 9, 2026 10:18
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR extends IValueObserver duration-measurement extension methods to optionally route exceptions thrown by Observe(...) to a caller-provided exceptionHandler, while allowing exceptions from the measured user code to propagate normally.

Changes:

  • Added exceptionHandler overloads for ObserveDuration / ObserveDurationAsync (sync + generic, async + generic).
  • Introduced a shared helper to perform Observe(...) with optional exception handling.
  • Added a new test suite covering success paths, method-exception paths, and observe-exception handling behavior.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/Prometheus.Client.Abstractions/ValueObserverExtensions.cs Adds new overloads and a helper to handle exceptions thrown by Observe(...) separately from the measured method.
tests/Prometheus.Client.Tests/ValueObserverExtensionsTests.cs Adds comprehensive tests for the new overloads and preserves existing behavior expectations.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

phnx47 and others added 2 commits March 9, 2026 20:16
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

phnx47 and others added 2 commits March 9, 2026 20:40
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@phnx47 phnx47 requested a review from Copilot March 9, 2026 14:04
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@phnx47 phnx47 merged commit e401ab0 into main Mar 9, 2026
7 of 8 checks passed
@phnx47 phnx47 deleted the observe-duration-exception-handler branch March 9, 2026 14:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

ability to swallow/ignore exceptions from Observe functionality; but throw from Func

2 participants