@@ -29,6 +29,7 @@ namespace Examples.Console;
29
29
internal class TestPrometheusExporter
30
30
{
31
31
private static readonly Meter MyMeter = new Meter ( "MyMeter" ) ;
32
+ private static readonly Meter MyMeter2 = new Meter ( "MyMeter2" ) ;
32
33
private static readonly Counter < double > Counter = MyMeter . CreateCounter < double > ( "myCounter" , description : "A counter for demonstration purpose." ) ;
33
34
private static readonly Histogram < long > MyHistogram = MyMeter . CreateHistogram < long > ( "myHistogram" ) ;
34
35
private static readonly ThreadLocal < Random > ThreadLocalRandom = new ThreadLocal < Random > ( ( ) => new Random ( ) ) ;
@@ -49,16 +50,26 @@ internal static object Run(int port)
49
50
50
51
using var meterProvider = Sdk . CreateMeterProviderBuilder ( )
51
52
. AddMeter ( MyMeter . Name )
52
- . AddPrometheusExporter ( opt =>
53
+ . AddMeter ( MyMeter2 . Name )
54
+ . AddPrometheusExporter ( options =>
53
55
{
54
- opt . StartHttpListener = true ;
55
- opt . HttpListenerPrefixes = new string [ ] { $ "http://localhost:{ port } /" } ;
56
+ options . StartHttpListener = true ;
57
+ options . HttpListenerPrefixes = new string [ ] { $ "http://localhost:{ port } /" } ;
58
+ options . ScrapeResponseCacheDurationMilliseconds = 0 ;
56
59
} )
57
60
. Build ( ) ;
58
61
59
62
var process = Process . GetCurrentProcess ( ) ;
60
63
MyMeter . CreateObservableCounter ( "thread.cpu_time" , ( ) => GetThreadCpuTime ( process ) , "ms" ) ;
61
64
65
+ // If the same Instrument name+unit combination happened under different Meters, PrometheusExporter
66
+ // exporter will output duplicated metric names. Related issues and PRs:
67
+ // * https://github.com/open-telemetry/opentelemetry-specification/pull/2017
68
+ // * https://github.com/open-telemetry/opentelemetry-specification/pull/2035
69
+ // * https://github.com/open-telemetry/opentelemetry-dotnet/pull/2593
70
+ //
71
+ // MyMeter2.CreateObservableCounter("thread.cpu_time", () => GetThreadCpuTime(process), "ms");
72
+
62
73
using var token = new CancellationTokenSource ( ) ;
63
74
64
75
Task . Run ( ( ) =>
0 commit comments