-
Notifications
You must be signed in to change notification settings - Fork 104
Opencensus Tracing: Add plumbing for tracing #633
Conversation
This has been extracted from googleapis#613 This doesn't provide any extra functionality. Instead it just sets up the foundation for integrating tracing in to gax. The general idea is to add a tracing abstraction layer that all parts of gax can call into. This is accomplished by introducing - ApiTracer interface that has methods for all annotations that a span should contain - ApiTracerFactory interface: since an ApiTracer is stateful and has a 1:1 mapping with operations, a factory is introduced to cleanly switch implementations of the tracer By default a NoopApiTracerFactory is configured that will return NoopApiTracers. In the future a parallel OpenCensusApiTracerFactory will be added. A client implementation will be able to opt into tracing by setting the factory in StubSettings. The actual ApiTracer will be propagated by CallContext.
Codecov Report
@@ Coverage Diff @@
## master #633 +/- ##
============================================
- Coverage 74.93% 74.18% -0.76%
- Complexity 935 938 +3
============================================
Files 177 180 +3
Lines 4102 4164 +62
Branches 328 333 +5
============================================
+ Hits 3074 3089 +15
- Misses 875 919 +44
- Partials 153 156 +3
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #633 +/- ##
============================================
- Coverage 74.93% 74.56% -0.38%
- Complexity 935 949 +14
============================================
Files 177 180 +3
Lines 4102 4172 +70
Branches 328 334 +6
============================================
+ Hits 3074 3111 +37
- Misses 875 908 +33
Partials 153 153
Continue to review full report at Codecov.
|
This depends on googleapis#633 and is extracted from googleapis#613. This introduces TracedUnaryCallables that will create a trace and complete it. It is inserted as one of the outermost links in the callable chain to allow all other callables to contribute their annotations. google-cloud-java that extend the chains (like cloud bigtable) will also use this class to trace their extensions.
This depends on googleapis#633 and is extracted from googleapis#613. This introduces TracedServerStreamingCallables that will create a trace and complete it. It is inserted as one of the outermost links in the callable chain to allow all other callables to contribute their annotations. google-cloud-java that extend the chains (like cloud bigtable) will also use this class to trace their extensions.
This depends on googleapis#633 and is extracted from googleapis#613. This introduces TracedBidiCallables that will create a trace and complete it. It is inserted as one of the outermost links in the callable chain to allow all other callables to contribute their annotations. google-cloud-java that extend the chains (like cloud bigtable) will also use this class to trace their extensions.
This depends on googleapis#633 and is extracted from googleapis#613. This introduces TracedBidiCallables that will create a trace and complete it. It is inserted as one of the outermost links in the callable chain to allow all other callables to contribute their annotations. google-cloud-java that extend the chains (like cloud bigtable) will also use this class to trace their extensions.
This depends on googleapis#633 and is extracted from googleapis#613. This introduces TracedClientStreamCallables that will create a trace and complete it. It is inserted as one of the outermost links in the callable chain to allow all other callables to contribute their annotations. google-cloud-java that extend the chains (like cloud bigtable) will also use this class to trace their extensions.
vam-google
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general looks good. My only real concern is: do we really want to abstract opencensus completely (please read ApiTracer review comment for more details)?
| @BetaApi("Reference ApiCallContext instead - this class is likely to experience breaking changes") | ||
| @InternalExtensionOnly | ||
| public final class GrpcCallContext implements ApiCallContext { | ||
| private static final CallOptions.Key<ApiTracer> TRACER_KEY = Key.create("gax.tracer"); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| @Override | ||
| public ApiTracer getTracer() { | ||
| if (tracer == null) { | ||
| return NoopApiTracer.create(); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
|
||
| private NoopApiTracer() {} | ||
|
|
||
| public static ApiTracer create() { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| * Signals that the overall operation has failed and no further attempts will be made. The tracer | ||
| * is now considered closed and should no longer be used. | ||
| */ | ||
| void operationFailed(Throwable error); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| * {@link Scope} removes any context that the underlying implementation might've set in {@link | ||
| * #inScope()}. | ||
| */ | ||
| interface Scope extends AutoCloseable { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| @@ -0,0 +1,45 @@ | |||
| /* | |||
| * Copyright 2017 Google LLC | |||
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| import com.google.api.core.InternalApi; | ||
|
|
||
| /** | ||
| * Factory that will build fake {@link ApiTracer}s. |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
|
||
| @Override | ||
| public boolean equals(Object obj) { | ||
| return obj instanceof NoopApiTracerFactory; |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| /** | ||
| * Creates a new instance of the name. | ||
| * | ||
| * @param clientName The name of the client. ie BigtableData |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| public abstract String getMethodName(); | ||
|
|
||
| /** Creates a new instance with the clientName overriden. */ | ||
| public SpanName withClientName(String clientName) { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
vam-google
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general LGTM, with several semi-important comments. Please address those before submitting, if found reasonable.
| public abstract String getMethodName(); | ||
|
|
||
| /** Creates a new instance with the clientName overriden. */ | ||
| public SpanName withClientName(String clientName) { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| HttpJsonCallContext ctxWithDefaultTracer = HttpJsonCallContext.createDefault(); | ||
| ApiTracer defaultTracer = ctxWithDefaultTracer.getTracer(); | ||
|
|
||
| // Explicit tracers override default tracers |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| Truth.assertThat(ctxWithDefaultTracer.merge(ctxWithExplicitTracer).getTracer()) | ||
| .isSameAs(explicitTracer); | ||
|
|
||
| // Default tracer do not override explicit tracers |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| @BetaApi("Reference ApiCallContext instead - this class is likely to experience breaking changes") | ||
| @InternalExtensionOnly | ||
| public final class GrpcCallContext implements ApiCallContext { | ||
| private static final CallOptions.Key<ApiTracer> TRACER_KEY = Key.create("gax.tracer"); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
|
I think addressed all of the concerns. Thanks for the review! I'm gonna go ahead and merge this. If there is anything else I should change I'll do it in a follow up PR |
This depends on googleapis#633 and is extracted from googleapis#613. This introduces TracedUnaryCallables that will create a trace and complete it. It is inserted as one of the outermost links in the callable chain to allow all other callables to contribute their annotations. google-cloud-java that extend the chains (like cloud bigtable) will also use this class to trace their extensions.
This depends on googleapis#633 and is extracted from googleapis#613. This introduces TracedServerStreamingCallables that will create a trace and complete it. It is inserted as one of the outermost links in the callable chain to allow all other callables to contribute their annotations. google-cloud-java that extend the chains (like cloud bigtable) will also use this class to trace their extensions.
This depends on googleapis#633 and is extracted from googleapis#613. This introduces TracedBidiCallables that will create a trace and complete it. It is inserted as one of the outermost links in the callable chain to allow all other callables to contribute their annotations. google-cloud-java that extend the chains (like cloud bigtable) will also use this class to trace their extensions.
This depends on googleapis#633 and is extracted from googleapis#613. This introduces TracedClientStreamCallables that will create a trace and complete it. It is inserted as one of the outermost links in the callable chain to allow all other callables to contribute their annotations. google-cloud-java that extend the chains (like cloud bigtable) will also use this class to trace their extensions.
* Start tracing unary callable. This depends on #633 and is extracted from #613. This introduces TracedUnaryCallables that will create a trace and complete it. It is inserted as one of the outermost links in the callable chain to allow all other callables to contribute their annotations. google-cloud-java that extend the chains (like cloud bigtable) will also use this class to trace their extensions. * trace http json calls as well * fix test * oops * a bit more work * improve method name parsing * address feedback * trace operation cancellation and use static mockito imports in tests * address feedback
* Start tracing bidi streaming callables. This depends on #633 and is extracted from #613. This introduces TracedBidiCallables that will create a trace and complete it. It is inserted as one of the outermost links in the callable chain to allow all other callables to contribute their annotations. google-cloud-java that extend the chains (like cloud bigtable) will also use this class to trace their extensions. * fixes * cancellation & static imports * address some feedback * address more feedback
* Start tracing client streaming callables. This depends on #633 and is extracted from #613. This introduces TracedClientStreamCallables that will create a trace and complete it. It is inserted as one of the outermost links in the callable chain to allow all other callables to contribute their annotations. google-cloud-java that extend the chains (like cloud bigtable) will also use this class to trace their extensions. * fixes * handle operation cancellation & use static imports * address feedbac * fix merge * address feedback * address feedback
This has been extracted from #613
This doesn't provide any extra functionality. Instead it just sets up the foundation for integrating tracing in to gax.
The general idea is to add a tracing abstraction layer that all parts of gax can call into. This is accomplished by introducing
By default a NoopApiTracerFactory is configured that will return NoopApiTracers. In the future a parallel OpenCensusApiTracerFactory will be added. A client implementation will be able to opt into tracing by setting the factory in StubSettings. The actual ApiTracer will be propagated by CallContext.