File tree Expand file tree Collapse file tree
src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/Shared/Serialization Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -101,6 +101,8 @@ internal abstract class TextFormatSerializer
101101
102102 private string [ ] ? reservedExemplarOutputKeys ;
103103
104+ private int serializedTagsBufferHint = 256 ;
105+
104106 public static OpenMetricsV0Serializer OpenMetricsV0 => field ??= new ( ) ;
105107
106108 public static OpenMetricsV1Serializer OpenMetricsV1 => field ??= new ( ) ;
@@ -987,7 +989,7 @@ internal byte[] SerializeTagsToPooledBuffer(
987989 out int length )
988990 {
989991 var pool = ArrayPool < byte > . Shared ;
990- var buffer = pool . Rent ( 128 ) ;
992+ var buffer = pool . Rent ( Volatile . Read ( ref this . serializedTagsBufferHint ) ) ;
991993
992994 while ( true )
993995 {
@@ -1009,6 +1011,11 @@ internal byte[] SerializeTagsToPooledBuffer(
10091011
10101012 length = cursor ;
10111013
1014+ if ( buffer . Length > Volatile . Read ( ref this . serializedTagsBufferHint ) )
1015+ {
1016+ Volatile . Write ( ref this . serializedTagsBufferHint , buffer . Length ) ;
1017+ }
1018+
10121019 return buffer ;
10131020 }
10141021 catch ( Exception ex ) when ( ex is IndexOutOfRangeException or ArgumentException )
You can’t perform that action at this time.
0 commit comments