Skip to content

Commit b3932c7

Browse files
authored
(micrometer) don't add . to empty unit with prometheus naming conventions (#8872)
1 parent acbab58 commit b3932c7

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

instrumentation/micrometer/micrometer-1.5/library/src/main/java/io/opentelemetry/instrumentation/micrometer/v1_5/PrometheusModeNamingConvention.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public String name(String name, Meter.Type type, @Nullable String baseUnit) {
2020
if (type == Meter.Type.COUNTER
2121
|| type == Meter.Type.DISTRIBUTION_SUMMARY
2222
|| type == Meter.Type.GAUGE) {
23-
if (baseUnit != null && !name.endsWith("." + baseUnit)) {
23+
if (baseUnit != null && !baseUnit.equals("") && !name.endsWith("." + baseUnit)) {
2424
name = name + "." + baseUnit;
2525
}
2626
}

instrumentation/micrometer/micrometer-1.5/testing/src/main/java/io/opentelemetry/instrumentation/micrometer/v1_5/AbstractPrometheusModeTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ void testCounter() {
3434
Counter.builder("testPrometheusCounter")
3535
.description("This is a test counter")
3636
.tags("tag", "value")
37-
.baseUnit("items")
37+
.baseUnit("")
3838
.register(Metrics.globalRegistry);
3939

4040
// when
@@ -44,13 +44,13 @@ void testCounter() {
4444
testing()
4545
.waitAndAssertMetrics(
4646
INSTRUMENTATION_NAME,
47-
"testPrometheusCounter.items",
47+
"testPrometheusCounter",
4848
metrics ->
4949
metrics.anySatisfy(
5050
metric ->
5151
assertThat(metric)
5252
.hasDescription("This is a test counter")
53-
.hasUnit("items")
53+
.hasUnit("")
5454
.hasDoubleSumSatisfying(
5555
sum ->
5656
sum.isMonotonic()

0 commit comments

Comments
 (0)