Skip to content

Commit 2cf3f5b

Browse files
authored
fix: Remove OpenCensus tracing code. (#1589)
* feat: Add FirestoreOpenTelemetryOptions to FirestoreOptions. * feat: Add com.google.cloud.firestore.telemetry package. * fix: Remove OpenCensus tracing code.
1 parent ef6bcb5 commit 2cf3f5b

File tree

12 files changed

+6
-261
lines changed

12 files changed

+6
-261
lines changed

google-cloud-firestore/pom.xml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,6 @@
4040
<artifactId>grpc-google-cloud-firestore-v1</artifactId>
4141
<scope>test</scope>
4242
</dependency>
43-
<dependency>
44-
<groupId>io.opencensus</groupId>
45-
<artifactId>opencensus-contrib-grpc-util</artifactId>
46-
</dependency>
4743
<dependency>
4844
<groupId>com.google.code.findbugs</groupId>
4945
<artifactId>jsr305</artifactId>
@@ -92,10 +88,6 @@
9288
<groupId>io.grpc</groupId>
9389
<artifactId>grpc-stub</artifactId>
9490
</dependency>
95-
<dependency>
96-
<groupId>io.opencensus</groupId>
97-
<artifactId>opencensus-api</artifactId>
98-
</dependency>
9991
<dependency>
10092
<groupId>com.google.auth</groupId>
10193
<artifactId>google-auth-library-credentials</artifactId>

google-cloud-firestore/src/main/java/com/google/cloud/firestore/BulkCommitBatch.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,10 @@
2121
import com.google.api.gax.rpc.ApiException;
2222
import com.google.cloud.Timestamp;
2323
import com.google.common.base.Preconditions;
24-
import com.google.common.collect.ImmutableMap;
2524
import com.google.common.util.concurrent.MoreExecutors;
2625
import com.google.firestore.v1.BatchWriteRequest;
2726
import com.google.firestore.v1.BatchWriteResponse;
2827
import io.grpc.Status;
29-
import io.opencensus.trace.AttributeValue;
30-
import io.opencensus.trace.Tracing;
3128
import java.util.ArrayList;
3229
import java.util.List;
3330
import java.util.Set;
@@ -69,12 +66,6 @@ ApiFuture<WriteResult> wrapResult(int writeIndex) {
6966
* <p>The writes in the batch are not applied atomically and can be applied out of order.
7067
*/
7168
ApiFuture<Void> bulkCommit() {
72-
Tracing.getTracer()
73-
.getCurrentSpan()
74-
.addAnnotation(
75-
TraceUtil.SPAN_NAME_BATCHWRITE,
76-
ImmutableMap.of("numDocuments", AttributeValue.longAttributeValue(getWrites().size())));
77-
7869
final BatchWriteRequest.Builder request = BatchWriteRequest.newBuilder();
7970
request.setDatabase(firestore.getDatabaseName());
8071

google-cloud-firestore/src/main/java/com/google/cloud/firestore/CollectionGroup.java

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@
2727
import com.google.common.util.concurrent.MoreExecutors;
2828
import com.google.firestore.v1.Cursor;
2929
import com.google.firestore.v1.PartitionQueryRequest;
30-
import io.opencensus.common.Scope;
31-
import io.opencensus.trace.Span;
32-
import io.opencensus.trace.Status;
3330
import java.util.ArrayList;
3431
import java.util.Collections;
3532
import java.util.List;
@@ -77,9 +74,7 @@ public void getPartitions(
7774
PartitionQueryRequest request = buildRequest(desiredPartitionCount);
7875

7976
final PartitionQueryPagedResponse response;
80-
final TraceUtil traceUtil = TraceUtil.getInstance();
81-
Span span = traceUtil.startSpan(TraceUtil.SPAN_NAME_PARTITIONQUERY);
82-
try (Scope scope = traceUtil.getTracer().withSpan(span)) {
77+
try {
8378
response =
8479
ApiExceptions.callAndTranslateApiException(
8580
rpcContext.sendRequest(
@@ -94,10 +89,7 @@ public void getPartitions(
9489

9590
observer.onCompleted();
9691
} catch (ApiException exception) {
97-
span.setStatus(Status.UNKNOWN.withDescription(exception.getMessage()));
9892
throw FirestoreException.forApiException(exception);
99-
} finally {
100-
span.end(TraceUtil.END_SPAN_OPTIONS);
10193
}
10294
}
10395
}
@@ -110,9 +102,7 @@ public ApiFuture<List<QueryPartition>> getPartitions(long desiredPartitionCount)
110102
} else {
111103
PartitionQueryRequest request = buildRequest(desiredPartitionCount);
112104

113-
final TraceUtil traceUtil = TraceUtil.getInstance();
114-
Span span = traceUtil.startSpan(TraceUtil.SPAN_NAME_PARTITIONQUERY);
115-
try (Scope scope = traceUtil.getTracer().withSpan(span)) {
105+
try {
116106
return ApiFutures.transform(
117107
rpcContext.sendRequest(request, rpcContext.getClient().partitionQueryPagedCallable()),
118108
response -> {
@@ -127,10 +117,7 @@ public ApiFuture<List<QueryPartition>> getPartitions(long desiredPartitionCount)
127117
},
128118
MoreExecutors.directExecutor());
129119
} catch (ApiException exception) {
130-
span.setStatus(Status.UNKNOWN.withDescription(exception.getMessage()));
131120
throw FirestoreException.forApiException(exception);
132-
} finally {
133-
span.end(TraceUtil.END_SPAN_OPTIONS);
134121
}
135122
}
136123
}

google-cloud-firestore/src/main/java/com/google/cloud/firestore/CollectionReference.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@
2929
import com.google.firestore.v1.Document;
3030
import com.google.firestore.v1.DocumentMask;
3131
import com.google.firestore.v1.ListDocumentsRequest;
32-
import io.opencensus.common.Scope;
33-
import io.opencensus.trace.Span;
34-
import io.opencensus.trace.Status;
3532
import java.util.Iterator;
3633
import java.util.Map;
3734
import javax.annotation.Nonnull;
@@ -137,20 +134,15 @@ public Iterable<DocumentReference> listDocuments() {
137134
request.setShowMissing(true);
138135

139136
final ListDocumentsPagedResponse response;
140-
final TraceUtil traceUtil = TraceUtil.getInstance();
141-
Span span = traceUtil.startSpan(TraceUtil.SPAN_NAME_LISTDOCUMENTS);
142-
try (Scope scope = traceUtil.getTracer().withSpan(span)) {
137+
try {
143138
FirestoreRpc client = rpcContext.getClient();
144139
UnaryCallable<ListDocumentsRequest, ListDocumentsPagedResponse> callable =
145140
client.listDocumentsPagedCallable();
146141
ListDocumentsRequest build = request.build();
147142
ApiFuture<ListDocumentsPagedResponse> future = rpcContext.sendRequest(build, callable);
148143
response = ApiExceptions.callAndTranslateApiException(future);
149144
} catch (ApiException exception) {
150-
span.setStatus(Status.UNKNOWN.withDescription(exception.getMessage()));
151145
throw FirestoreException.forApiException(exception);
152-
} finally {
153-
span.end(TraceUtil.END_SPAN_OPTIONS);
154146
}
155147

156148
return new Iterable<DocumentReference>() {

google-cloud-firestore/src/main/java/com/google/cloud/firestore/DocumentReference.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@
2424
import com.google.cloud.firestore.v1.FirestoreClient.ListCollectionIdsPagedResponse;
2525
import com.google.common.util.concurrent.MoreExecutors;
2626
import com.google.firestore.v1.ListCollectionIdsRequest;
27-
import io.opencensus.common.Scope;
28-
import io.opencensus.trace.Span;
29-
import io.opencensus.trace.Status;
3027
import java.util.Iterator;
3128
import java.util.List;
3229
import java.util.Map;
@@ -378,18 +375,13 @@ public Iterable<CollectionReference> listCollections() {
378375
ListCollectionIdsRequest.Builder request = ListCollectionIdsRequest.newBuilder();
379376
request.setParent(path.toString());
380377
final ListCollectionIdsPagedResponse response;
381-
final TraceUtil traceUtil = TraceUtil.getInstance();
382-
Span span = traceUtil.startSpan(TraceUtil.SPAN_NAME_LISTCOLLECTIONIDS);
383-
try (Scope scope = traceUtil.getTracer().withSpan(span)) {
378+
try {
384379
response =
385380
ApiExceptions.callAndTranslateApiException(
386381
rpcContext.sendRequest(
387382
request.build(), rpcContext.getClient().listCollectionIdsPagedCallable()));
388383
} catch (ApiException exception) {
389-
span.setStatus(Status.UNKNOWN.withDescription(exception.getMessage()));
390384
throw FirestoreException.forApiException(exception);
391-
} finally {
392-
span.end(TraceUtil.END_SPAN_OPTIONS);
393385
}
394386

395387
return new Iterable<CollectionReference>() {

google-cloud-firestore/src/main/java/com/google/cloud/firestore/FirestoreImpl.java

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,10 @@
3232
import com.google.cloud.firestore.spi.v1.FirestoreRpc;
3333
import com.google.common.annotations.VisibleForTesting;
3434
import com.google.common.base.Preconditions;
35-
import com.google.common.collect.ImmutableMap;
3635
import com.google.firestore.v1.BatchGetDocumentsRequest;
3736
import com.google.firestore.v1.BatchGetDocumentsResponse;
3837
import com.google.firestore.v1.DatabaseRootName;
3938
import com.google.protobuf.ByteString;
40-
import io.opencensus.trace.AttributeValue;
41-
import io.opencensus.trace.Tracer;
42-
import io.opencensus.trace.Tracing;
4339
import java.security.SecureRandom;
4440
import java.util.ArrayList;
4541
import java.util.HashMap;
@@ -61,8 +57,6 @@ class FirestoreImpl implements Firestore, FirestoreRpcContext<FirestoreImpl> {
6157
private static final String AUTO_ID_ALPHABET =
6258
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
6359

64-
private static final Tracer tracer = Tracing.getTracer();
65-
6660
private final FirestoreRpc firestoreClient;
6761
private final FirestoreOptions firestoreOptions;
6862
private final ResourcePath databasePath;
@@ -221,7 +215,7 @@ void getAll(
221215

222216
ResponseObserver<BatchGetDocumentsResponse> responseObserver =
223217
new ResponseObserver<BatchGetDocumentsResponse>() {
224-
int numResponses;
218+
int numResponses = 0;
225219
boolean hasCompleted = false;
226220

227221
@Override
@@ -233,16 +227,6 @@ public void onResponse(BatchGetDocumentsResponse response) {
233227
DocumentSnapshot documentSnapshot;
234228

235229
numResponses++;
236-
if (numResponses == 1) {
237-
tracer
238-
.getCurrentSpan()
239-
.addAnnotation(TraceUtil.SPAN_NAME_BATCHGETDOCUMENTS + ": First response");
240-
} else if (numResponses % 100 == 0) {
241-
tracer
242-
.getCurrentSpan()
243-
.addAnnotation(
244-
TraceUtil.SPAN_NAME_BATCHGETDOCUMENTS + ": Received 100 responses");
245-
}
246230

247231
switch (response.getResultCase()) {
248232
case FOUND:
@@ -277,19 +261,13 @@ public void onResponse(BatchGetDocumentsResponse response) {
277261

278262
@Override
279263
public void onError(Throwable throwable) {
280-
tracer
281-
.getCurrentSpan()
282-
.addAnnotation(TraceUtil.SPAN_NAME_BATCHGETDOCUMENTS + ": Error");
283264
apiStreamObserver.onError(throwable);
284265
}
285266

286267
@Override
287268
public void onComplete() {
288269
if (hasCompleted) return;
289270
hasCompleted = true;
290-
tracer
291-
.getCurrentSpan()
292-
.addAnnotation(TraceUtil.SPAN_NAME_BATCHGETDOCUMENTS + ": Complete");
293271
apiStreamObserver.onCompleted();
294272
}
295273
};
@@ -309,13 +287,6 @@ public void onComplete() {
309287
request.addDocuments(docRef.getName());
310288
}
311289

312-
tracer
313-
.getCurrentSpan()
314-
.addAnnotation(
315-
TraceUtil.SPAN_NAME_BATCHGETDOCUMENTS + ": Start",
316-
ImmutableMap.of(
317-
"numDocuments", AttributeValue.longAttributeValue(documentReferences.length)));
318-
319290
streamRequest(request.build(), responseObserver, firestoreClient.batchGetDocumentsCallable());
320291
}
321292

google-cloud-firestore/src/main/java/com/google/cloud/firestore/Query.java

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
import com.google.cloud.firestore.v1.FirestoreSettings;
4242
import com.google.common.base.Preconditions;
4343
import com.google.common.collect.ImmutableList;
44-
import com.google.common.collect.ImmutableMap;
4544
import com.google.firestore.bundle.BundledQuery;
4645
import com.google.firestore.v1.Cursor;
4746
import com.google.firestore.v1.Document;
@@ -58,8 +57,6 @@
5857
import com.google.protobuf.ByteString;
5958
import com.google.protobuf.Int32Value;
6059
import io.grpc.Status;
61-
import io.opencensus.trace.AttributeValue;
62-
import io.opencensus.trace.Tracing;
6360
import java.util.ArrayList;
6461
import java.util.Arrays;
6562
import java.util.Collections;
@@ -1641,20 +1638,11 @@ private void internalStream(
16411638
request.setReadTime(readTime.toProto());
16421639
}
16431640

1644-
Tracing.getTracer()
1645-
.getCurrentSpan()
1646-
.addAnnotation(
1647-
TraceUtil.SPAN_NAME_RUNQUERY + ": Start",
1648-
ImmutableMap.of(
1649-
"transactional", AttributeValue.booleanAttributeValue(transactionId != null)));
1650-
16511641
final AtomicReference<QueryDocumentSnapshot> lastReceivedDocument = new AtomicReference<>();
16521642

16531643
ResponseObserver<RunQueryResponse> observer =
16541644
new ResponseObserver<RunQueryResponse>() {
16551645
Timestamp readTime;
1656-
boolean firstResponse;
1657-
int numDocuments;
16581646

16591647
// The stream's `onComplete()` could be called more than once,
16601648
// this flag makes sure only the first one is actually processed.
@@ -1665,17 +1653,7 @@ public void onStart(StreamController streamController) {}
16651653

16661654
@Override
16671655
public void onResponse(RunQueryResponse response) {
1668-
if (!firstResponse) {
1669-
firstResponse = true;
1670-
Tracing.getTracer().getCurrentSpan().addAnnotation("Firestore.Query: First response");
1671-
}
16721656
if (response.hasDocument()) {
1673-
numDocuments++;
1674-
if (numDocuments % 100 == 0) {
1675-
Tracing.getTracer()
1676-
.getCurrentSpan()
1677-
.addAnnotation("Firestore.Query: Received 100 documents");
1678-
}
16791657
Document document = response.getDocument();
16801658
QueryDocumentSnapshot documentSnapshot =
16811659
QueryDocumentSnapshot.fromDocument(
@@ -1689,12 +1667,6 @@ public void onResponse(RunQueryResponse response) {
16891667
}
16901668

16911669
if (response.getDone()) {
1692-
Tracing.getTracer()
1693-
.getCurrentSpan()
1694-
.addAnnotation(
1695-
"Firestore.Query: Completed",
1696-
ImmutableMap.of(
1697-
"numDocuments", AttributeValue.longAttributeValue(numDocuments)));
16981670
onComplete();
16991671
}
17001672
}
@@ -1703,10 +1675,6 @@ public void onResponse(RunQueryResponse response) {
17031675
public void onError(Throwable throwable) {
17041676
QueryDocumentSnapshot cursor = lastReceivedDocument.get();
17051677
if (shouldRetry(cursor, throwable)) {
1706-
Tracing.getTracer()
1707-
.getCurrentSpan()
1708-
.addAnnotation("Firestore.Query: Retryable Error");
1709-
17101678
Query.this
17111679
.startAfter(cursor)
17121680
.internalStream(
@@ -1716,7 +1684,6 @@ public void onError(Throwable throwable) {
17161684
options.getRequireConsistency() ? cursor.getReadTime() : null);
17171685

17181686
} else {
1719-
Tracing.getTracer().getCurrentSpan().addAnnotation("Firestore.Query: Error");
17201687
documentObserver.onError(throwable);
17211688
}
17221689
}
@@ -1725,13 +1692,6 @@ public void onError(Throwable throwable) {
17251692
public void onComplete() {
17261693
if (hasCompleted) return;
17271694
hasCompleted = true;
1728-
1729-
Tracing.getTracer()
1730-
.getCurrentSpan()
1731-
.addAnnotation(
1732-
"Firestore.Query: Completed",
1733-
ImmutableMap.of(
1734-
"numDocuments", AttributeValue.longAttributeValue(numDocuments)));
17351695
documentObserver.onCompleted(readTime);
17361696
}
17371697

0 commit comments

Comments
 (0)