@@ -11,22 +11,35 @@ namespace OpenTelemetry.Logs;
11
11
internal sealed class LogRecordEnrichedAttributes : IReadOnlyList < KeyValuePair < string , object ? > >
12
12
{
13
13
private readonly List < KeyValuePair < string , object ? > > enrichedAttributes = new ( ) ;
14
- private IReadOnlyList < KeyValuePair < string , object ? > > initialAttributes ;
14
+ private readonly LogRecord logRecord ;
15
+ private IReadOnlyList < KeyValuePair < string , object ? > > ? initialAttributes ;
15
16
16
- public LogRecordEnrichedAttributes ( )
17
+ public LogRecordEnrichedAttributes ( LogRecord logRecord )
17
18
{
18
- this . initialAttributes = Array . Empty < KeyValuePair < string , object ? > > ( ) ;
19
+ Debug . Assert ( logRecord != null , "logRecord was null" ) ;
20
+
21
+ this . logRecord = logRecord ! ;
19
22
}
20
23
21
- public int Count => this . initialAttributes . Count + this . enrichedAttributes . Count ;
24
+ public int Count
25
+ {
26
+ get
27
+ {
28
+ Debug . Assert ( this . initialAttributes != null , "this.initialAttributes was null" ) ;
29
+
30
+ return this . initialAttributes ! . Count + this . enrichedAttributes . Count ;
31
+ }
32
+ }
22
33
23
34
public KeyValuePair < string , object ? > this [ int index ]
24
35
{
25
36
get
26
37
{
27
38
Guard . ThrowIfNegative ( index ) ;
28
39
29
- var initialAttributes = this . initialAttributes ;
40
+ Debug . Assert ( this . initialAttributes != null , "this.initialAttributes was null" ) ;
41
+
42
+ var initialAttributes = this . initialAttributes ! ;
30
43
31
44
var count = initialAttributes . Count ;
32
45
if ( index < count )
@@ -38,9 +51,12 @@ public LogRecordEnrichedAttributes()
38
51
}
39
52
}
40
53
41
- public void Reset ( IReadOnlyList < KeyValuePair < string , object ? > > ? initialAttributes )
54
+ public void Reset ( )
42
55
{
43
- this . initialAttributes = initialAttributes ?? Array . Empty < KeyValuePair < string , object ? > > ( ) ;
56
+ this . initialAttributes = this . logRecord . Attributes ?? Array . Empty < KeyValuePair < string , object ? > > ( ) ;
57
+
58
+ // Note: Clear sets the count/size to 0 but it maintains the underlying
59
+ // array(capacity).
44
60
this . enrichedAttributes . Clear ( ) ;
45
61
}
46
62
0 commit comments