Skip to content

Commit

Permalink
opentelemetry: Add explicit histogram buckets for per-call metrics (#…
Browse files Browse the repository at this point in the history
…11281) (#11287)

Add explicit histogram buckets for per-call metrics as specified in gRFC A66 https://github.com/grpc/proposal/blob/master/A66-otel-stats.md#units.
  • Loading branch information
DNVindhya authored Jun 14, 2024
1 parent f54cdf0 commit 71eca4e
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import static com.google.common.base.Preconditions.checkNotNull;
import static io.grpc.internal.GrpcUtil.IMPLEMENTATION_VERSION;
import static io.grpc.opentelemetry.internal.OpenTelemetryConstants.LATENCY_BUCKETS;
import static io.grpc.opentelemetry.internal.OpenTelemetryConstants.SIZE_BUCKETS;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Stopwatch;
Expand Down Expand Up @@ -172,6 +174,7 @@ static OpenTelemetryMetricsResource createMetricInstruments(Meter meter,
.setUnit("s")
.setDescription(
"Time taken by gRPC to complete an RPC from application's perspective")
.setExplicitBucketBoundariesAdvice(LATENCY_BUCKETS)
.build());
}

Expand All @@ -189,6 +192,7 @@ static OpenTelemetryMetricsResource createMetricInstruments(Meter meter,
"grpc.client.attempt.duration")
.setUnit("s")
.setDescription("Time taken to complete a client call attempt")
.setExplicitBucketBoundariesAdvice(LATENCY_BUCKETS)
.build());
}

Expand All @@ -200,6 +204,7 @@ static OpenTelemetryMetricsResource createMetricInstruments(Meter meter,
.setUnit("By")
.setDescription("Compressed message bytes sent per client call attempt")
.ofLongs()
.setExplicitBucketBoundariesAdvice(SIZE_BUCKETS)
.build());
}

Expand All @@ -211,6 +216,7 @@ static OpenTelemetryMetricsResource createMetricInstruments(Meter meter,
.setUnit("By")
.setDescription("Compressed message bytes received per call attempt")
.ofLongs()
.setExplicitBucketBoundariesAdvice(SIZE_BUCKETS)
.build());
}

Expand All @@ -228,6 +234,7 @@ static OpenTelemetryMetricsResource createMetricInstruments(Meter meter,
.setUnit("s")
.setDescription(
"Time taken to complete a call from server transport's perspective")
.setExplicitBucketBoundariesAdvice(LATENCY_BUCKETS)
.build());
}

Expand All @@ -239,6 +246,7 @@ static OpenTelemetryMetricsResource createMetricInstruments(Meter meter,
.setUnit("By")
.setDescription("Compressed message bytes sent per server call")
.ofLongs()
.setExplicitBucketBoundariesAdvice(SIZE_BUCKETS)
.build());
}

Expand All @@ -250,6 +258,7 @@ static OpenTelemetryMetricsResource createMetricInstruments(Meter meter,
.setUnit("By")
.setDescription("Compressed message bytes received per server call")
.ofLongs()
.setExplicitBucketBoundariesAdvice(SIZE_BUCKETS)
.build());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

package io.grpc.opentelemetry.internal;

import com.google.common.collect.ImmutableList;
import io.opentelemetry.api.common.AttributeKey;
import java.util.List;

public final class OpenTelemetryConstants {

Expand All @@ -31,6 +33,19 @@ public final class OpenTelemetryConstants {
public static final AttributeKey<String> LOCALITY_KEY =
AttributeKey.stringKey("grpc.lb.locality");

public static final List<Double> LATENCY_BUCKETS =
ImmutableList.of(
0d, 0.00001d, 0.00005d, 0.0001d, 0.0003d, 0.0006d, 0.0008d, 0.001d, 0.002d,
0.003d, 0.004d, 0.005d, 0.006d, 0.008d, 0.01d, 0.013d, 0.016d, 0.02d,
0.025d, 0.03d, 0.04d, 0.05d, 0.065d, 0.08d, 0.1d, 0.13d, 0.16d,
0.2d, 0.25d, 0.3d, 0.4d, 0.5d, 0.65d, 0.8d, 1d, 2d,
5d, 10d, 20d, 50d, 100d);

public static final List<Long> SIZE_BUCKETS =
ImmutableList.of(
0L, 1024L, 2048L, 4096L, 16384L, 65536L, 262144L, 1048576L, 4194304L, 16777216L,
67108864L, 268435456L, 1073741824L, 4294967296L);

private OpenTelemetryConstants() {
}
}
Loading

0 comments on commit 71eca4e

Please sign in to comment.