@@ -9,8 +9,7 @@ import '../../experimental_sdk.dart' as sdk;
9
9
10
10
/// Applies given [sdk.SpanLimits] to a list of [api.SpanLink] s.
11
11
@protected
12
- List <api.SpanLink > applyLinkLimits (
13
- List <api.SpanLink > links, sdk.SpanLimits limits) {
12
+ List <api.SpanLink > applyLinkLimits (List <api.SpanLink > links, sdk.SpanLimits limits) {
14
13
final spanLink = < api.SpanLink > [];
15
14
16
15
for (final link in links) {
@@ -29,8 +28,7 @@ List<api.SpanLink> applyLinkLimits(
29
28
for (final attr in link.attributes) {
30
29
// if attributes num is already greater than maxNumAttributesPerLink
31
30
// and this key doesn't exist in the list, drop it.
32
- if (attributeMap.length >= limits.maxNumAttributesPerLink &&
33
- ! attributeMap.containsKey (attr.key)) {
31
+ if (attributeMap.length >= limits.maxNumAttributesPerLink && ! attributeMap.containsKey (attr.key)) {
34
32
droppedAttributes++ ;
35
33
continue ;
36
34
}
@@ -51,8 +49,7 @@ List<api.SpanLink> applyLinkLimits(
51
49
}
52
50
}
53
51
54
- spanLink.add (api.SpanLink (link.context,
55
- attributes: linkAttributes, droppedAttributes: droppedAttributes));
52
+ spanLink.add (api.SpanLink (link.context, attributes: linkAttributes, droppedAttributes: droppedAttributes));
56
53
}
57
54
return spanLink;
58
55
}
@@ -65,14 +62,11 @@ api.Attribute applyAttributeLimits(api.Attribute attr, sdk.SpanLimits limits) {
65
62
66
63
if (attr.value is String ) {
67
64
attr = api.Attribute .fromString (
68
- attr.key,
69
- applyAttributeLengthLimit (
70
- attr.value as String , limits.maxNumAttributeLength));
65
+ attr.key, applyAttributeLengthLimit (attr.value as String , limits.maxNumAttributeLength));
71
66
} else if (attr.value is List <String >) {
72
67
final listString = attr.value as List <String >;
73
68
for (var j = 0 ; j < listString.length; j++ ) {
74
- listString[j] = applyAttributeLengthLimit (
75
- listString[j], limits.maxNumAttributeLength);
69
+ listString[j] = applyAttributeLengthLimit (listString[j], limits.maxNumAttributeLength);
76
70
}
77
71
attr = api.Attribute .fromStringList (attr.key, listString);
78
72
}
@@ -88,18 +82,13 @@ api.Attribute applyAttributeLimitsForLog(
88
82
if (limits.attributeValueLengthLimit < 0 ) return attr;
89
83
90
84
if (attr.value is String ) {
91
- final truncatedValue = applyAttributeLengthLimit (
92
- attr.value as String , limits.attributeValueLengthLimit);
93
-
94
- if (truncatedValue == attr.value) return attr;
95
-
96
- return api.Attribute .fromString (attr.key, truncatedValue);
85
+ return (attr.value as String ).length > limits.attributeValueLengthLimit
86
+ ? api.Attribute .fromString (attr.key, (attr.value as String ).substring (0 , limits.attributeValueLengthLimit))
87
+ : attr;
97
88
} else if (attr.value is List <String >) {
98
89
final listString = attr.value as List <String >;
99
- final truncatedValues = listString
100
- .map ((e) =>
101
- applyAttributeLengthLimit (e, limits.attributeValueLengthLimit))
102
- .toList ();
90
+ final truncatedValues =
91
+ listString.map ((e) => applyAttributeLengthLimit (e, limits.attributeValueLengthLimit)).toList ();
103
92
104
93
final equal = const ListEquality ().equals (listString, truncatedValues);
105
94
if (equal) return attr;
0 commit comments