Skip to content

Commit

Permalink
fix: Remove OpenCensus tracing code.
Browse files Browse the repository at this point in the history
  • Loading branch information
ehsannas committed Feb 26, 2024
1 parent 27d4bc1 commit 77107e2
Show file tree
Hide file tree
Showing 12 changed files with 6 additions and 261 deletions.
8 changes: 0 additions & 8 deletions google-cloud-firestore/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@
<artifactId>grpc-google-cloud-firestore-v1</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.opencensus</groupId>
<artifactId>opencensus-contrib-grpc-util</artifactId>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
Expand Down Expand Up @@ -91,10 +87,6 @@
<groupId>io.grpc</groupId>
<artifactId>grpc-stub</artifactId>
</dependency>
<dependency>
<groupId>io.opencensus</groupId>
<artifactId>opencensus-api</artifactId>
</dependency>
<dependency>
<groupId>com.google.auth</groupId>
<artifactId>google-auth-library-credentials</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,10 @@
import com.google.api.gax.rpc.ApiException;
import com.google.cloud.Timestamp;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
import com.google.common.util.concurrent.MoreExecutors;
import com.google.firestore.v1.BatchWriteRequest;
import com.google.firestore.v1.BatchWriteResponse;
import io.grpc.Status;
import io.opencensus.trace.AttributeValue;
import io.opencensus.trace.Tracing;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
Expand Down Expand Up @@ -69,12 +66,6 @@ ApiFuture<WriteResult> wrapResult(int writeIndex) {
* <p>The writes in the batch are not applied atomically and can be applied out of order.
*/
ApiFuture<Void> bulkCommit() {
Tracing.getTracer()
.getCurrentSpan()
.addAnnotation(
TraceUtil.SPAN_NAME_BATCHWRITE,
ImmutableMap.of("numDocuments", AttributeValue.longAttributeValue(getWrites().size())));

final BatchWriteRequest.Builder request = BatchWriteRequest.newBuilder();
request.setDatabase(firestore.getDatabaseName());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@
import com.google.common.util.concurrent.MoreExecutors;
import com.google.firestore.v1.Cursor;
import com.google.firestore.v1.PartitionQueryRequest;
import io.opencensus.common.Scope;
import io.opencensus.trace.Span;
import io.opencensus.trace.Status;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -77,9 +74,7 @@ public void getPartitions(
PartitionQueryRequest request = buildRequest(desiredPartitionCount);

final PartitionQueryPagedResponse response;
final TraceUtil traceUtil = TraceUtil.getInstance();
Span span = traceUtil.startSpan(TraceUtil.SPAN_NAME_PARTITIONQUERY);
try (Scope scope = traceUtil.getTracer().withSpan(span)) {
try {
response =
ApiExceptions.callAndTranslateApiException(
rpcContext.sendRequest(
Expand All @@ -94,10 +89,7 @@ public void getPartitions(

observer.onCompleted();
} catch (ApiException exception) {
span.setStatus(Status.UNKNOWN.withDescription(exception.getMessage()));
throw FirestoreException.forApiException(exception);
} finally {
span.end(TraceUtil.END_SPAN_OPTIONS);
}
}
}
Expand All @@ -110,9 +102,7 @@ public ApiFuture<List<QueryPartition>> getPartitions(long desiredPartitionCount)
} else {
PartitionQueryRequest request = buildRequest(desiredPartitionCount);

final TraceUtil traceUtil = TraceUtil.getInstance();
Span span = traceUtil.startSpan(TraceUtil.SPAN_NAME_PARTITIONQUERY);
try (Scope scope = traceUtil.getTracer().withSpan(span)) {
try {
return ApiFutures.transform(
rpcContext.sendRequest(request, rpcContext.getClient().partitionQueryPagedCallable()),
response -> {
Expand All @@ -127,10 +117,7 @@ public ApiFuture<List<QueryPartition>> getPartitions(long desiredPartitionCount)
},
MoreExecutors.directExecutor());
} catch (ApiException exception) {
span.setStatus(Status.UNKNOWN.withDescription(exception.getMessage()));
throw FirestoreException.forApiException(exception);
} finally {
span.end(TraceUtil.END_SPAN_OPTIONS);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@
import com.google.firestore.v1.Document;
import com.google.firestore.v1.DocumentMask;
import com.google.firestore.v1.ListDocumentsRequest;
import io.opencensus.common.Scope;
import io.opencensus.trace.Span;
import io.opencensus.trace.Status;
import java.util.Iterator;
import java.util.Map;
import javax.annotation.Nonnull;
Expand Down Expand Up @@ -137,20 +134,15 @@ public Iterable<DocumentReference> listDocuments() {
request.setShowMissing(true);

final ListDocumentsPagedResponse response;
final TraceUtil traceUtil = TraceUtil.getInstance();
Span span = traceUtil.startSpan(TraceUtil.SPAN_NAME_LISTDOCUMENTS);
try (Scope scope = traceUtil.getTracer().withSpan(span)) {
try {
FirestoreRpc client = rpcContext.getClient();
UnaryCallable<ListDocumentsRequest, ListDocumentsPagedResponse> callable =
client.listDocumentsPagedCallable();
ListDocumentsRequest build = request.build();
ApiFuture<ListDocumentsPagedResponse> future = rpcContext.sendRequest(build, callable);
response = ApiExceptions.callAndTranslateApiException(future);
} catch (ApiException exception) {
span.setStatus(Status.UNKNOWN.withDescription(exception.getMessage()));
throw FirestoreException.forApiException(exception);
} finally {
span.end(TraceUtil.END_SPAN_OPTIONS);
}

return new Iterable<DocumentReference>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@
import com.google.cloud.firestore.v1.FirestoreClient.ListCollectionIdsPagedResponse;
import com.google.common.util.concurrent.MoreExecutors;
import com.google.firestore.v1.ListCollectionIdsRequest;
import io.opencensus.common.Scope;
import io.opencensus.trace.Span;
import io.opencensus.trace.Status;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -378,18 +375,13 @@ public Iterable<CollectionReference> listCollections() {
ListCollectionIdsRequest.Builder request = ListCollectionIdsRequest.newBuilder();
request.setParent(path.toString());
final ListCollectionIdsPagedResponse response;
final TraceUtil traceUtil = TraceUtil.getInstance();
Span span = traceUtil.startSpan(TraceUtil.SPAN_NAME_LISTCOLLECTIONIDS);
try (Scope scope = traceUtil.getTracer().withSpan(span)) {
try {
response =
ApiExceptions.callAndTranslateApiException(
rpcContext.sendRequest(
request.build(), rpcContext.getClient().listCollectionIdsPagedCallable()));
} catch (ApiException exception) {
span.setStatus(Status.UNKNOWN.withDescription(exception.getMessage()));
throw FirestoreException.forApiException(exception);
} finally {
span.end(TraceUtil.END_SPAN_OPTIONS);
}

return new Iterable<CollectionReference>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,10 @@
import com.google.cloud.firestore.spi.v1.FirestoreRpc;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
import com.google.firestore.v1.BatchGetDocumentsRequest;
import com.google.firestore.v1.BatchGetDocumentsResponse;
import com.google.firestore.v1.DatabaseRootName;
import com.google.protobuf.ByteString;
import io.opencensus.trace.AttributeValue;
import io.opencensus.trace.Tracer;
import io.opencensus.trace.Tracing;
import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.HashMap;
Expand All @@ -61,8 +57,6 @@ class FirestoreImpl implements Firestore, FirestoreRpcContext<FirestoreImpl> {
private static final String AUTO_ID_ALPHABET =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";

private static final Tracer tracer = Tracing.getTracer();

private final FirestoreRpc firestoreClient;
private final FirestoreOptions firestoreOptions;
private final ResourcePath databasePath;
Expand Down Expand Up @@ -221,7 +215,7 @@ void getAll(

ResponseObserver<BatchGetDocumentsResponse> responseObserver =
new ResponseObserver<BatchGetDocumentsResponse>() {
int numResponses;
int numResponses = 0;
boolean hasCompleted = false;

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

numResponses++;
if (numResponses == 1) {
tracer
.getCurrentSpan()
.addAnnotation(TraceUtil.SPAN_NAME_BATCHGETDOCUMENTS + ": First response");
} else if (numResponses % 100 == 0) {
tracer
.getCurrentSpan()
.addAnnotation(
TraceUtil.SPAN_NAME_BATCHGETDOCUMENTS + ": Received 100 responses");
}

switch (response.getResultCase()) {
case FOUND:
Expand Down Expand Up @@ -277,19 +261,13 @@ public void onResponse(BatchGetDocumentsResponse response) {

@Override
public void onError(Throwable throwable) {
tracer
.getCurrentSpan()
.addAnnotation(TraceUtil.SPAN_NAME_BATCHGETDOCUMENTS + ": Error");
apiStreamObserver.onError(throwable);
}

@Override
public void onComplete() {
if (hasCompleted) return;
hasCompleted = true;
tracer
.getCurrentSpan()
.addAnnotation(TraceUtil.SPAN_NAME_BATCHGETDOCUMENTS + ": Complete");
apiStreamObserver.onCompleted();
}
};
Expand All @@ -309,13 +287,6 @@ public void onComplete() {
request.addDocuments(docRef.getName());
}

tracer
.getCurrentSpan()
.addAnnotation(
TraceUtil.SPAN_NAME_BATCHGETDOCUMENTS + ": Start",
ImmutableMap.of(
"numDocuments", AttributeValue.longAttributeValue(documentReferences.length)));

streamRequest(request.build(), responseObserver, firestoreClient.batchGetDocumentsCallable());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import com.google.cloud.firestore.v1.FirestoreSettings;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.firestore.bundle.BundledQuery;
import com.google.firestore.v1.Cursor;
import com.google.firestore.v1.Document;
Expand All @@ -58,8 +57,6 @@
import com.google.protobuf.ByteString;
import com.google.protobuf.Int32Value;
import io.grpc.Status;
import io.opencensus.trace.AttributeValue;
import io.opencensus.trace.Tracing;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
Expand Down Expand Up @@ -1641,20 +1638,11 @@ private void internalStream(
request.setReadTime(readTime.toProto());
}

Tracing.getTracer()
.getCurrentSpan()
.addAnnotation(
TraceUtil.SPAN_NAME_RUNQUERY + ": Start",
ImmutableMap.of(
"transactional", AttributeValue.booleanAttributeValue(transactionId != null)));

final AtomicReference<QueryDocumentSnapshot> lastReceivedDocument = new AtomicReference<>();

ResponseObserver<RunQueryResponse> observer =
new ResponseObserver<RunQueryResponse>() {
Timestamp readTime;
boolean firstResponse;
int numDocuments;

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

@Override
public void onResponse(RunQueryResponse response) {
if (!firstResponse) {
firstResponse = true;
Tracing.getTracer().getCurrentSpan().addAnnotation("Firestore.Query: First response");
}
if (response.hasDocument()) {
numDocuments++;
if (numDocuments % 100 == 0) {
Tracing.getTracer()
.getCurrentSpan()
.addAnnotation("Firestore.Query: Received 100 documents");
}
Document document = response.getDocument();
QueryDocumentSnapshot documentSnapshot =
QueryDocumentSnapshot.fromDocument(
Expand All @@ -1689,12 +1667,6 @@ public void onResponse(RunQueryResponse response) {
}

if (response.getDone()) {
Tracing.getTracer()
.getCurrentSpan()
.addAnnotation(
"Firestore.Query: Completed",
ImmutableMap.of(
"numDocuments", AttributeValue.longAttributeValue(numDocuments)));
onComplete();
}
}
Expand All @@ -1703,10 +1675,6 @@ public void onResponse(RunQueryResponse response) {
public void onError(Throwable throwable) {
QueryDocumentSnapshot cursor = lastReceivedDocument.get();
if (shouldRetry(cursor, throwable)) {
Tracing.getTracer()
.getCurrentSpan()
.addAnnotation("Firestore.Query: Retryable Error");

Query.this
.startAfter(cursor)
.internalStream(
Expand All @@ -1716,7 +1684,6 @@ public void onError(Throwable throwable) {
options.getRequireConsistency() ? cursor.getReadTime() : null);

} else {
Tracing.getTracer().getCurrentSpan().addAnnotation("Firestore.Query: Error");
documentObserver.onError(throwable);
}
}
Expand All @@ -1725,13 +1692,6 @@ public void onError(Throwable throwable) {
public void onComplete() {
if (hasCompleted) return;
hasCompleted = true;

Tracing.getTracer()
.getCurrentSpan()
.addAnnotation(
"Firestore.Query: Completed",
ImmutableMap.of(
"numDocuments", AttributeValue.longAttributeValue(numDocuments)));
documentObserver.onCompleted(readTime);
}

Expand Down
Loading

0 comments on commit 77107e2

Please sign in to comment.