Skip to content

[EventCounters] Do not publish extra metrics#4031

Open
martincostello wants to merge 5 commits intoopen-telemetry:mainfrom
martincostello:gh-1382
Open

[EventCounters] Do not publish extra metrics#4031
martincostello wants to merge 5 commits intoopen-telemetry:mainfrom
martincostello:gh-1382

Conversation

@martincostello
Copy link
Copy Markdown
Member

@martincostello martincostello commented Mar 27, 2026

Fixes #1382

Changes

Avoid exporting additional metrics when tools like dotnet-counters are in use.

I still need to manually verify the end-to-end fix locally. Fairly sure this is working from using dotnet-monitor against dotnet test in Visual Studio with and without the fix by hitting a debug breakpoint to dump to PID and pause it to attach it. The test fails without the fix too.

Merge requirement checklist

  • CONTRIBUTING guidelines followed (license requirements, nullable enabled, static analysis, etc.)
  • Unit tests added/updated
  • Appropriate CHANGELOG.md files updated for non-trivial changes
  • Changes in public API reviewed (if applicable)

Avoid exporting additional metrics when tools like dotnet-counters are in use.

Fixes open-telemetry#1382.
@github-actions github-actions bot added the comp:instrumentation.eventcounters Things related to OpenTelemetry.Instrumentation.EventCounters label Mar 27, 2026
@martincostello martincostello changed the title [EventCounters] Do not public extra metrics [EventCounters] Do not publish extra metrics Mar 27, 2026
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 27, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 72.08%. Comparing base (da86069) to head (a4aaf6c).
⚠️ Report is 27 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4031      +/-   ##
==========================================
+ Coverage   71.94%   72.08%   +0.14%     
==========================================
  Files         458      448      -10     
  Lines       17872    17823      -49     
==========================================
- Hits        12858    12848      -10     
+ Misses       5014     4975      -39     
Flag Coverage Δ
unittests-Instrumentation.Cassandra ?
unittests-Instrumentation.EventCounters 77.67% <100.00%> (+0.40%) ⬆️

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

Files with missing lines Coverage Δ
...entCounters/EventCountersInstrumentationOptions.cs 100.00% <100.00%> (ø)
...trumentation.EventCounters/EventCountersMetrics.cs 82.95% <100.00%> (+0.19%) ⬆️

... and 10 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.

Use expression-bodied method.
@martincostello martincostello marked this pull request as ready for review March 30, 2026 10:09
@martincostello martincostello requested a review from a team as a code owner March 30, 2026 10:09
Copilot AI review requested due to automatic review settings March 30, 2026 10:09
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

Prevents OpenTelemetry.Instrumentation.EventCounters from exporting metrics for EventSources that were not explicitly configured, addressing the reported behavior when external tools (e.g., dotnet-counters) enable additional sources.

Changes:

  • Add a configuration guard in OnEventWritten to ignore events from non-configured EventSources.
  • Update/refactor existing unit tests and add a new regression test ensuring only configured sources emit metrics.
  • Document the fix in the EventCounters instrumentation changelog.

Reviewed changes

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

File Description
test/OpenTelemetry.Instrumentation.EventCounters.Tests/EventCountersMetricsTests.cs Refactors provider lifetimes in tests and adds a regression test for “only configured sources emit metrics”.
src/OpenTelemetry.Instrumentation.EventCounters/EventCountersMetrics.cs Filters OnEventWritten to process only configured EventSources, preventing extra metrics emission.
src/OpenTelemetry.Instrumentation.EventCounters/CHANGELOG.md Adds an Unreleased changelog entry describing the fix.

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

Address Copilot review comment.
Copy the list on write instead of mutating the reference.
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 7, 2026

This PR was marked stale due to lack of activity. It will be closed in 7 days.

@github-actions github-actions bot added the Stale label Apr 7, 2026
@Kielek
Copy link
Copy Markdown
Member

Kielek commented Apr 7, 2026

@hananiel, @mic-max could you please take a look here?

@Kielek Kielek removed the Stale label Apr 7, 2026
@martincostello martincostello added the keep-open Prevents issues and pull requests being closed as stale label Apr 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp:instrumentation.eventcounters Things related to OpenTelemetry.Instrumentation.EventCounters keep-open Prevents issues and pull requests being closed as stale

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Additional metrics are emitted when "dotnet-counters" tool is used for the running process

5 participants