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 OpenCensus tracing instrumentation in google-http-client module. #393

Merged

Conversation

HailongWen
Copy link
Contributor

This PR adds OpenCensus-Java instrumentation in to monitor and record events when executing HttpExecute#execute().

The instrumentation starts a Span when the method begins, and is ended before the method exits. The status of the span will be determined according to the status of the response. This Span is stored into local span store, and can be optionally exported if user explicitly configure an exporter (e.g. stackdriver exporter).

Spans can have children. In this case, the generated Span in the instrumentation will be parent of all the Spans generated by server-side procedure. To link the children Span with their parent, the context information should be propagated to server side. This is done by using OpenCensus HTTP Util to inject the information into the header in the request.

Added OpenCensusUtils provides helper methods to perform context propagation, and setting end status of span.

The added dependency of opencensus-api contains basic no-op implementation. It will be replaced by real implementation if user explicitly adds dependency of opencensus-impl or opencensus-impl-lite (for android and gae) in the classpath.

This PR does not contain integration test when opencensus-impl is provided. It can be added with the help of maintainers.

@HailongWen HailongWen force-pushed the opencensus-instrumentation branch from 30e4166 to 9b542cf Compare January 28, 2018 06:40
@HailongWen
Copy link
Contributor Author

Hi @mattwhisenhunt , would you please kindly help on this PR?

Copy link
Contributor

@mattwhisenhunt mattwhisenhunt left a comment

Choose a reason for hiding this comment

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

LGTM

@mattwhisenhunt mattwhisenhunt merged commit 2f67205 into googleapis:dev Jan 29, 2018
* Sets the {@link TextFormat} used in context propagation.
* @param textFormat the text format.
*/
public static void setPropagationTextFormat(@Nullable TextFormat textFormat) {

This comment was marked as spam.

* Sets the {@link TextFormat.Setter} used in context propagation.
* @param textFormatSetter the {@code TextFormat.Setter} for the text format.
*/
public static void setPropagationTextFormatSetter(@Nullable TextFormat.Setter textFormatSetter) {

This comment was marked as spam.

* {@link TextFormat.Setter} for {@link activeTextFormat}.
*/
@Nullable
static TextFormat.Setter propagationTextFormatSetter = null;

This comment was marked as spam.

This comment was marked as spam.

@@ -854,7 +865,9 @@ public HttpResponse execute() throws IOException {
Preconditions.checkNotNull(requestMethod);
Preconditions.checkNotNull(url);

Span span = tracer.spanBuilder(traceSpanNamePrefix + "execute").startSpan();

This comment was marked as spam.

public static void propagateTracingContext(HttpHeaders headers) {
Preconditions.checkNotNull(headers);
if (propagationTextFormat != null && propagationTextFormatSetter != null) {
Span span = tracer.getCurrentSpan();

This comment was marked as spam.

@@ -1057,6 +1076,7 @@ public HttpResponse execute() throws IOException {
}
}
} while (retryRequest);
span.end(OpenCensusUtils.getEndSpanOptions(response == null ? null : response.getStatusCode()));

This comment was marked as spam.

@@ -977,6 +992,8 @@ public HttpResponse execute() throws IOException {

// execute
lowLevelHttpRequest.setTimeout(connectTimeout, readTimeout);
// switch tracing scope to current span
Scope ws = tracer.withSpan(span);

This comment was marked as spam.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants