This repository was archived by the owner on May 14, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 74
Closed
PoC: Otel metrics #1807
Changes from 2 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
2ae69f7
OTEL POC with attempt latency.
blakeli0 6671379
Add ClientMetricsTracer. Add channel size metric.
blakeli0 cd9f387
Add response to OperationSucceeded. Add a way to add attributes to me…
blakeli0 5eccd09
Add metrics for retryCount.
blakeli0 c2573b6
Add ApiTracerFactory to java-core.
blakeli0 292beae
chore: Add gRPC metrics for DirectPath.
blakeli0 9cfd35e
Add GFE metadata metrics. Add status labels.
blakeli0 4d19614
Add gax thread count metric.
blakeli0 be5b7b3
Merge branch 'main' into otel-poc
blakeli0 527985f
Make metric recorders protected.
blakeli0 56c9999
Add OperationCounter
blakeli0 d249b66
Add MetricsRecorder
blakeli0 145ad30
Merge branch 'main' into otel-poc
blakeli0 5c30048
Merge branch 'main' into otel-poc
blakeli0 57571b2
Add MetricsRecorder
blakeli0 3e2a771
Merge branch 'main' into otel-poc
blakeli0 3f24049
Expose addAdditionalAttributes in ApiTracer.
blakeli0 09c7c7b
Move OpenTelemetry logics to MetricsRecorder
blakeli0 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
gax-java/gax/src/main/java/com/google/api/gax/tracing/ClientMetricsTracer.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package com.google.api.gax.tracing; | ||
|
|
||
| public interface ClientMetricsTracer { | ||
|
|
||
| void recordCurrentChannelSize(int channelSize); | ||
|
|
||
| default String channelSizeName() { | ||
| return "channel_size"; | ||
| }; | ||
| } |
21 changes: 21 additions & 0 deletions
21
gax-java/gax/src/main/java/com/google/api/gax/tracing/OpenTelemetryClientMetricsTracer.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| package com.google.api.gax.tracing; | ||
|
|
||
| import io.opentelemetry.api.metrics.Meter; | ||
|
|
||
| public class OpenTelemetryClientMetricsTracer implements ClientMetricsTracer { | ||
|
|
||
| private Meter meter; | ||
| public OpenTelemetryClientMetricsTracer(Meter meter) { | ||
| this.meter = meter; | ||
| } | ||
|
|
||
| @Override | ||
| public void recordCurrentChannelSize(int channelSize) { | ||
| meter | ||
| .gaugeBuilder(channelSizeName()) | ||
| .setDescription("Channel Size") | ||
| .setUnit("1") | ||
| .ofLongs() | ||
| .buildWithCallback(measurement -> measurement.record(channelSize)); | ||
| } | ||
| } |
150 changes: 150 additions & 0 deletions
150
gax-java/gax/src/main/java/com/google/api/gax/tracing/OpenTelemetryMetricsTracer.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,150 @@ | ||
| /* | ||
| * Copyright 2023 Google LLC | ||
| * | ||
| * Redistribution and use in source and binary forms, with or without | ||
| * modification, are permitted provided that the following conditions are | ||
| * met: | ||
| * | ||
| * * Redistributions of source code must retain the above copyright | ||
| * notice, this list of conditions and the following disclaimer. | ||
| * * Redistributions in binary form must reproduce the above | ||
| * copyright notice, this list of conditions and the following disclaimer | ||
| * in the documentation and/or other materials provided with the | ||
| * distribution. | ||
| * * Neither the name of Google LLC nor the names of its | ||
| * contributors may be used to endorse or promote products derived from | ||
| * this software without specific prior written permission. | ||
| * | ||
| * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
| * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
| * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
| * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
| * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
| * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
| * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
| * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
| * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
| * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| */ | ||
|
|
||
| package com.google.api.gax.tracing; | ||
|
|
||
| import com.google.common.base.Stopwatch; | ||
| import io.opentelemetry.api.common.Attributes; | ||
| import io.opentelemetry.api.metrics.DoubleHistogram; | ||
| import io.opentelemetry.api.metrics.LongCounter; | ||
| import io.opentelemetry.api.metrics.Meter; | ||
| import org.threeten.bp.Duration; | ||
|
|
||
| import java.util.concurrent.TimeUnit; | ||
|
|
||
| import static io.opentelemetry.api.common.AttributeKey.stringKey; | ||
|
|
||
| public class OpenTelemetryMetricsTracer implements ApiTracer { | ||
| protected Meter meter; | ||
|
|
||
| private Stopwatch attemptTimer; | ||
|
|
||
| private SpanName spanName; | ||
|
|
||
| public OpenTelemetryMetricsTracer(Meter meter, SpanName spanName) { | ||
| this.meter = meter; | ||
| this.spanName = spanName; | ||
| } | ||
|
|
||
| @Override | ||
| public Scope inScope() { | ||
| return () -> {}; | ||
| } | ||
|
|
||
| @Override | ||
| public void operationSucceeded() { | ||
|
|
||
| } | ||
|
|
||
| @Override | ||
| public void operationCancelled() { | ||
|
|
||
| } | ||
|
|
||
| @Override | ||
| public void operationFailed(Throwable error) { | ||
|
|
||
| } | ||
|
|
||
| @Override | ||
| public void connectionSelected(String id) { | ||
|
|
||
| } | ||
|
|
||
| @Override | ||
| public void attemptStarted(int attemptNumber) { | ||
|
|
||
| } | ||
|
|
||
| @Override | ||
| public void attemptStarted(Object request, int attemptNumber) { | ||
| attemptTimer = Stopwatch.createStarted(); | ||
| LongCounter longCounter = meter.counterBuilder("attempt_count") | ||
| .setDescription("Attempt Count") | ||
| .setUnit("1") | ||
| .build(); | ||
| longCounter.add(1); | ||
| } | ||
|
|
||
| @Override | ||
| public void attemptSucceeded() { | ||
| DoubleHistogram doubleHistogram = meter.histogramBuilder(attemptLatencyName()) | ||
| .setDescription("Duration of an individual operation attempt") | ||
| .setUnit("ms") | ||
| .build(); | ||
| Attributes attributes = Attributes.of(stringKey("method_name"), spanName.toString()); | ||
| doubleHistogram.record(attemptTimer.elapsed(TimeUnit.MILLISECONDS), attributes); | ||
| } | ||
|
|
||
| @Override | ||
| public void attemptCancelled() { | ||
|
|
||
| } | ||
|
|
||
| @Override | ||
| public void attemptFailed(Throwable error, Duration delay) { | ||
|
|
||
| } | ||
|
|
||
| @Override | ||
| public void attemptFailedRetriesExhausted(Throwable error) { | ||
|
|
||
| } | ||
|
|
||
| @Override | ||
| public void attemptPermanentFailure(Throwable error) { | ||
|
|
||
| } | ||
|
|
||
| @Override | ||
| public void lroStartFailed(Throwable error) { | ||
|
|
||
| } | ||
|
|
||
| @Override | ||
| public void lroStartSucceeded() { | ||
|
|
||
| } | ||
|
|
||
| @Override | ||
| public void responseReceived() { | ||
|
|
||
| } | ||
|
|
||
| @Override | ||
| public void requestSent() { | ||
|
|
||
| } | ||
|
|
||
| @Override | ||
| public void batchRequestSent(long elementCount, long requestSize) { | ||
|
|
||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're going to provide a default implementation, I wonder instead of override the attempt name, maybe we can provide a general class, something like
ApiTracerRecorderand provide functions like apiTracerInstrument.record(latency, attributes). So client libraries can define their own meter definition. Similar to https://github.com/googleapis/java-bigtable/pull/1796/files#diff-f2ab39ff606949b18fa0ea0a25b6149352064c8b1f775a78cb79eb8acfddde6fBigtableInsturmentandBuiltinInstruments(I'm going to rename them to BgitableRecorder and BuiltinRecorder)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can see the need of another abstraction layer for customizing some attributes(like extract this method to something like
MetricNames), however, I think most of things, likedescriptionandunitshould be the same for all services, so that we can have a consistent experience for all services. Let me know if I'm missing something.