From b164feb9a6ba26619e77fb9123973320107a2db0 Mon Sep 17 00:00:00 2001 From: Mateusz Rzeszutek Date: Tue, 1 Aug 2023 14:22:06 +0200 Subject: [PATCH] Rename `http.*.duration` to `http.*.request.duration` --- .../api/instrumenter/http/HttpClientMetrics.java | 6 +++++- .../api/instrumenter/http/HttpMetricsUtil.java | 11 +++++++---- .../api/instrumenter/http/HttpServerMetrics.java | 6 +++++- .../http/HttpClientMetricsStableSemconvTest.java | 4 ++-- .../http/HttpServerMetricsStableSemconvTest.java | 6 +++--- 5 files changed, 22 insertions(+), 11 deletions(-) diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetrics.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetrics.java index c82455083eab..17bc8e53b1b8 100644 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetrics.java +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetrics.java @@ -44,9 +44,13 @@ public static OperationMetrics get() { private final DoubleHistogram duration; private HttpClientMetrics(Meter meter) { + String durationInstrumentName = + HttpMetricsUtil.emitNewSemconvMetrics + ? "http.client.request.duration" + : "http.client.duration"; duration = createDurationHistogram( - meter, "http.client.duration", "The duration of the outbound HTTP request"); + meter, durationInstrumentName, "The duration of the outbound HTTP request"); } @Override diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpMetricsUtil.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpMetricsUtil.java index fcbbd8238977..47682a83030f 100644 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpMetricsUtil.java +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpMetricsUtil.java @@ -19,7 +19,7 @@ final class HttpMetricsUtil { // we'll use the old unit if the old semconv is in use - private static final boolean useSeconds = + static final boolean emitNewSemconvMetrics = SemconvStability.emitStableHttpSemconv() && !SemconvStability.emitOldHttpSemconv(); static final List DURATION_SECONDS_BUCKETS = @@ -33,9 +33,12 @@ final class HttpMetricsUtil { static DoubleHistogram createDurationHistogram(Meter meter, String name, String description) { DoubleHistogramBuilder durationBuilder = - meter.histogramBuilder(name).setUnit(useSeconds ? "s" : "ms").setDescription(description); + meter + .histogramBuilder(name) + .setUnit(emitNewSemconvMetrics ? "s" : "ms") + .setDescription(description); // don't set custom buckets if milliseconds are still used - if (useSeconds && durationBuilder instanceof ExtendedDoubleHistogramBuilder) { + if (emitNewSemconvMetrics && durationBuilder instanceof ExtendedDoubleHistogramBuilder) { ((ExtendedDoubleHistogramBuilder) durationBuilder) .setAdvice(advice -> advice.setExplicitBucketBoundaries(DURATION_SECONDS_BUCKETS)); } @@ -43,7 +46,7 @@ static DoubleHistogram createDurationHistogram(Meter meter, String name, String } static double nanosToUnit(long durationNanos) { - return durationNanos / (useSeconds ? NANOS_PER_S : NANOS_PER_MS); + return durationNanos / (emitNewSemconvMetrics ? NANOS_PER_S : NANOS_PER_MS); } private HttpMetricsUtil() {} diff --git a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetrics.java b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetrics.java index 25fb7c1f0692..7c834591c05c 100644 --- a/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetrics.java +++ b/instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetrics.java @@ -58,9 +58,13 @@ private HttpServerMetrics(Meter meter) { .setUnit("{requests}") .setDescription("The number of concurrent HTTP requests that are currently in-flight") .build(); + String durationInstrumentName = + HttpMetricsUtil.emitNewSemconvMetrics + ? "http.server.request.duration" + : "http.server.duration"; duration = createDurationHistogram( - meter, "http.server.duration", "The duration of the inbound HTTP request"); + meter, durationInstrumentName, "The duration of the inbound HTTP request"); requestSize = meter .histogramBuilder("http.server.request.size") diff --git a/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetricsStableSemconvTest.java b/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetricsStableSemconvTest.java index ba77b7b19d7b..0b919096d6de 100644 --- a/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetricsStableSemconvTest.java +++ b/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpClientMetricsStableSemconvTest.java @@ -82,7 +82,7 @@ void collectsMetrics() { .satisfiesExactlyInAnyOrder( metric -> assertThat(metric) - .hasName("http.client.duration") + .hasName("http.client.request.duration") .hasUnit("s") .hasHistogramSatisfying( histogram -> @@ -114,7 +114,7 @@ void collectsMetrics() { .satisfiesExactlyInAnyOrder( metric -> assertThat(metric) - .hasName("http.client.duration") + .hasName("http.client.request.duration") .hasHistogramSatisfying( histogram -> histogram.hasPointsSatisfying( diff --git a/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetricsStableSemconvTest.java b/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetricsStableSemconvTest.java index c1ee03986b4b..926776b6d53d 100644 --- a/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetricsStableSemconvTest.java +++ b/instrumentation-api-semconv/src/testStableHttpSemconv/java/io/opentelemetry/instrumentation/api/instrumenter/http/HttpServerMetricsStableSemconvTest.java @@ -146,7 +146,7 @@ void collectsMetrics() { .hasSpanId(spanContext1.getSpanId())))), metric -> assertThat(metric) - .hasName("http.server.duration") + .hasName("http.server.request.duration") .hasUnit("s") .hasHistogramSatisfying( histogram -> @@ -235,7 +235,7 @@ void collectsMetrics() { .hasSpanId(spanContext2.getSpanId())))), metric -> assertThat(metric) - .hasName("http.server.duration") + .hasName("http.server.request.duration") .hasHistogramSatisfying( histogram -> histogram.hasPointsSatisfying( @@ -306,7 +306,7 @@ void collectsHttpRouteFromEndAttributes() { .anySatisfy( metric -> assertThat(metric) - .hasName("http.server.duration") + .hasName("http.server.request.duration") .hasUnit("s") .hasHistogramSatisfying( histogram ->