diff --git a/apm-agent-plugins/apm-micrometer-plugin/src/main/java/co/elastic/apm/agent/micrometer/MicrometerMeterRegistrySerializer.java b/apm-agent-plugins/apm-micrometer-plugin/src/main/java/co/elastic/apm/agent/micrometer/MicrometerMeterRegistrySerializer.java index 58048dde12..73016f36ab 100644 --- a/apm-agent-plugins/apm-micrometer-plugin/src/main/java/co/elastic/apm/agent/micrometer/MicrometerMeterRegistrySerializer.java +++ b/apm-agent-plugins/apm-micrometer-plugin/src/main/java/co/elastic/apm/agent/micrometer/MicrometerMeterRegistrySerializer.java @@ -201,7 +201,7 @@ private static boolean serializeTimer(JsonWriter jw, HistogramSnapshot histogram serializeValue(id, ".count", count, jw, replaceBuilder, dedotMetricName); jw.writeByte(JsonWriter.COMMA); serializeValue(id, ".sum.us", totalTime, jw, replaceBuilder, dedotMetricName); - if (histogramSnapshot != null && histogramSnapshot.histogramCounts().length > 0) { + if (histogramSnapshot != null && logHistoLength(histogramSnapshot.histogramCounts().length) > 0) { jw.writeByte(JsonWriter.COMMA); serializeHistogram(id, histogramSnapshot, jw, replaceBuilder, dedotMetricName); } @@ -229,7 +229,7 @@ private static boolean serializeDistributionSummary(JsonWriter jw, HistogramSnap serializeValue(id, ".count", count, jw, replaceBuilder, dedotMetricName); jw.writeByte(JsonWriter.COMMA); serializeValue(id, ".sum", totalAmount, jw, replaceBuilder, dedotMetricName); - if (histogramSnapshot != null && histogramSnapshot.histogramCounts().length > 0) { + if (histogramSnapshot != null && logHistoLength(histogramSnapshot.histogramCounts().length) > 0) { jw.writeByte(JsonWriter.COMMA); serializeHistogram(id, histogramSnapshot, jw, replaceBuilder, dedotMetricName); } @@ -238,12 +238,21 @@ private static boolean serializeDistributionSummary(JsonWriter jw, HistogramSnap return hasValue; } + private static int logHistoLength(int length){ + logger.debug("Histogram length1: {}", length); + return length; + } + private static void serializeHistogram(Meter.Id id, HistogramSnapshot histogramSnapshot, JsonWriter jw, StringBuilder replaceBuilder, boolean dedotMetricName) { if (histogramSnapshot == null) { return; } String suffix = ".histogram"; CountAtBucket[] bucket = histogramSnapshot.histogramCounts(); + logger.debug("Histogram length2: {}", bucket.length); + if (bucket.length == 0) { + return; + } serializeObjectStart(id.getName(), "values", suffix, jw, replaceBuilder, dedotMetricName); jw.writeByte(JsonWriter.ARRAY_START); if (bucket.length > 0) {