@@ -20,6 +20,7 @@ internal sealed class ComponentsMetrics : IDisposable
2020    private  readonly  Histogram < double >  _eventDuration ; 
2121    private  readonly  Histogram < double >  _parametersDuration ; 
2222    private  readonly  Histogram < double >  _batchDuration ; 
23+     private  readonly  Histogram < int >  _batchSize ; 
2324
2425    public  bool  IsNavigationEnabled  =>  _navigationCount . Enabled ; 
2526
@@ -37,27 +38,33 @@ public ComponentsMetrics(IMeterFactory meterFactory)
3738        _lifeCycleMeter  =  meterFactory . Create ( LifecycleMeterName ) ; 
3839
3940        _navigationCount  =  _meter . CreateCounter < long > ( 
40-             "aspnetcore.components.navigation " , 
41+             "aspnetcore.components.navigate " , 
4142            unit :  "{route}" , 
4243            description :  "Total number of route changes." ) ; 
4344
4445        _eventDuration  =  _meter . CreateHistogram ( 
45-             "aspnetcore.components.event_handler " , 
46+             "aspnetcore.components.handle_event.duration " , 
4647            unit :  "s" , 
4748            description :  "Duration of processing browser event.  It includes business logic of the component but not affected child components." , 
4849            advice :  new  InstrumentAdvice < double >  {  HistogramBucketBoundaries  =  MetricsConstants . ShortSecondsBucketBoundaries  } ) ; 
4950
5051        _parametersDuration  =  _lifeCycleMeter . CreateHistogram ( 
51-             "aspnetcore.components.update_parameters" , 
52+             "aspnetcore.components.update_parameters.duration " , 
5253            unit :  "s" , 
5354            description :  "Duration of processing component parameters. It includes business logic of the component." , 
5455            advice :  new  InstrumentAdvice < double >  {  HistogramBucketBoundaries  =  MetricsConstants . BlazorRenderingSecondsBucketBoundaries  } ) ; 
5556
5657        _batchDuration  =  _lifeCycleMeter . CreateHistogram ( 
57-             "aspnetcore.components.render_diff" , 
58+             "aspnetcore.components.render_diff.duration " , 
5859            unit :  "s" , 
5960            description :  "Duration of rendering component tree and producing HTML diff. It includes business logic of the changed components." , 
6061            advice :  new  InstrumentAdvice < double >  {  HistogramBucketBoundaries  =  MetricsConstants . BlazorRenderingSecondsBucketBoundaries  } ) ; 
62+ 
63+         _batchSize  =  _lifeCycleMeter . CreateHistogram ( 
64+             "aspnetcore.components.render_diff.size" , 
65+             unit :  "{elements}" , 
66+             description :  "Number of HTML elements modified during a rendering batch." , 
67+             advice :  new  InstrumentAdvice < int >  {  HistogramBucketBoundaries  =  MetricsConstants . BlazorRenderingDiffLengthBucketBoundaries  } ) ; 
6168    } 
6269
6370    public  void  Navigation ( string  componentType ,  string  route ) 
@@ -137,10 +144,7 @@ public void FailParametersSync(Exception ex, long startTimestamp, string? compon
137144
138145    public  async  Task  CaptureBatchDuration ( Task  task ,  long  startTimestamp ,  int  diffLength ) 
139146    { 
140-         var  tags  =  new  TagList 
141-         { 
142-             {  "aspnetcore.components.diff.length" ,  BucketDiffLength ( diffLength )  } 
143-         } ; 
147+         var  tags  =  new  TagList ( ) ; 
144148
145149        try 
146150        { 
@@ -152,37 +156,19 @@ public async Task CaptureBatchDuration(Task task, long startTimestamp, int diffL
152156        } 
153157        var  duration  =  Stopwatch . GetElapsedTime ( startTimestamp ) ; 
154158        _batchDuration . Record ( duration . TotalSeconds ,  tags ) ; 
159+         _batchSize . Record ( diffLength ,  tags ) ; 
155160    } 
156161
157162    public  void  FailBatchSync ( Exception  ex ,  long  startTimestamp ) 
158163    { 
159164        var  duration  =  Stopwatch . GetElapsedTime ( startTimestamp ) ; 
160165        var  tags  =  new  TagList 
161166            { 
162-                 {  "aspnetcore.components.diff.length" ,  0  } , 
163167                {  "error.type" ,  ex . GetType ( ) . FullName  ??  "unknown"  } 
164168            } ; 
165169        _batchDuration . Record ( duration . TotalSeconds ,  tags ) ; 
166170    } 
167171
168-     private  static int  BucketDiffLength ( int  diffLength ) 
169-     { 
170-         return  diffLength  switch 
171-         { 
172-             <=  1  =>  1 , 
173-             <=  2  =>  2 , 
174-             <=  5  =>  5 , 
175-             <=  10  =>  10 , 
176-             <=  20  =>  20 , 
177-             <=  50  =>  50 , 
178-             <=  100  =>  100 , 
179-             <=  500  =>  500 , 
180-             <=  1000  =>  1000 , 
181-             <=  10000  =>  10000 , 
182-             _ =>  10001 , 
183-         } ; 
184-     } 
185- 
186172    public  void  Dispose ( ) 
187173    { 
188174        _meter . Dispose ( ) ; 
0 commit comments