|
1 | 1 | // Copyright 2021-2022 Workiva. |
2 | 2 | // Licensed under the Apache License, Version 2.0. Please see https://github.com/Workiva/opentelemetry-dart/blob/master/LICENSE for more information |
3 | | -import 'package:collection/collection.dart'; |
4 | 3 | import 'package:meta/meta.dart'; |
5 | 4 |
|
6 | 5 | import '../../../api.dart' as api; |
@@ -86,14 +85,18 @@ api.Attribute applyAttributeLimitsForLog( |
86 | 85 | ? api.Attribute.fromString(attr.key, (attr.value as String).substring(0, limits.attributeValueLengthLimit)) |
87 | 86 | : attr; |
88 | 87 | } else if (attr.value is List<String>) { |
89 | | - final listString = attr.value as List<String>; |
90 | | - final truncatedValues = |
91 | | - listString.map((e) => applyAttributeLengthLimit(e, limits.attributeValueLengthLimit)).toList(); |
92 | | - |
93 | | - final equal = const ListEquality().equals(listString, truncatedValues); |
94 | | - if (equal) return attr; |
95 | | - |
96 | | - return api.Attribute.fromStringList(attr.key, truncatedValues); |
| 88 | + final list = (attr.value as List<String>); |
| 89 | + List<String>? truncated; |
| 90 | + for (int i = 0; i < list.length; i++) { |
| 91 | + final s = list[i]; |
| 92 | + if (s.length > limits.attributeValueLengthLimit) { |
| 93 | + truncated ??= List<String>.from(list, growable: false); |
| 94 | + truncated[i] = s.substring(0, limits.attributeValueLengthLimit); |
| 95 | + } |
| 96 | + } |
| 97 | + if (truncated != null) { |
| 98 | + return api.Attribute.fromStringList(attr.key, truncated); |
| 99 | + } |
97 | 100 | } |
98 | 101 | return attr; |
99 | 102 | } |
|
0 commit comments