-
Notifications
You must be signed in to change notification settings - Fork 232
Conversation
The Span object has custom logic to set `Span#isRpc` and `Span#isClient` based on the tags passed into `Span#setTag`. Creating a Span using SpanBuilder bypasses this logic causing `Span#isRPC` to be false. This causes ThriftSpanConverter to use lc annotations instead of sr/ss This commit sanitizes input from SpanBuilder so that setting tags on the SpanBuilder results in the same behavior as setting a tag on the Span
public void testBuildServerSpan() { | ||
Span span = (com.uber.jaeger.Span) tracer.buildSpan("flexo") | ||
.withTag(Tags.SPAN_KIND.getKey(), | ||
Tags.SPAN_KIND_SERVER).start(); |
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.
odd formatting
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 update
private void sanitizeAndSetTags(Map<String, Object> tags) { | ||
this.tags = new HashMap<>(); | ||
for (Map.Entry<String, Object> tag : tags.entrySet()) { | ||
setTagAsObject(tag.getKey(), tag.getValue()); |
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.
a little worried about performance here - setTagAsObject locks every time. if sanitizeAndSetTags is only called in the constructor, I don't think we need to worry about syncing.
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.
sanitizeAndSetTags is only called in the constructor, are you suggesting that we create a setTagAsObject
that is not synchronized? Also, the average number of tags passed in are pretty small (<8) and this operation is only performed for spans that are sampled.
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 would suggest not to synchronize ever where we need don't need to synchronize.
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.
Agree, updated.
} | ||
|
||
@Test | ||
public void testBuildClientSpan() { |
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 test seems identical to the one above
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.
Good catch, I'll update
/** | ||
* uses {@link #setTagAsObject} to only insert tags that don't have special significance | ||
*/ | ||
private void sanitizeAndSetTags(Map<String, Object> tags) { |
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.
"sanitize" implies validation and potentially discarding or replacing tags, we do not do that 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.
That's incorrect, we check and discard tags.
For e.g., one can never set a span.kind:server
on the Span
object. It is always discarded after setting the isRPC
field to true. Other tags that are discarded are PEER_PORT, PEER_HOST, PEER_SERVICE, etc.
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.
one can never set a span.kind:server on the Span object. It is always discarded after setting the isRPC field to true.
This method is called from the constructor, so "after" is not applicable. And we do not discard any tags; they may not be stored as tags explicitly, but they are certainly "stored" one way or another. Nothing is being "sanitized" here.
I would just inline this code in the constructor, since it's never reused. It would also allow tags
member variable to be final
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.
Also, once we upgrade this to jaeger.thrift, all this special handling goes away.
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.
And we do not discard any tags; they may not be stored as tags explicitly, but they are certainly "stored" one way or another. Nothing is being "sanitized" here.
I agree that the data contained in the tags are stored one way or the other.
The tags themselves are discarded and cannot be retrieved by Span#getTags
. Generally, if something is not discarded, I expect something set using the setter to be retrievable using a getter.
In the class, setting tags using #setTag
does not follow this behavior.
At any rate, I don't see the point of arguing about semantics here. I'll inline this code.
@@ -66,6 +68,26 @@ public void testBuildSpan() { | |||
} | |||
|
|||
@Test | |||
public void testBuildServerSpan() { | |||
Span span = (com.uber.jaeger.Span) tracer.buildSpan("flexo") | |||
.withTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_SERVER) |
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.
can you put tracer.buildSpan("flexo")
on the 2nd line to avoid the insane indenting by the formatter? Or at least put .buildSpan()
on the second line.
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
Span
object has custom logic to setSpan#isRpc
andSpan#isClient
basedon the tags passed into
Span#setTag
.Creating a
Span
usingSpanBuilder
bypasses this logic causingSpan#isRPC
to befalse. This causes ThriftSpanConverter to use
lc
annotations instead ofsr/ss
This commit sanitizes input from
SpanBuilder
so that setting tags on theSpanBuilder
results in the same behavior as setting a tag on theSpan
.