feat: add opencensus tracing/stats support#130
feat: add opencensus tracing/stats support#130BenWhitehead merged 2 commits intogoogleapis:masterfrom
Conversation
Codecov Report
@@ Coverage Diff @@
## master #130 +/- ##
============================================
- Coverage 58.30% 57.17% -1.13%
Complexity 384 384
============================================
Files 47 48 +1
Lines 2331 2377 +46
Branches 261 264 +3
============================================
Hits 1359 1359
- Misses 865 911 +46
Partials 107 107
Continue to review full report at Codecov.
|
|
@mayurkale22, would you be able to take a quick look at this PR to see if OpenCensus is being used correctly? Thanks heaps. |
d16bb7e to
da7fead
Compare
pom.xml
Outdated
| <guava.version>29.0-android</guava.version> | ||
| <threeten.version>1.4.4</threeten.version> | ||
| <javax.annotations.version>1.3.2</javax.annotations.version> | ||
| <opencensus.version>0.24.0</opencensus.version> |
There was a problem hiding this comment.
I would use latest version: 0.26.0.
There was a problem hiding this comment.
Recently google-cloud-shared-dependencies was added in this client which is pull latest version automatically.
| com.google.datastore.v1.BeginTransactionResponse beginTransaction( | ||
| final com.google.datastore.v1.BeginTransactionRequest requestPb) { | ||
| Span span = traceUtil.startSpan(TraceUtil.SPAN_NAME_BEGINTRANSACTION); | ||
| Scope scope = traceUtil.getTracer().withSpan(span); |
There was a problem hiding this comment.
Personally, I prefer to use try-with-resources for scope. It implements AutoClosable, so it'll be closed when the try block ends. Ex:
try (Scope s = tracer.withSpan(span)) {
... rest of the logic
}| this.datastoreRpc = options.getDatastoreRpcV1(); | ||
| retrySettings = | ||
| MoreObjects.firstNonNull(options.getRetrySettings(), ServiceOptions.getNoRetrySettings()); | ||
| traceUtil = TraceUtil.getInstance(); |
There was a problem hiding this comment.
just set this in the declaration on line 57
| @@ -131,29 +136,41 @@ public T call() throws DatastoreException { | |||
| @Override | |||
| public <T> T runInTransaction(final TransactionCallable<T> callable) { | |||
| final DatastoreImpl self = this; | |||
There was a problem hiding this comment.
this self variable seems pointless
| @Override | ||
| public <T> T runInTransaction( | ||
| final TransactionCallable<T> callable, TransactionOptions transactionOptions) { | ||
| final DatastoreImpl self = this; |
| final TransactionCallable<T> callable, TransactionOptions transactionOptions) { | ||
| final DatastoreImpl self = this; | ||
| Span span = traceUtil.startSpan(TraceUtil.SPAN_NAME_TRANSACTION); | ||
| Scope scope = traceUtil.getTracer().withSpan(span); |
There was a problem hiding this comment.
You can use try with resources for the scope
| com.google.datastore.v1.RunQueryResponse runQuery( | ||
| final com.google.datastore.v1.RunQueryRequest requestPb) { | ||
| Span span = traceUtil.startSpan(TraceUtil.SPAN_NAME_RUNQUERY); | ||
| Scope scope = traceUtil.getTracer().withSpan(span); |
There was a problem hiding this comment.
You can use try with resources for the scope (unless the order of closing the span would be wrong?)
| * Helper class for tracing utility. It is used for instrumenting {@link HttpDatastoreRpc} with Open | ||
| * Census APIs. | ||
| * | ||
| * <p>TraceUtil Instance are created by the {@link TraceUtil#getInstance()} method. |
| */ | ||
| public class TraceUtil { | ||
| private final Tracer tracer = Tracing.getTracer(); | ||
| private static TraceUtil traceUtil; |
| * | ||
| * @return An instance of {@link TraceUtil} | ||
| */ | ||
| public static TraceUtil getInstance() { |
There was a problem hiding this comment.
no need, just create a TraceUtil on the field
| // Open Census initialization | ||
| CensusHttpModule censusHttpModule = | ||
| new CensusHttpModule(TraceUtil.getInstance().getTracer(), true); | ||
| delegate = censusHttpModule.getHttpRequestInitializer(delegate); |
There was a problem hiding this comment.
try to avoid reassigning local variables
|
@mayurkale22 PTAL |
mayurkale22
left a comment
There was a problem hiding this comment.
Added one comment, overall LGTM.
| EXCEPTION_HANDLER, | ||
| getOptions().getClock()); | ||
| } catch (RetryHelperException e) { | ||
| span.setStatus(Status.UNKNOWN.withDescription(e.getMessage())); |
There was a problem hiding this comment.
Any specific reason for Status.UNKNOWN instead of status.INTERNAL? Generally, an example of (UNKNOWN) where this error may be returned is if a Status value received from another address space belongs to an error-space that is not known in this address space. On the other side, Internal errors mean some invariants expected by underlying system has been broken.
Also, DEADLINE_EXCEEDED can be useful in case of retries exceeded.
Having said that, I am not familiar with datastore codebase. Feel free to ignore if you disagree.
|
@elharo PTAL |
|
@elharo gentle ping |
26986bd to
0c18852
Compare
0c18852 to
9d85b03
Compare
|
@BenWhitehead @elharo PTAL |
google-cloud-datastore/src/main/java/com/google/cloud/datastore/TraceUtil.java
Show resolved
Hide resolved
🤖 I have created a release \*beep\* \*boop\* --- ## [1.104.0](https://www.github.com/googleapis/java-datastore/compare/v1.103.0...v1.104.0) (2020-06-17) ### Features * add opencensus tracing/stats support for Datastore RPC operations ([#130](https://www.github.com/googleapis/java-datastore/issues/130)) ([5aee52f](https://www.github.com/googleapis/java-datastore/commit/5aee52f5013d6780e523e0c6d7d00a1826b83b9b)) * add support to customize gcloud command of LocalDatastoreHelper ([#137](https://www.github.com/googleapis/java-datastore/issues/137)) ([976d979](https://www.github.com/googleapis/java-datastore/commit/976d9791572117dc703d8d7d6963bdd6603ecd63)) ### Bug Fixes * fix version number in changelog to correctly reflect what was released to maven central ([#145](https://www.github.com/googleapis/java-datastore/issues/145)) ([c509a2a](https://www.github.com/googleapis/java-datastore/commit/c509a2a4229f864edef8681677d73f3c7be1101f)) ### Dependencies * update dependency com.google.cloud:google-cloud-shared-dependencies to v0.8.0 ([#161](https://www.github.com/googleapis/java-datastore/issues/161)) ([39c8d72](https://www.github.com/googleapis/java-datastore/commit/39c8d723b318d08ca494b71167eaa80b1df6423d)) * update dependency com.google.cloud:google-cloud-shared-dependencies to v0.8.1 ([#163](https://www.github.com/googleapis/java-datastore/issues/163)) ([7bfa07e](https://www.github.com/googleapis/java-datastore/commit/7bfa07eb3a7cf84fcf3e19f6a33914162fa28499)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please).
Fixes #109