Skip to content

Feat: client side metrics testing #1902

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 119 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
119 commits
Select commit Hold shift + click to select a range
30a7011
enable 4 metrics from GAX
milaGGL Aug 14, 2024
ed85413
format
milaGGL Aug 16, 2024
57084c4
add default otel
milaGGL Aug 21, 2024
571c095
format
milaGGL Aug 21, 2024
f4b8416
move constants out
milaGGL Aug 22, 2024
da0fe82
format
milaGGL Aug 23, 2024
61432eb
add additional attributes
milaGGL Aug 26, 2024
b5bfe5c
Merge branch 'main' into mila/client-side-metrics-demo
milaGGL Aug 26, 2024
f0a029d
add attributes to gax metrics
milaGGL Aug 27, 2024
5456038
Update BuiltinMetricsConstants.java
milaGGL Sep 4, 2024
5efaba6
remove current metrics implementation
milaGGL Sep 9, 2024
c0b4cc1
add custom exporter, add latency recorder
milaGGL Sep 11, 2024
3979331
use 2 otel instances
milaGGL Sep 18, 2024
a9d08b5
set custom apiTracerFactory to gax
milaGGL Sep 20, 2024
029bd8c
Merge branch 'main' into mila/client-side-metrics-demo2
milaGGL Sep 23, 2024
50e05fb
fix opentelemtry dependency version conflict issue
milaGGL Sep 23, 2024
53cd48a
use enabled/disabled style
milaGGL Sep 24, 2024
7adb9d6
modify access modifiers
milaGGL Sep 24, 2024
690e4ee
format
milaGGL Sep 24, 2024
e6f8ba6
rename boolean
milaGGL Sep 26, 2024
c4ca4ae
Merge branch 'main' into mila/client-side-metrics-demo2
milaGGL Sep 27, 2024
887221d
chore: generate libraries at Fri Sep 27 19:25:02 UTC 2024
cloud-java-bot Sep 27, 2024
a2c715a
Update pom.xml
milaGGL Sep 27, 2024
ed78182
resolve comments from proto
milaGGL Oct 1, 2024
e0d46be
e2E latency for runTransaction
milaGGL Oct 3, 2024
a72a685
Merge branch 'main' into mila/client-side-metrics-demo2
milaGGL Oct 4, 2024
92c83c1
chore: generate libraries at Fri Oct 4 14:44:19 UTC 2024
cloud-java-bot Oct 4, 2024
c5137c1
remove noise
milaGGL Oct 4, 2024
63b5bd3
reformat code
milaGGL Oct 4, 2024
ac424a6
re-format code
milaGGL Oct 7, 2024
52f428f
add documentations/comments
milaGGL Oct 8, 2024
c06b2cb
remove logger.info
milaGGL Oct 8, 2024
daf9fbe
record AggregationQuery firstResponseLatency
milaGGL Oct 10, 2024
1999ff7
Update BuiltinMetricsProvider.java
milaGGL Oct 10, 2024
6aa816b
add 2 new metrics
milaGGL Oct 16, 2024
81e349b
Merge branch 'main' into mila/client-side-metrics-demo2
milaGGL Oct 16, 2024
f4e36d9
resolve comments
milaGGL Oct 16, 2024
05e8efb
Update pom.xml
milaGGL Oct 16, 2024
b0b1687
remove duplicated tracing dependency
milaGGL Oct 16, 2024
4abbcf0
add opentelemetry-sdk-metrics dependency
milaGGL Oct 17, 2024
328855d
adjust end-to-end latency in streaming queries
milaGGL Oct 19, 2024
c619029
Merge branch 'mila/client-side-metrics-demo2' into mila/client-side-m…
milaGGL Oct 21, 2024
5e1fb4b
fix clirr error
milaGGL Oct 21, 2024
4a2a8d8
Merge branch 'mila/client-side-metrics-demo2' into mila/client-side-m…
milaGGL Oct 21, 2024
47f6b37
record serverSicdeTransaction
milaGGL Oct 22, 2024
4fa8874
add exportBuiltinMetricsToGoogleCloudMonitoring flag
milaGGL Oct 23, 2024
a21feac
include system-rules for trsting
milaGGL Oct 24, 2024
ba1f0c9
fix typo
milaGGL Oct 24, 2024
72bb99f
debug
milaGGL Oct 24, 2024
b746231
remove system-rules lib
milaGGL Oct 24, 2024
6f3cd57
add the lib
milaGGL Oct 24, 2024
9ce225c
Update MetricsUtilTest.java
milaGGL Oct 24, 2024
936936d
Update MetricsUtilTest.java
milaGGL Oct 24, 2024
6f8b06b
Update MetricsUtilTest.java
milaGGL Oct 24, 2024
03f17c5
use system lambda instead
milaGGL Oct 24, 2024
89d7e8d
fix typo
milaGGL Oct 24, 2024
3fb7cae
use system-stubs-junit4
milaGGL Oct 25, 2024
be3559f
add system-stubs-core
milaGGL Oct 25, 2024
08df5b0
Update MetricsUtilTest.java
milaGGL Oct 25, 2024
f30e21f
revert back to system lambda
milaGGL Oct 25, 2024
11a3345
add vm options to test profile
milaGGL Oct 25, 2024
d491de5
add test scope to system lambda
milaGGL Oct 25, 2024
f988db9
Merge branch 'mila/client-side-metrics-demo2' into mila/client-side-m…
milaGGL Oct 28, 2024
cc3834d
create TransactionMetricsContext
milaGGL Oct 28, 2024
39e5293
refactor the metrics recorders to use enum
milaGGL Oct 28, 2024
f17a62b
remove TransactionMetricsContext
milaGGL Oct 28, 2024
7deb0d6
Merge branch 'main' into mila/client-side-metrics-demo2
milaGGL Oct 29, 2024
0662da5
Update pom.xml
milaGGL Oct 29, 2024
a0952ed
Merge branch 'mila/client-side-metrics-demo2' into mila/client-side-m…
milaGGL Oct 29, 2024
3136d20
Merge branch 'mila/client-side-metrics-transaction' into mila/client-…
milaGGL Oct 29, 2024
2c43cd3
add disabled/enabled MetricsUtil test
milaGGL Oct 30, 2024
7f5744f
add more tests
milaGGL Nov 1, 2024
7592dcc
Merge branch 'main' into mila/client-side-metrics-testing
milaGGL Nov 6, 2024
e6694c6
add unit tests for BuiltInMetricsProvider
milaGGL Nov 6, 2024
53cb8da
finalize unit tests
milaGGL Nov 7, 2024
120c14d
Merge branch 'main' into mila/client-side-metrics-testing
milaGGL Nov 7, 2024
d4a5a41
try removing `FirestoreOptions.getDefaultInstance()` from tracing tests
milaGGL Nov 7, 2024
ef0afb6
use logger to check enabled vs disable
milaGGL Nov 7, 2024
4285d0e
is projectId null on github checks?
milaGGL Nov 7, 2024
5a6884b
did serviceOptions set the projectId?
milaGGL Nov 7, 2024
675a686
the test did not go through FirestoreOptions(Builder builder)
milaGGL Nov 7, 2024
b40b7d4
did enabled metrics causes this?
milaGGL Nov 7, 2024
fac2d09
Revert "did enabled metrics causes this?"
milaGGL Nov 7, 2024
8be64d0
handle null projectId exception
milaGGL Nov 7, 2024
23236f0
Update EnabledMetricsUtil.java
milaGGL Nov 7, 2024
7b4fc14
Update EnabledMetricsUtil.java
milaGGL Nov 7, 2024
f7ec3c0
add integration tests
milaGGL Nov 13, 2024
57c4a3d
format
milaGGL Nov 13, 2024
cfd78ee
add e2e latency to UpdateBuilder
milaGGL Nov 14, 2024
06c8c2d
add tests that doesn't trigger rpc metrics
milaGGL Nov 15, 2024
a78cd66
replace RunQuery.get with Query.get
milaGGL Nov 15, 2024
1228214
Update clirr-ignored-differences.xml
milaGGL Nov 18, 2024
edc8df0
Merge branch 'main' into mila/client-side-metrics-testing
milaGGL Nov 18, 2024
693260c
format
milaGGL Nov 18, 2024
16cd25f
refactor test code
milaGGL Nov 20, 2024
7f81d12
add E2E test
milaGGL Nov 26, 2024
25f9b59
Update ITE2EMetricsTest.java
milaGGL Nov 26, 2024
ffe72db
E2E tests verifys metrics are published only
milaGGL Nov 27, 2024
5d26ef7
remove metricUtil shutdown
milaGGL Nov 27, 2024
c55f2f6
shutdown metricReader gracefully
milaGGL Nov 27, 2024
457dde5
format
milaGGL Nov 27, 2024
95e088e
configure unit tests to not enable metrics collection
milaGGL Nov 28, 2024
ab9bb92
skip E2E metric test unless running against nightly
milaGGL Nov 28, 2024
02909a9
remove override function for obsolete api in api tracer
milaGGL Nov 28, 2024
a2c87c3
Merge branch 'main' into mila/client-side-metrics-testing
milaGGL Nov 28, 2024
f28794d
chore: generate libraries at Thu Nov 28 19:28:06 UTC 2024
cloud-java-bot Nov 28, 2024
3c2c017
chore: generate libraries at Thu Nov 28 19:30:10 UTC 2024
cloud-java-bot Nov 28, 2024
ec7556d
fix dependency error, test run E2E metric tests on CI
milaGGL Nov 28, 2024
48f2079
Merge branch 'mila/client-side-metrics-testing' of https://github.com…
milaGGL Nov 28, 2024
a735a18
Merge branch 'main' into mila/client-side-metrics-testing
milaGGL Jan 15, 2025
321379b
Merge branch 'main' into mila/client-side-metrics-testing
milaGGL Apr 17, 2025
d258d95
chore: generate libraries at Thu Apr 17 16:49:05 UTC 2025
cloud-java-bot Apr 17, 2025
d97a85b
fix the flakiness of the E2E tests
milaGGL Apr 23, 2025
c6baaa6
remove end to end latency metric
milaGGL Apr 23, 2025
d2e1e5c
format
milaGGL Apr 25, 2025
a899489
format TelemetryConstants, remove MonitoredStreamResponseObserver class
milaGGL May 1, 2025
b91fb59
Merge branch 'main' into mila/client-side-metrics-testing
milaGGL May 2, 2025
ace18e5
chore: generate libraries at Fri May 2 14:25:11 UTC 2025
cloud-java-bot May 2, 2025
475add5
Merge branch 'main' into mila/client-side-metrics-testing
milaGGL May 9, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion google-cloud-firestore/clirr-ignored-differences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@
<differenceType>7009</differenceType>
<method>void internalStream(*)</method>
</difference>

<!-- Relocate constants in TraceUtil -->
<difference>
<differenceType>6011</differenceType>
Expand All @@ -346,4 +346,38 @@
<method>void internalStream(*)</method>
<to>*</to>
</difference>

<!-- Update TelemetryConstants -->
<difference>
<differenceType>6011</differenceType>
<className>com/google/cloud/firestore/telemetry/TelemetryConstants</className>
<field>*</field>
</difference>

<difference>
<differenceType>6001</differenceType>
<className>com/google/cloud/firestore/telemetry/TelemetryConstants</className>
<field>*</field>
</difference>

<difference>
<differenceType>6004</differenceType>
<className>com/google/cloud/firestore/telemetry/TelemetryConstants</className>
<field>METRIC_ATTRIBUTE_KEY_*</field>
<from>io.opentelemetry.api.common.AttributeKey</from>
<to>java.lang.String</to>
</difference>

<difference>
<differenceType>6001</differenceType>
<className>com/google/cloud/firestore/telemetry/TelemetryConstants$MetricType</className>
<field>END_TO_END_LATENCY</field>
</difference>

<difference>
<differenceType>7012</differenceType>
<className>com/google/cloud/firestore/telemetry/MetricsUtil</className>
<method>void shutdown()</method>
</difference>

</differences>
56 changes: 50 additions & 6 deletions google-cloud-firestore/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@
<site.installationModule>google-cloud-firestore</site.installationModule>
<opentelemetry.version>1.49.0</opentelemetry.version>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-bom</artifactId>
<version>1.49.0</version> <type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
Expand Down Expand Up @@ -137,6 +149,14 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-sdk-common</artifactId>
</dependency>
<dependency>
<groupId>com.google.cloud.opentelemetry</groupId>
<artifactId>detector-resources-support</artifactId>
</dependency>
<!-- END OpenTelemetry -->

<!-- Test dependencies -->
Expand All @@ -156,6 +176,12 @@
<version>4.11.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.github.stefanbirkner</groupId>
<artifactId>system-lambda</artifactId>
<scope>test</scope>
<version>1.2.1</version>
</dependency>
<!-- Need testing utility classes for generated gRPC clients tests -->
<dependency>
<groupId>com.google.api</groupId>
Expand Down Expand Up @@ -211,12 +237,6 @@
<version>${opentelemetry.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-sdk-common</artifactId>
<version>${opentelemetry.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.cloud.opentelemetry</groupId>
<artifactId>exporter-trace</artifactId>
Expand All @@ -237,6 +257,18 @@
<version>2.62.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.api.grpc</groupId>
<artifactId>proto-google-cloud-monitoring-v3</artifactId>
<version>3.55.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-monitoring</artifactId>
<version>3.55.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.http-client</groupId>
<artifactId>google-http-client</artifactId>
Expand Down Expand Up @@ -317,6 +349,18 @@
<artifactId>javax.annotation-api</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.1.2</version>
<configuration>
<argLine>--add-opens java.base/java.util=ALL-UNNAMED</argLine>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<!-- JDK17 set up for tests in src/test-jdk17 -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package com.google.cloud.firestore;

import static com.google.cloud.firestore.telemetry.TelemetryConstants.METHOD_NAME_RUN_AGGREGATION_QUERY;
import static com.google.cloud.firestore.telemetry.TraceUtil.ATTRIBUTE_KEY_ATTEMPT;

import com.google.api.core.ApiFuture;
Expand All @@ -29,7 +28,6 @@
import com.google.cloud.Timestamp;
import com.google.cloud.firestore.telemetry.MetricsUtil.MetricsContext;
import com.google.cloud.firestore.telemetry.TelemetryConstants;
import com.google.cloud.firestore.telemetry.TelemetryConstants.MetricType;
import com.google.cloud.firestore.telemetry.TraceUtil;
import com.google.cloud.firestore.telemetry.TraceUtil.Scope;
import com.google.cloud.firestore.v1.FirestoreSettings;
Expand Down Expand Up @@ -108,7 +106,7 @@ public ApiFuture<ExplainResults<AggregateQuerySnapshot>> explain(ExplainOptions
getTraceUtil().startSpan(TelemetryConstants.METHOD_NAME_AGGREGATION_QUERY_GET);

MetricsContext metricsContext =
createMetricsContext(TelemetryConstants.METHOD_NAME_RUN_AGGREGATION_QUERY_EXPLAIN);
createMetricsContext(TelemetryConstants.METHOD_NAME_AGGREGATION_QUERY_EXPLAIN);

try (Scope ignored = span.makeCurrent()) {
AggregateQueryExplainResponseDeliverer responseDeliverer =
Expand Down Expand Up @@ -141,8 +139,8 @@ ApiFuture<AggregateQuerySnapshot> get(
MetricsContext metricsContext =
createMetricsContext(
transactionId == null
? TelemetryConstants.METHOD_NAME_RUN_AGGREGATION_QUERY_GET
: TelemetryConstants.METHOD_NAME_RUN_AGGREGATION_QUERY_TRANSACTIONAL);
? TelemetryConstants.METHOD_NAME_AGGREGATION_QUERY_GET
: TelemetryConstants.METHOD_NAME_TRANSACTION_GET_AGGREGATION_QUERY);

try (Scope ignored = span.makeCurrent()) {
AggregateQueryResponseDeliverer responseDeliverer =
Expand Down Expand Up @@ -224,12 +222,11 @@ ApiFuture<T> getFuture() {
}

void deliverFirstResponse() {
metricsContext.recordLatency(MetricType.FIRST_RESPONSE_LATENCY);
metricsContext.recordLatency(TelemetryConstants.MetricType.FIRST_RESPONSE_LATENCY);
}

void deliverError(Throwable throwable) {
future.setException(throwable);
metricsContext.recordLatency(MetricType.END_TO_END_LATENCY, throwable);
}

void deliverResult(
Expand All @@ -239,7 +236,6 @@ void deliverResult(
try {
T result = processResult(serverData, readTime, metrics);
future.set(result);
metricsContext.recordLatency(MetricType.END_TO_END_LATENCY);
} catch (Exception error) {
deliverError(error);
}
Expand Down Expand Up @@ -341,7 +337,9 @@ private boolean isExplainQuery() {
public void onStart(StreamController streamController) {
getTraceUtil()
.currentSpan()
.addEvent(METHOD_NAME_RUN_AGGREGATION_QUERY + " Stream started.", getAttemptAttributes());
.addEvent(
TelemetryConstants.METHOD_NAME_RUN_AGGREGATION_QUERY + " Stream started.",
getAttemptAttributes());
}

@Override
Expand All @@ -354,7 +352,8 @@ public void onResponse(RunAggregationQueryResponse response) {
getTraceUtil()
.currentSpan()
.addEvent(
METHOD_NAME_RUN_AGGREGATION_QUERY + " Response Received.", getAttemptAttributes());
TelemetryConstants.METHOD_NAME_RUN_AGGREGATION_QUERY + " Response Received.",
getAttemptAttributes());
if (response.hasReadTime()) {
readTime = Timestamp.fromProto(response.getReadTime());
}
Expand Down Expand Up @@ -383,15 +382,15 @@ public void onError(Throwable throwable) {
getTraceUtil()
.currentSpan()
.addEvent(
METHOD_NAME_RUN_AGGREGATION_QUERY + ": Retryable Error",
TelemetryConstants.METHOD_NAME_RUN_AGGREGATION_QUERY + ": Retryable Error",
Collections.singletonMap("error.message", throwable.toString()));

runQuery(responseDeliverer, attempt + 1);
} else {
getTraceUtil()
.currentSpan()
.addEvent(
METHOD_NAME_RUN_AGGREGATION_QUERY + ": Error",
TelemetryConstants.METHOD_NAME_RUN_AGGREGATION_QUERY + ": Error",
Collections.singletonMap("error.message", throwable.toString()));
responseDeliverer.deliverError(throwable);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@
import com.google.api.core.SettableApiFuture;
import com.google.api.gax.rpc.ApiException;
import com.google.api.gax.rpc.StatusCode.Code;
import com.google.cloud.firestore.telemetry.MetricsUtil.MetricsContext;
import com.google.cloud.firestore.telemetry.TelemetryConstants;
import com.google.cloud.firestore.telemetry.TelemetryConstants.MetricType;
import com.google.cloud.firestore.telemetry.TraceUtil;
import com.google.cloud.firestore.telemetry.TraceUtil.Context;
import com.google.cloud.firestore.telemetry.TraceUtil.Scope;
Expand Down Expand Up @@ -919,12 +917,6 @@ private void sendBatchLocked(final BulkCommitBatch batch) {
.startSpan(TelemetryConstants.METHOD_NAME_BULK_WRITER_COMMIT, traceContext)
.setAttribute(ATTRIBUTE_KEY_DOC_COUNT, batch.getMutationsSize());

MetricsContext metricsContext =
firestore
.getOptions()
.getMetricsUtil()
.createMetricsContext(TelemetryConstants.METHOD_NAME_BULK_WRITER_COMMIT);

try (Scope ignored = span.makeCurrent()) {
ApiFuture<Void> result = batch.bulkCommit();
if (!lastFlushOperation.isDone()) {
Expand All @@ -939,10 +931,8 @@ private void sendBatchLocked(final BulkCommitBatch batch) {
bulkWriterExecutor);
}
span.endAtFuture(result);
metricsContext.recordLatencyAtFuture(MetricType.END_TO_END_LATENCY, result);
} catch (Exception error) {
span.end(error);
metricsContext.recordLatency(MetricType.END_TO_END_LATENCY, error);
throw error;
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@
import com.google.api.gax.rpc.ApiException;
import com.google.api.gax.rpc.ApiExceptions;
import com.google.api.gax.rpc.ApiStreamObserver;
import com.google.cloud.firestore.telemetry.MetricsUtil.MetricsContext;
import com.google.cloud.firestore.telemetry.TelemetryConstants;
import com.google.cloud.firestore.telemetry.TelemetryConstants.MetricType;
import com.google.cloud.firestore.telemetry.TraceUtil;
import com.google.cloud.firestore.telemetry.TraceUtil.Scope;
import com.google.cloud.firestore.v1.FirestoreClient.PartitionQueryPagedResponse;
Expand Down Expand Up @@ -114,13 +112,6 @@ public ApiFuture<List<QueryPartition>> getPartitions(long desiredPartitionCount)
.getTraceUtil()
.startSpan(TelemetryConstants.METHOD_NAME_PARTITION_QUERY);

MetricsContext metricsContext =
rpcContext
.getFirestore()
.getOptions()
.getMetricsUtil()
.createMetricsContext(TelemetryConstants.METHOD_NAME_PARTITION_QUERY);

try (Scope ignored = span.makeCurrent()) {
ApiFuture<List<QueryPartition>> result =
ApiFutures.transform(
Expand All @@ -138,15 +129,12 @@ public ApiFuture<List<QueryPartition>> getPartitions(long desiredPartitionCount)
},
MoreExecutors.directExecutor());
span.endAtFuture(result);
metricsContext.recordLatencyAtFuture(MetricType.END_TO_END_LATENCY, result);
return result;
} catch (ApiException exception) {
span.end(exception);
metricsContext.recordLatency(MetricType.END_TO_END_LATENCY, exception);
throw FirestoreException.forApiException(exception);
} catch (Throwable throwable) {
span.end(throwable);
metricsContext.recordLatency(MetricType.END_TO_END_LATENCY, throwable);
throw throwable;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@
import com.google.api.gax.rpc.UnaryCallable;
import com.google.cloud.firestore.encoding.CustomClassMapper;
import com.google.cloud.firestore.spi.v1.FirestoreRpc;
import com.google.cloud.firestore.telemetry.MetricsUtil.MetricsContext;
import com.google.cloud.firestore.telemetry.TelemetryConstants;
import com.google.cloud.firestore.telemetry.TelemetryConstants.MetricType;
import com.google.cloud.firestore.telemetry.TraceUtil;
import com.google.cloud.firestore.telemetry.TraceUtil.Scope;
import com.google.cloud.firestore.v1.FirestoreClient.ListDocumentsPagedResponse;
Expand Down Expand Up @@ -139,13 +137,6 @@ public Iterable<DocumentReference> listDocuments() {
.getTraceUtil()
.startSpan(TelemetryConstants.METHOD_NAME_COL_REF_LIST_DOCUMENTS);

MetricsContext metricsContext =
rpcContext
.getFirestore()
.getOptions()
.getMetricsUtil()
.createMetricsContext(TelemetryConstants.METHOD_NAME_COL_REF_LIST_DOCUMENTS);

try (Scope ignored = span.makeCurrent()) {
ListDocumentsRequest.Builder request = ListDocumentsRequest.newBuilder();
request.setParent(options.getParentPath().toString());
Expand Down Expand Up @@ -185,15 +176,12 @@ public void remove() {
}
};
span.end();
metricsContext.recordLatency(MetricType.END_TO_END_LATENCY);
return result;
} catch (ApiException exception) {
span.end(exception);
metricsContext.recordLatency(MetricType.END_TO_END_LATENCY, exception);
throw FirestoreException.forApiException(exception);
} catch (Throwable throwable) {
span.end(throwable);
metricsContext.recordLatency(MetricType.END_TO_END_LATENCY, throwable);
throw throwable;
}
}
Expand All @@ -216,25 +204,16 @@ public ApiFuture<DocumentReference> add(@Nonnull final Map<String, Object> field
.getTraceUtil()
.startSpan(TelemetryConstants.METHOD_NAME_COL_REF_ADD);

MetricsContext metricsContext =
rpcContext
.getFirestore()
.getOptions()
.getMetricsUtil()
.createMetricsContext(TelemetryConstants.METHOD_NAME_COL_REF_ADD);

try (Scope ignored = span.makeCurrent()) {
final DocumentReference documentReference = document();
ApiFuture<WriteResult> createFuture = documentReference.create(fields);
ApiFuture<DocumentReference> result =
ApiFutures.transform(
createFuture, writeResult -> documentReference, MoreExecutors.directExecutor());
span.endAtFuture(result);
metricsContext.recordLatencyAtFuture(MetricType.END_TO_END_LATENCY, result);
return result;
} catch (Exception error) {
span.end(error);
metricsContext.recordLatency(MetricType.END_TO_END_LATENCY, error);
throw error;
}
}
Expand Down
Loading