33
44using System . Diagnostics ;
55using System . Diagnostics . Metrics ;
6+ using Microsoft . AspNetCore . Components ;
67using Microsoft . AspNetCore . Http ;
78
8- namespace Microsoft . AspNetCore . Components . Rendering ;
9+ namespace Microsoft . AspNetCore . Components ;
910
10- internal sealed class RenderingMetrics : IDisposable
11+ internal sealed class ComponentsMetrics : IDisposable
1112{
12- public const string MeterName = "Microsoft.AspNetCore.Components.Rendering " ;
13+ public const string MeterName = "Microsoft.AspNetCore.Components" ;
1314 private readonly Meter _meter ;
1415
16+ private readonly Counter < long > _navigationCount ;
17+
1518 private readonly Histogram < double > _eventSyncDuration ;
1619 private readonly Histogram < double > _eventAsyncDuration ;
1720 private readonly Counter < long > _eventException ;
@@ -25,6 +28,8 @@ internal sealed class RenderingMetrics : IDisposable
2528 private readonly Histogram < double > _batchDuration ;
2629 private readonly Counter < long > _batchException ;
2730
31+ public bool IsNavigationEnabled => _navigationCount . Enabled ;
32+
2833 public bool IsEventDurationEnabled => _eventSyncDuration . Enabled || _eventAsyncDuration . Enabled ;
2934 public bool IsEventExceptionEnabled => _eventException . Enabled ;
3035
@@ -36,43 +41,48 @@ internal sealed class RenderingMetrics : IDisposable
3641 public bool IsBatchDurationEnabled => _batchDuration . Enabled ;
3742 public bool IsBatchExceptionEnabled => _batchException . Enabled ;
3843
39- public RenderingMetrics ( IMeterFactory meterFactory )
44+ public ComponentsMetrics ( IMeterFactory meterFactory )
4045 {
4146 Debug . Assert ( meterFactory != null ) ;
4247
4348 _meter = meterFactory . Create ( MeterName ) ;
4449
50+ _navigationCount = _meter . CreateCounter < long > (
51+ "aspnetcore.components.navigation.count" ,
52+ unit : "{exceptions}" ,
53+ description : "Total number of route changes." ) ;
54+
4555 _eventSyncDuration = _meter . CreateHistogram (
46- "aspnetcore.components.rendering. event.synchronous.duration" ,
56+ "aspnetcore.components.event.synchronous.duration" ,
4757 unit : "s" ,
4858 description : "Duration of processing browser event synchronously." ,
4959 advice : new InstrumentAdvice < double > { HistogramBucketBoundaries = MetricsConstants . ShortSecondsBucketBoundaries } ) ;
5060
5161 _eventAsyncDuration = _meter . CreateHistogram (
52- "aspnetcore.components.rendering. event.asynchronous.duration" ,
62+ "aspnetcore.components.event.asynchronous.duration" ,
5363 unit : "s" ,
5464 description : "Duration of processing browser event asynchronously." ,
5565 advice : new InstrumentAdvice < double > { HistogramBucketBoundaries = MetricsConstants . ShortSecondsBucketBoundaries } ) ;
5666
5767 _eventException = _meter . CreateCounter < long > (
58- "aspnetcore.components.rendering. event.exception" ,
68+ "aspnetcore.components.event.exception" ,
5969 unit : "{exceptions}" ,
6070 description : "Total number of exceptions during browser event processing." ) ;
6171
6272 _parametersSyncDuration = _meter . CreateHistogram (
63- "aspnetcore.components.rendering. parameters.synchronous.duration" ,
73+ "aspnetcore.components.parameters.synchronous.duration" ,
6474 unit : "s" ,
6575 description : "Duration of processing component parameters synchronously." ,
6676 advice : new InstrumentAdvice < double > { HistogramBucketBoundaries = MetricsConstants . ShortSecondsBucketBoundaries } ) ;
6777
6878 _parametersAsyncDuration = _meter . CreateHistogram (
69- "aspnetcore.components.rendering. parameters.asynchronous.duration" ,
79+ "aspnetcore.components.parameters.asynchronous.duration" ,
7080 unit : "s" ,
7181 description : "Duration of processing component parameters asynchronously." ,
7282 advice : new InstrumentAdvice < double > { HistogramBucketBoundaries = MetricsConstants . ShortSecondsBucketBoundaries } ) ;
7383
7484 _parametersException = _meter . CreateCounter < long > (
75- "aspnetcore.components.rendering. parameters.exception" ,
85+ "aspnetcore.components.parameters.exception" ,
7686 unit : "{exceptions}" ,
7787 description : "Total number of exceptions during processing component parameters." ) ;
7888
@@ -94,6 +104,17 @@ public RenderingMetrics(IMeterFactory meterFactory)
94104 description : "Total number of exceptions during batch rendering." ) ;
95105 }
96106
107+ public void Navigation ( string componentType , string route )
108+ {
109+ var tags = new TagList
110+ {
111+ { "component.type" , componentType ?? "unknown" } ,
112+ { "route" , route ?? "unknown" } ,
113+ } ;
114+
115+ _navigationCount . Add ( 1 , tags ) ;
116+ }
117+
97118 public void EventDurationSync ( long startTimestamp , string ? componentType , string ? methodName , string ? attributeName )
98119 {
99120 var tags = new TagList
0 commit comments