forked from dotnet/diagnostics
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
In .NET 8.0 we added tags on Meters and Instruments but MetricsEventSource only included the names when emitting value publishing events. This made it ambiguous when there was more than one Meter or Instrument with the same name. In 9.0 MetricsEventSource started included InstrumentIDs in the BeginInstrumentReporting events and in the value publishing events that provides a stronger correlation identifier. This change consumes the IDs in those events within Microsoft.Diagnostics.Monitoring.EventPipe, allowing dotnet-counters (and presumably dotnet-monitor too) to track time series that differ only by the tags provided to the Meter/Instrument constructors. I also re-enabled a disabled test that got broken .NET 9.0 added the System.Runtime Meter. Fixes dotnet#4843, dotnet#4564
- Loading branch information
Showing
5 changed files
with
264 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics.Metrics; | ||
|
||
|
||
|
||
namespace EventPipeTracee | ||
{ | ||
// The constructor overloads for Meter and Counter that take tags were added in .NET 8.0 | ||
// so this class is only available when built against 8.0 and later | ||
#if NET8_0_OR_GREATER | ||
internal sealed class DuplicateNameMetrics : IDisposable | ||
{ | ||
private Meter _meter1; | ||
private Meter _meter2; | ||
private Counter<int> _counter1a; | ||
private Counter<int> _counter1b; | ||
private Counter<int> _counter2a; | ||
private Counter<int> _counter2b; | ||
|
||
public DuplicateNameMetrics() | ||
{ | ||
_meter1 = new Meter("AmbiguousNameMeter", "", [new("MeterTag", "one")]); | ||
_meter2 = new Meter("AmbiguousNameMeter", "", [new("MeterTag", "two")]); | ||
_counter1a = _meter1.CreateCounter<int>("AmbiguousNameCounter", "", "", [new("InstrumentTag", "A")]); | ||
_counter1b = _meter1.CreateCounter<int>("AmbiguousNameCounter", "", "", [new("InstrumentTag", "B")]); | ||
_counter2a = _meter2.CreateCounter<int>("AmbiguousNameCounter", "", "", [new("InstrumentTag", "A")]); | ||
_counter2b = _meter2.CreateCounter<int>("AmbiguousNameCounter", "", "", [new("InstrumentTag", "B")]); | ||
} | ||
|
||
|
||
public void IncrementCounter(int v = 1) | ||
{ | ||
_counter1a.Add(v); | ||
_counter1b.Add(v + 1); | ||
_counter2a.Add(v + 2); | ||
_counter2b.Add(v + 3); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
_meter1?.Dispose(); | ||
_meter2?.Dispose(); | ||
} | ||
} | ||
#endif | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.