Skip to content

Commit 0dca607

Browse files
committed
handle overflow
1 parent 4254d30 commit 0dca607

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

sdk/metrics/src/main/java/io/opentelemetry/sdk/metrics/internal/state/AsynchronousMetricStorage.java

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -161,16 +161,23 @@ private Attributes validateAndProcessAttributes(Attributes attributes) {
161161
attributes = attributesProcessor.process(attributes, context);
162162

163163
if (aggregatorHandles.size() >= maxCardinality) {
164-
throttlingLogger.log(
165-
Level.WARNING,
166-
"Instrument "
167-
+ metricDescriptor.getSourceInstrument().getName()
168-
+ " has exceeded the maximum allowed cardinality ("
169-
+ maxCardinality
170-
+ ").");
171-
return MetricStorage.CARDINALITY_OVERFLOW;
164+
aggregatorHandles.forEach(
165+
(attr, handle) -> {
166+
if (!handle.hasRecordedValues()) {
167+
aggregatorHandles.remove(attr);
168+
}
169+
});
170+
if (aggregatorHandles.size() >= maxCardinality) {
171+
throttlingLogger.log(
172+
Level.WARNING,
173+
"Instrument "
174+
+ metricDescriptor.getSourceInstrument().getName()
175+
+ " has exceeded the maximum allowed cardinality ("
176+
+ maxCardinality
177+
+ ").");
178+
return MetricStorage.CARDINALITY_OVERFLOW;
179+
}
172180
}
173-
174181
return attributes;
175182
}
176183

0 commit comments

Comments
 (0)