-
Notifications
You must be signed in to change notification settings - Fork 1.1k
OpenCensus Support for Cloud Pub/Sub #4240
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
Conversation
|
@dinooliva, did @igorbernstein2 reach out to you yet about his work in GAX? That work should supersede this PR. |
|
we are in touch |
sduskis
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.
Please add a some unit tests for this
| <dependency> | ||
| <groupId>io.opencensus</groupId> | ||
| <artifactId>opencensus-api</artifactId> | ||
| <version>${opencensus.version}</version> |
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.
This version should be inherited from google-cloud-clients
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.
Done.
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.
This still needs to be changed. Please remove <version>${opencensus.version}</version>
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.
Seems this dependency is inherited from google-cloud-clients so I can remove it altogether.
| .spanBuilderWithExplicitParent(name, tracer.getCurrentSpan()) | ||
| .setRecordEvents(true) | ||
| // TODO(dpo): set to default. | ||
| .setSampler(Samplers.alwaysSample()) |
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.
@dinooliva, does this need to be fixed before merging?
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.
Yes, as per the TODO() - done now.
| </parent> | ||
| <properties> | ||
| <site.installationModule>google-cloud-pubsub</site.installationModule> | ||
| <opencensus.version>0.15.1</opencensus.version> |
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.
Please remove this variable.
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.
I've moved the variable to google-cloud-clients.
| String encodedSpanContext = message.getAttributesOrDefault(TRACE_CONTEXT_KEY, ""); | ||
| try ( | ||
| Scope spanScope = createScopedSpan("receiver"); | ||
| Scope statsScope = createScopedTagContext(encodedTagContext)) { |
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.
Shouldn't the creation of the span be conditional on the attributes being present?
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.
Done.
| @MustBeClosed | ||
| private static Scope createScopedSpan(String name) { | ||
| return tracer | ||
| .spanBuilderWithExplicitParent(name, tracer.getCurrentSpan()) |
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.
What would be the current span on the receiver side? Shouldn't it start a new root span? Also, shouldn't recordEvents setting be copied from the publisher's span config?
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.
On the receiver side, we create a root span and set the publisher's span as a parent link.
| String encodedTagContext = message.getAttributesOrDefault(TAG_CONTEXT_KEY, ""); | ||
| String encodedSpanContext = message.getAttributesOrDefault(TRACE_CONTEXT_KEY, ""); | ||
| try ( | ||
| Scope spanScope = createScopedSpan("receiver"); |
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.
If I'm not mistaken, there is a good probability that this will be a top level span. Since this is a continuation of the publisher span, maybe it should be prefixed with the publisher span's name?
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.
We don't transfer the Publisher's span name over the wire so it's not available. The link contains the Publisher's trace and span id's so users can find them through that.
| throw new IllegalStateException("Cannot publish on a shut-down publisher."); | ||
| } | ||
|
|
||
| PubsubMessage message = OpenCensusUtil.putOpenCensusAttributes(originalMessage); |
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.
Is there any way to hook into OpenCensus' sampling logic here and avoid increasing request size if the span will not be published?
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.
Done.
| <dependency> | ||
| <groupId>io.opencensus</groupId> | ||
| <artifactId>opencensus-api</artifactId> | ||
| <version>${opencensus.version}</version> |
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.
This still needs to be changed. Please remove <version>${opencensus.version}</version>
| @@ -0,0 +1,193 @@ | |||
| /* Copyright 2018 Google Inc. | |||
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.
s/2018/2019
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.
Done.
| import java.util.logging.Level; | ||
| import java.util.logging.Logger; | ||
|
|
||
| final class OpenCensusUtil { |
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.
class comments are need
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.
Done.
Are class comments necessary even though the class isn't public?
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.
Will we have to make this class public in the new scheme?
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.
Yes, done.
google-cloud-clients/pom.xml
Outdated
| <!-- test dependency versions --> | ||
| <easymock.version>3.4</easymock.version> | ||
| <objenesis.version>2.6</objenesis.version> | ||
| <opencensus.version>0.16.0</opencensus.version> |
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.
There is already an <opencensus.version> above. Please remove this duplicate entry.
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.
Done.
| private static final Tracer tracer = Tracing.getTracer(); | ||
|
|
||
| // Used in Publisher. | ||
| // TODO: consider adding configuration support to control adding these attributes. |
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.
I believe we need the configuration control before merging this. This should be off by default, I would think.
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.
Sure, that makes sense - do you have any links to how configuration is handled in the Google Cloud Java client libraries?
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.
I don't know offhand. I'm just concerned that this will change user behavior without user selecting to turn this on.
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.
The library only has a dependency on the OpenCensus API library, which means this code is a no-op. To enable propagation, an application will need to explicitly add a dependency on an OpenCensus Impl library. This is how configuration is done for other Java cloud client libraries (e.g. cloud bigtable and spanner).
| } | ||
|
|
||
| @Override | ||
| public void receiveMessage(PubsubMessage message, AckReplyConsumer consumer) { |
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.
Do we need configuration here as well, so that the user can define whether or not they want this?
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.
I think that makes sense too.
| private static final Tracer tracer = Tracing.getTracer(); | ||
|
|
||
| // Used in Publisher. | ||
| // TODO: consider adding configuration support to control adding these attributes. |
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.
I don't know offhand. I'm just concerned that this will change user behavior without user selecting to turn this on.
| } | ||
| return "traceid=" + traceId.toLowerBase16() | ||
| + "&spanid=" + spanId.toLowerBase16() | ||
| + "&traceopt=" + (traceOpts.isSampled() ? "t&" : "f&"); |
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.
should this line now be "&traceopt=f&"?
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.
I've changed the text encoding of span to use our standard TraceContext text format.
Codecov Report
@@ Coverage Diff @@
## master #4240 +/- ##
============================================
+ Coverage 49.19% 49.66% +0.47%
- Complexity 21958 22705 +747
============================================
Files 2076 2158 +82
Lines 207416 213518 +6102
Branches 24111 24206 +95
============================================
+ Hits 102033 106043 +4010
- Misses 97207 99182 +1975
- Partials 8176 8293 +117
Continue to review full report at Codecov.
|
…g spec has been finalized (census-instrumentation/opencensus-specs#65).
|
Note: I developed the design of the OpenCensus Pub/Sub integration in conjunction with the Cloud Pub/Sub team. Also, as previously noted, similar to Google Cloud Bigtable and Spanner (and other libraries e.g. gRPC), this feature is inactive unless a dependency on an OpenCensus implementation is added to the application. |
| <artifactId>grpc-google-iam-v1</artifactId> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> |
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.
Do we really need to add opencensus-impl here?
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.
We should not, only the final app should do this.
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.
These are the test dependencies rather than the library dependencies. I use the implementation to test OpenCensusUtil.
| </parent> | ||
| <properties> | ||
| <site.installationModule>google-cloud-pubsub</site.installationModule> | ||
| <opencensus.version>0.15.1</opencensus.version> |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
| <artifactId>grpc-google-iam-v1</artifactId> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> |
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.
We should not, only the final app should do this.
| import java.util.logging.Level; | ||
| import java.util.logging.Logger; | ||
|
|
||
| final class OpenCensusUtil { |
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.
Will we have to make this class public in the new scheme?
| private static final TagContextBinarySerializer serializer = | ||
| Tags.getTagPropagationComponent().getBinarySerializer(); | ||
|
|
||
| private static final TraceOptions SAMPLED = TraceOptions.builder().setIsSampled(true).build(); |
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.
SAMPLED isn't used anymore. Please remove it.
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.
Done.
|
Thanks! |
Adds OpenCensus context propagation to the CPS Publisher and Subscriber. This pr is initially meant for discussion between OpenCensus and CPS.