Skip to content

Commit 8fed951

Browse files
committed
wip: limit list
1 parent 94c1fde commit 8fed951

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

lib/src/sdk/common/limits.dart

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// Copyright 2021-2022 Workiva.
22
// 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';
43
import 'package:meta/meta.dart';
54

65
import '../../../api.dart' as api;
@@ -86,14 +85,18 @@ api.Attribute applyAttributeLimitsForLog(
8685
? api.Attribute.fromString(attr.key, (attr.value as String).substring(0, limits.attributeValueLengthLimit))
8786
: attr;
8887
} 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+
}
97100
}
98101
return attr;
99102
}

0 commit comments

Comments
 (0)