Skip to content
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

Add initial opencensus instrumentation code in Cloud Storage. #2846

Merged
merged 5 commits into from
Feb 9, 2018

Conversation

HailongWen
Copy link

@HailongWen HailongWen commented Feb 3, 2018

This PR adds OpenCensus-Java instrumentation to monitor and record events in Cloud Storage client and propagate the trace context via HTTP headers to google service.

Note that there is another PR to instrument underlying library google-http-java-client is also instrumented so as to provide detailed span break down. In case that we don't catch up new release of google-http-java-client, in this PR I still added helper class to do context propagation.

There are 3 major changes in this PR:

  • Added a helper class CensusHttpModule to do trace context propagation through HttpHeaders. (might be temporary - can be removed if google-http-java-client release new version)
  • Added a helper class HttpStorageRpcSpans, which contains all span names and a method to register them all for collection.
  • Added instrumentation code in HttpStorageRpc. The instrumented code starts a new Span the main logic of the method begins, set it as current span with Tracer.withSpan. If exception occurs during the execution, the span status will be set to Status.UNKNOWN to indicate unparsed exception. The span and its scope will be ended before method exits.

All the above Spans will be stored into local span store, and can be optionally exported if user explicitly configure an exporter (e.g. stackdriver exporter).

Please @hzyi-google and @bogdandrutu kindly help review.

@HailongWen HailongWen requested a review from pongad as a code owner February 3, 2018 01:31
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Feb 3, 2018
// Open Census initialization
censusHttpModule = new CensusHttpModule(tracer, true);
initializer = censusHttpModule.getHttpRequestInitializer(initializer);
batchRequestInitializer = censusHttpModule.getHttpRequestInitializer(null);

This comment was marked as spam.

@@ -112,7 +129,8 @@ public HttpStorageRpc(StorageOptions options) {
private DefaultRpcBatch(Storage storage) {
this.storage = storage;
batches = new LinkedList<>();
batches.add(storage.batch());
// add OpenCensus HttpRequestInitializer
batches.add(storage.batch(batchRequestInitializer));

This comment was marked as spam.

@@ -162,12 +180,22 @@ public void addGet(StorageObject storageObject, RpcBatch.Callback<StorageObject>

@Override
public void submit() {

This comment was marked as spam.

This comment was marked as spam.


/**
* An {@link HttpRequestInitializer} implementation to set {@link CensusHttpExecuteInterceptor} as
* intercptor.

This comment was marked as spam.

This comment was marked as spam.

@pongad
Copy link
Contributor

pongad commented Feb 6, 2018

@HailongWen I see the WIP in the title. Is this ready to review now?

@HailongWen HailongWen changed the title [WIP] Add initial opencensus instrumentation code in Cloud Storage. Add initial opencensus instrumentation code in Cloud Storage. Feb 6, 2018
@HailongWen
Copy link
Author

@pongad Yes. Sorry for the confusion. I have changed the title.

@yihanzhen
Copy link
Contributor

LGTM +1

Copy link
Contributor

@pongad pongad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM as well. @garrettjonesgoogle do you want to take a look?

@@ -162,12 +180,22 @@ public void addGet(StorageObject storageObject, RpcBatch.Callback<StorageObject>

@Override
public void submit() {

This comment was marked as spam.

@@ -1052,11 +1052,21 @@
<artifactId>opencensus-api</artifactId>
<version>${opencensus.version}</version>
</dependency>
<dependency>

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

* Add helper class `CensusHttpModule` to do trace context propagation.

* Add helper class `HttpStorageRpcSpans` to define and register
different span names.

* Add instrumentation code in `HttpStorageRpc`.

* Update errorprone version to 2.2.0.
@HailongWen HailongWen force-pushed the opencensus-instrumentation branch from bae5c39 to f14c3bb Compare February 8, 2018 19:08
@pongad pongad merged commit 8121f07 into googleapis:master Feb 9, 2018
@HailongWen
Copy link
Author

Thank you all for the help and support!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants