diff --git a/implementations/micrometer-registry-otlp/src/main/java/io/micrometer/registry/otlp/OtlpMeterRegistry.java b/implementations/micrometer-registry-otlp/src/main/java/io/micrometer/registry/otlp/OtlpMeterRegistry.java index f697aa0c03..af5d63a21a 100644 --- a/implementations/micrometer-registry-otlp/src/main/java/io/micrometer/registry/otlp/OtlpMeterRegistry.java +++ b/implementations/micrometer-registry-otlp/src/main/java/io/micrometer/registry/otlp/OtlpMeterRegistry.java @@ -312,7 +312,7 @@ Metric writeGauge(Gauge gauge) { return getMetricBuilder(gauge.getId()) .setGauge(io.opentelemetry.proto.metrics.v1.Gauge.newBuilder() .addDataPoints(NumberDataPoint.newBuilder() - .setTimeUnixNano(getTimeUnixNano()) + .setTimeUnixNano(TimeUnit.MILLISECONDS.toNanos(clock.wallTime())) .setAsDouble(gauge.value()) .addAllAttributes(getTagsForId(gauge.getId())) .build())) diff --git a/implementations/micrometer-registry-otlp/src/test/java/io/micrometer/registry/otlp/OtlpDeltaMeterRegistryTest.java b/implementations/micrometer-registry-otlp/src/test/java/io/micrometer/registry/otlp/OtlpDeltaMeterRegistryTest.java index a612bccc9d..301f70df84 100644 --- a/implementations/micrometer-registry-otlp/src/test/java/io/micrometer/registry/otlp/OtlpDeltaMeterRegistryTest.java +++ b/implementations/micrometer-registry-otlp/src/test/java/io/micrometer/registry/otlp/OtlpDeltaMeterRegistryTest.java @@ -78,7 +78,9 @@ void gauge() { Metric metric = writeToMetric(gauge); assertThat(metric.getGauge()).isNotNull(); assertThat(metric.getGauge().getDataPoints(0).getAsDouble()).isEqualTo(5); - assertThat(metric.getGauge().getDataPoints(0).getTimeUnixNano()).isEqualTo(TimeUnit.MINUTES.toNanos(1)); + assertThat(metric.getGauge().getDataPoints(0).getTimeUnixNano()) + .describedAs("Gauges should have timestamp of the instant when data is sampled") + .isEqualTo(otlpConfig().step().plus(Duration.ofMillis(1)).toNanos()); } @Test @@ -88,7 +90,9 @@ void timeGauge() { Metric metric = writeToMetric(timeGauge); assertThat(metric.getGauge()).isNotNull(); assertThat(metric.getGauge().getDataPoints(0).getAsDouble()).isEqualTo(0.024); - assertThat(metric.getGauge().getDataPoints(0).getTimeUnixNano()).isEqualTo(TimeUnit.MINUTES.toNanos(1)); + assertThat(metric.getGauge().getDataPoints(0).getTimeUnixNano()) + .describedAs("Gauges should have timestamp of the instant when data is sampled") + .isEqualTo(otlpConfig().step().plus(Duration.ofMillis(1)).toNanos()); } @Test