Conversation
|
@dmichel1 tracing PR as mentioned, would be awesome if you could take a look |
e8c5014 to
8f581a9
Compare
dmichel1
left a comment
There was a problem hiding this comment.
left a few comments.
can you add how to use this to the readme as well?
exciting!
| requireNonNull(future); | ||
| requireNonNull(operation); | ||
|
|
||
| final io.opencensus.trace.Tracer tracer = Tracing.getTracer(); |
There was a problem hiding this comment.
typically this is a static variable - https://github.com/census-instrumentation/opencensus-java/blob/master/examples/src/main/java/io/opencensus/examples/trace/MultiSpansTracing.java#L31
There was a problem hiding this comment.
Ah cool, will fix.
| ocSpan.putAttribute("component", stringAttributeValue("folsom")); | ||
| ocSpan.putAttribute("peer.service", stringAttributeValue("memcache")); | ||
| ocSpan.putAttribute("operation", stringAttributeValue(operation)); | ||
| if (key != null) { |
There was a problem hiding this comment.
should adding the key as an annotation be configurable? I'm thinking there might be scenarios where key is "sensitive."
There was a problem hiding this comment.
I was thinking about this, which is why I opted not to include the value. But perhaps this is worth considering also with the key.
There was a problem hiding this comment.
knowing what key is potentially causing an issue could definitely be valuable during troubleshooting so I can see the benefit of leaving it here/enabled by default...
what about adding another attribute for the size of the payload being sent to memcached? that could also be valuable during troubleshooting
There was a problem hiding this comment.
Great suggestions! Pushed an update for addressing both of these. There's now a builder to configure if you want keys/values included in traces. Also added value size.
|
|
||
| final io.opencensus.trace.Tracer tracer = Tracing.getTracer(); | ||
|
|
||
| final io.opencensus.trace.Span ocSpan = |
There was a problem hiding this comment.
this is the trickiest part of tracing especially with async operations happening...
with this implicit context propagation traces spans might not be linked when they go from a say an apollo thread pool -> memcached thread pool.
if this is indeed the case here, the span can be added as parameter to these methods and passed in with the memcached operation. This would then become tracer.spanBuilderWithExplicitParent()
There was a problem hiding this comment.
Yeah, this assumes that the context is propagated to the calling thread/gRPC Context. Once in Folsom-land, this should works as expected. But, this would be equally true for tracing in say Bigtable/Spanner, right (I've only looked at the Spanner client and it seems to use the same pattern as here)? If so, I believe we should make sure we propagate the tracing context correctly at least out of the box in Apollo, is this the case today?
There was a problem hiding this comment.
we should be propagating the context in apollo correctly as the traces to any gRPC based service (bigtable/pubsub/spanner) are linked already. have you tried testing this code with an apollo services yet?
There was a problem hiding this comment.
I haven't yet, but got a service hopefully lined up
There was a problem hiding this comment.
I think this pattern is generally used for many libraries, Bigtable does it similarly. It may be useful to allow passing in the parent span instead of solely relying on getCurrentSpan - that way if the calling code is doing something unusual there's a way to keep the context correctly linked.
There was a problem hiding this comment.
@hexedpackets do you have a reference handy to how this is done in Bigtable, would be curious as to how they opted to design it? I tried to find, but not sure I'm looking in the right place.
For now, I would not want to change the Folsom API in order to support tracing, but if we see more requests from users on setting explicit parent spans I think we should look closer at how to do this in the future.
There was a problem hiding this comment.
That makes sense, I think the use case of needing to pass in the parent span should be pretty rare.
Bigtable creates a span when the operation is instantiated and then closes it in a callback after the operation ends. I don't think this is passed around, but various functions in the class add tags and annotations to the span when they're run.
| SetRequest request = SetRequest.casSet(byteKey, valueBytes, ttl, cas); | ||
| CompletionStage<MemcacheStatus> future = rawMemcacheClient.send(request); | ||
| metrics.measureSetFuture(future); | ||
| tracer.span("folsom.set", future, "set", key); |
There was a problem hiding this comment.
If we need to do explicit propagation this would have to look something like...
public CompletionStage<MemcacheStatus> set(String key, V value, int ttl, long cas, Span span) {
...
tracer.span("folsom.set", future, "set", key, span);There was a problem hiding this comment.
I'd like to avoid polluting the Folsom API if at all possible :)
|
Fix pushed which addresses comments so far, including an updated README |
dmichel1
left a comment
There was a problem hiding this comment.
Couple more comments and then let's try this out.
README.md
Outdated
| </dependency> | ||
|
|
||
| If you want to use one of the metric libraries, make sure you use the same version as the main artifact. | ||
| <!-- optional if you want to expose folsom metrics with yammer --> |
There was a problem hiding this comment.
s/folsom metrics with yammer/traces with OpenCensus/
| if (includeValues) { | ||
| span.putAttribute("value_hex", stringAttributeValue(HEX.encode(value))); | ||
| } | ||
| span.putAttribute("value_size", longAttributeValue(value.length)); |
There was a problem hiding this comment.
include the unit here. e.g. value_size_bytes
| public class OpenCensus { | ||
|
|
||
| private static final boolean DEFAULT_INCLUDE_KEYS = true; | ||
| private static final boolean DEFAULT_INCLUDE_VALUES = false; |
There was a problem hiding this comment.
I'm a bit concerned about someone enabling the value attribute. It could be a really big payload. I think since folks have the ability to see the key if they really care about the value they can fetch it themselves.
I would be in favor of removing the value attribute entirely.
There was a problem hiding this comment.
I think it's fine as long as this is default to off, but I'll add a note about this in the documentation.
This add support for tracing memcache operations, including an implementation for OpenCensus. This change opts to only trace high level operations for the sake of simplicity. It will for example not trace operations to individual nodes (e.g. for delete all operations). As we learn more about tracing needs, we might change this to include more fine-grained operations. The OpenCensus implementation attempts to use the OpenTracing conventions for attributes: https://opentracing.io/specification/conventions/
This PR is based on top of #135 so please review that first.