diff --git a/instrumentation/micrometer/micrometer-1.5/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/micrometer/v1_5/AsyncInstrumentRegistry.java b/instrumentation/micrometer/micrometer-1.5/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/micrometer/v1_5/AsyncInstrumentRegistry.java index 29970358db29..7c710f857852 100644 --- a/instrumentation/micrometer/micrometer-1.5/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/micrometer/v1_5/AsyncInstrumentRegistry.java +++ b/instrumentation/micrometer/micrometer-1.5/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/micrometer/v1_5/AsyncInstrumentRegistry.java @@ -44,18 +44,7 @@ void buildGauge( @Nullable T obj, ToDoubleFunction objMetric) { - buildGauge( - meterId.getName(), description(meterId), baseUnit(meterId), attributes, obj, objMetric); - } - - void buildGauge( - String name, - String description, - String baseUnit, - Attributes attributes, - @Nullable T obj, - ToDoubleFunction objMetric) { - + String name = meterId.getName(); synchronized (gauges) { // use the gauges map as lock for the recorder state - this way all gauge-related mutable // state will always be accessed in synchronized(gauges) @@ -69,8 +58,8 @@ void buildGauge( new DoubleMeasurementsRecorder(recorderLock); meter .gaugeBuilder(name) - .setDescription(description) - .setUnit(baseUnit) + .setDescription(description(meterId)) + .setUnit(baseUnit(meterId)) .buildWithCallback(recorderCallback); return recorderCallback; }); @@ -90,6 +79,17 @@ void buildDoubleCounter( Attributes attributes, T obj, ToDoubleFunction objMetric) { + buildDoubleCounter( + meterId.getName(), description(meterId), baseUnit(meterId), attributes, obj, objMetric); + } + + void buildDoubleCounter( + String name, + String description, + String baseUnit, + Attributes attributes, + @Nullable T obj, + ToDoubleFunction objMetric) { synchronized (doubleCounters) { // use the counters map as lock for the recorder state - this way all double counter-related @@ -98,14 +98,14 @@ void buildDoubleCounter( DoubleMeasurementsRecorder recorder = doubleCounters.computeIfAbsent( - meterId.getName(), + name, n -> { DoubleMeasurementsRecorder recorderCallback = new DoubleMeasurementsRecorder(recorderLock); meter - .counterBuilder(meterId.getName()) - .setDescription(description(meterId)) - .setUnit(baseUnit(meterId)) + .counterBuilder(name) + .setDescription(description) + .setUnit(baseUnit) .ofDoubles() .buildWithCallback(recorderCallback); return recorderCallback; diff --git a/instrumentation/micrometer/micrometer-1.5/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/micrometer/v1_5/OpenTelemetryFunctionTimer.java b/instrumentation/micrometer/micrometer-1.5/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/micrometer/v1_5/OpenTelemetryFunctionTimer.java index dc18d72b0133..077ad37cd8a7 100644 --- a/instrumentation/micrometer/micrometer-1.5/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/micrometer/v1_5/OpenTelemetryFunctionTimer.java +++ b/instrumentation/micrometer/micrometer-1.5/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/micrometer/v1_5/OpenTelemetryFunctionTimer.java @@ -45,7 +45,7 @@ final class OpenTelemetryFunctionTimer implements FunctionTimer, RemovableMet asyncInstrumentRegistry.buildLongCounter( countMeterName, description(id), /* baseUnit = */ "1", attributes, obj, countFunction); - asyncInstrumentRegistry.buildGauge( + asyncInstrumentRegistry.buildDoubleCounter( totalTimeMeterName, description(id), /* baseUnit = */ "ms", @@ -85,7 +85,7 @@ public Id getId() { @Override public void onRemove() { asyncInstrumentRegistry.removeLongCounter(countMeterName, attributes); - asyncInstrumentRegistry.removeGauge(totalTimeMeterName, attributes); + asyncInstrumentRegistry.removeDoubleCounter(totalTimeMeterName, attributes); } @SuppressWarnings("EqualsWhichDoesntCheckParameterClass") diff --git a/instrumentation/micrometer/micrometer-1.5/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/micrometer/v1_5/FunctionTimerTest.java b/instrumentation/micrometer/micrometer-1.5/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/micrometer/v1_5/FunctionTimerTest.java index 4feaa54b936a..f3d27204ffbb 100644 --- a/instrumentation/micrometer/micrometer-1.5/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/micrometer/v1_5/FunctionTimerTest.java +++ b/instrumentation/micrometer/micrometer-1.5/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/micrometer/v1_5/FunctionTimerTest.java @@ -77,7 +77,7 @@ void testFunctionTimer() throws Exception { assertThat(metric) .hasDescription("This is a test function timer") .hasUnit("ms") - .hasDoubleGauge() + .hasDoubleSum() .points() .satisfiesExactly( point -> @@ -124,7 +124,7 @@ void testNanoPrecision() { metric -> assertThat(metric) .hasUnit("ms") - .hasDoubleGauge() + .hasDoubleSum() .points() .satisfiesExactly( point -> assertThat(point).hasValue(1.234).attributes()))); @@ -167,7 +167,7 @@ void functionTimersWithSameNameAndDifferentTags() { metric -> assertThat(metric) .hasUnit("ms") - .hasDoubleGauge() + .hasDoubleSum() .points() .anySatisfy( point ->