@@ -137,15 +137,15 @@ internal OtlpLogs.LogRecord ToOtlpLog(LogRecord logRecord)
137137
138138 if ( ! string . IsNullOrEmpty ( logRecord . EventId . Name ) )
139139 {
140- AddStringAttribute ( otlpLogRecord , ExperimentalOptions . LogRecordEventNameAttribute , logRecord . EventId . Name , attributeValueLengthLimit , attributeCountLimit ) ;
140+ AddStringAttribute ( otlpLogRecord , ExperimentalOptions . LogRecordEventNameAttribute , logRecord . EventId . Name , attributeCountLimit , attributeValueLengthLimit ) ;
141141 }
142142 }
143143
144144 if ( logRecord . Exception != null )
145145 {
146- AddStringAttribute ( otlpLogRecord , SemanticConventions . AttributeExceptionType , logRecord . Exception . GetType ( ) . Name , attributeValueLengthLimit , attributeCountLimit ) ;
147- AddStringAttribute ( otlpLogRecord , SemanticConventions . AttributeExceptionMessage , logRecord . Exception . Message , attributeValueLengthLimit , attributeCountLimit ) ;
148- AddStringAttribute ( otlpLogRecord , SemanticConventions . AttributeExceptionStacktrace , logRecord . Exception . ToInvariantString ( ) , attributeValueLengthLimit , attributeCountLimit ) ;
146+ AddStringAttribute ( otlpLogRecord , SemanticConventions . AttributeExceptionType , logRecord . Exception . GetType ( ) . Name , attributeCountLimit , attributeValueLengthLimit ) ;
147+ AddStringAttribute ( otlpLogRecord , SemanticConventions . AttributeExceptionMessage , logRecord . Exception . Message , attributeCountLimit , attributeValueLengthLimit ) ;
148+ AddStringAttribute ( otlpLogRecord , SemanticConventions . AttributeExceptionStacktrace , logRecord . Exception . ToInvariantString ( ) , attributeCountLimit , attributeValueLengthLimit ) ;
149149 }
150150
151151 bool bodyPopulatedFromFormattedMessage = false ;
@@ -166,9 +166,9 @@ internal OtlpLogs.LogRecord ToOtlpLog(LogRecord logRecord)
166166 {
167167 otlpLogRecord . Body = new OtlpCommon . AnyValue { StringValue = attribute . Value as string } ;
168168 }
169- else if ( OtlpTagTransformer . Instance . TryTransformTag ( attribute , out var result , attributeValueLengthLimit ) )
169+ else
170170 {
171- AddAttribute ( otlpLogRecord , result , attributeCountLimit ) ;
171+ AddAttribute ( otlpLogRecord , attribute , attributeCountLimit , attributeValueLengthLimit ) ;
172172 }
173173 }
174174
@@ -224,10 +224,7 @@ void ProcessScope(LogRecordScope scope, OtlpLogs.LogRecord otlpLog)
224224 }
225225 else
226226 {
227- if ( OtlpTagTransformer . Instance . TryTransformTag ( scopeItem , out var result , attributeValueLengthLimit ) )
228- {
229- AddAttribute ( otlpLog , result , attributeCountLimit ) ;
230- }
227+ AddAttribute ( otlpLog , scopeItem , attributeCountLimit , attributeValueLengthLimit ) ;
231228 }
232229 }
233230 }
@@ -241,36 +238,34 @@ void ProcessScope(LogRecordScope scope, OtlpLogs.LogRecord otlpLog)
241238 }
242239
243240 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
244- private static void AddAttribute ( OtlpLogs . LogRecord logRecord , OtlpCommon . KeyValue attribute , int maxAttributeCount )
241+ private static void AddAttribute ( OtlpLogs . LogRecord logRecord , KeyValuePair < string , object > attribute , int maxAttributeCount , int ? maxValueLength )
245242 {
246- if ( logRecord . Attributes . Count < maxAttributeCount )
243+ var logRecordAttributes = logRecord . Attributes ;
244+
245+ if ( logRecordAttributes . Count == maxAttributeCount )
247246 {
248- logRecord . Attributes . Add ( attribute ) ;
247+ logRecord . DroppedAttributesCount ++ ;
249248 }
250249 else
251250 {
252- logRecord . DroppedAttributesCount ++ ;
251+ OtlpTagWriter . Instance . TryWriteTag ( ref logRecordAttributes , attribute , maxValueLength ) ;
253252 }
254253 }
255254
256255 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
257- private static void AddStringAttribute ( OtlpLogs . LogRecord logRecord , string key , string value , int ? maxValueLength , int maxAttributeCount )
256+ private static void AddStringAttribute ( OtlpLogs . LogRecord logRecord , string key , string value , int maxAttributeCount , int ? maxValueLength )
258257 {
259258 var attributeItem = new KeyValuePair < string , object > ( key , value ) ;
260- if ( OtlpTagTransformer . Instance . TryTransformTag ( attributeItem , out var result , maxValueLength ) )
261- {
262- AddAttribute ( logRecord , result , maxAttributeCount ) ;
263- }
259+
260+ AddAttribute ( logRecord , attributeItem , maxAttributeCount , maxValueLength ) ;
264261 }
265262
266263 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
267264 private static void AddIntAttribute ( OtlpLogs . LogRecord logRecord , string key , int value , int maxAttributeCount )
268265 {
269266 var attributeItem = new KeyValuePair < string , object > ( key , value ) ;
270- if ( OtlpTagTransformer . Instance . TryTransformTag ( attributeItem , out var result ) )
271- {
272- AddAttribute ( logRecord , result , maxAttributeCount ) ;
273- }
267+
268+ AddAttribute ( logRecord , attributeItem , maxAttributeCount , maxValueLength : null ) ;
274269 }
275270
276271 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
0 commit comments