[EventCounters] Do not publish extra metrics#4031
[EventCounters] Do not publish extra metrics#4031martincostello wants to merge 5 commits intoopen-telemetry:mainfrom
Conversation
Avoid exporting additional metrics when tools like dotnet-counters are in use. Fixes open-telemetry#1382.
Add PR number.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ 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
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
Use expression-bodied method.
There was a problem hiding this comment.
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
OnEventWrittento 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.
test/OpenTelemetry.Instrumentation.EventCounters.Tests/EventCountersMetricsTests.cs
Show resolved
Hide resolved
Address Copilot review comment.
Copy the list on write instead of mutating the reference.
|
This PR was marked stale due to lack of activity. It will be closed in 7 days. |
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 usingdotnet-monitoragainst 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
CHANGELOG.mdfiles updated for non-trivial changesChanges in public API reviewed (if applicable)