@@ -137,15 +137,15 @@ internal OtlpLogs.LogRecord ToOtlpLog(LogRecord logRecord)
137
137
138
138
if ( ! string . IsNullOrEmpty ( logRecord . EventId . Name ) )
139
139
{
140
- AddStringAttribute ( otlpLogRecord , ExperimentalOptions . LogRecordEventNameAttribute , logRecord . EventId . Name , attributeValueLengthLimit , attributeCountLimit ) ;
140
+ AddStringAttribute ( otlpLogRecord , ExperimentalOptions . LogRecordEventNameAttribute , logRecord . EventId . Name , attributeCountLimit , attributeValueLengthLimit ) ;
141
141
}
142
142
}
143
143
144
144
if ( logRecord . Exception != null )
145
145
{
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 ) ;
149
149
}
150
150
151
151
bool bodyPopulatedFromFormattedMessage = false ;
@@ -166,9 +166,9 @@ internal OtlpLogs.LogRecord ToOtlpLog(LogRecord logRecord)
166
166
{
167
167
otlpLogRecord . Body = new OtlpCommon . AnyValue { StringValue = attribute . Value as string } ;
168
168
}
169
- else if ( OtlpTagTransformer . Instance . TryTransformTag ( attribute , out var result , attributeValueLengthLimit ) )
169
+ else
170
170
{
171
- AddAttribute ( otlpLogRecord , result , attributeCountLimit ) ;
171
+ AddAttribute ( otlpLogRecord , attribute , attributeCountLimit , attributeValueLengthLimit ) ;
172
172
}
173
173
}
174
174
@@ -224,10 +224,7 @@ void ProcessScope(LogRecordScope scope, OtlpLogs.LogRecord otlpLog)
224
224
}
225
225
else
226
226
{
227
- if ( OtlpTagTransformer . Instance . TryTransformTag ( scopeItem , out var result , attributeValueLengthLimit ) )
228
- {
229
- AddAttribute ( otlpLog , result , attributeCountLimit ) ;
230
- }
227
+ AddAttribute ( otlpLog , scopeItem , attributeCountLimit , attributeValueLengthLimit ) ;
231
228
}
232
229
}
233
230
}
@@ -241,36 +238,34 @@ void ProcessScope(LogRecordScope scope, OtlpLogs.LogRecord otlpLog)
241
238
}
242
239
243
240
[ 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 )
245
242
{
246
- if ( logRecord . Attributes . Count < maxAttributeCount )
243
+ var logRecordAttributes = logRecord . Attributes ;
244
+
245
+ if ( logRecordAttributes . Count == maxAttributeCount )
247
246
{
248
- logRecord . Attributes . Add ( attribute ) ;
247
+ logRecord . DroppedAttributesCount ++ ;
249
248
}
250
249
else
251
250
{
252
- logRecord . DroppedAttributesCount ++ ;
251
+ OtlpTagWriter . Instance . TryWriteTag ( ref logRecordAttributes , attribute , maxValueLength ) ;
253
252
}
254
253
}
255
254
256
255
[ 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 )
258
257
{
259
258
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 ) ;
264
261
}
265
262
266
263
[ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
267
264
private static void AddIntAttribute ( OtlpLogs . LogRecord logRecord , string key , int value , int maxAttributeCount )
268
265
{
269
266
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 ) ;
274
269
}
275
270
276
271
[ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
0 commit comments