Skip to content

Commit

Permalink
Rename http.*.duration to http.*.request.duration (#9089)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateusz Rzeszutek authored Aug 7, 2023
1 parent 01883e3 commit ff55471
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Double> DURATION_SECONDS_BUCKETS =
Expand All @@ -33,17 +33,20 @@ 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));
}
return durationBuilder.build();
}

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() {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ void collectsMetrics() {
.satisfiesExactlyInAnyOrder(
metric ->
assertThat(metric)
.hasName("http.client.duration")
.hasName("http.client.request.duration")
.hasUnit("s")
.hasHistogramSatisfying(
histogram ->
Expand Down Expand Up @@ -114,7 +114,7 @@ void collectsMetrics() {
.satisfiesExactlyInAnyOrder(
metric ->
assertThat(metric)
.hasName("http.client.duration")
.hasName("http.client.request.duration")
.hasHistogramSatisfying(
histogram ->
histogram.hasPointsSatisfying(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -306,7 +306,7 @@ void collectsHttpRouteFromEndAttributes() {
.anySatisfy(
metric ->
assertThat(metric)
.hasName("http.server.duration")
.hasName("http.server.request.duration")
.hasUnit("s")
.hasHistogramSatisfying(
histogram ->
Expand Down

0 comments on commit ff55471

Please sign in to comment.