Skip to content
This repository has been archived by the owner on Jul 1, 2022. It is now read-only.

Fix client/server span classification #102

Merged
merged 5 commits into from
Dec 2, 2016
Merged

Fix client/server span classification #102

merged 5 commits into from
Dec 2, 2016

Conversation

vprithvi
Copy link
Contributor

@vprithvi vprithvi commented Dec 1, 2016

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.

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
@coveralls
Copy link

coveralls commented Dec 1, 2016

Coverage Status

Coverage remained the same at 78.704% when pulling bbfa3eb on fix_lc_traces into 2bcca42 on master.

public void testBuildServerSpan() {
Span span = (com.uber.jaeger.Span) tracer.buildSpan("flexo")
.withTag(Tags.SPAN_KIND.getKey(),
Tags.SPAN_KIND_SERVER).start();
Copy link
Member

Choose a reason for hiding this comment

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

odd formatting

Copy link
Contributor Author

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());
Copy link

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.

Copy link
Contributor Author

@vprithvi vprithvi Dec 1, 2016

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.

Copy link

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.

Copy link
Contributor Author

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() {
Copy link
Member

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

Copy link
Contributor Author

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) {
Copy link
Member

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.

Copy link
Contributor Author

@vprithvi vprithvi Dec 1, 2016

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.

Copy link
Member

@yurishkuro yurishkuro Dec 2, 2016

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

Copy link
Member

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.

Copy link
Contributor Author

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.

@coveralls
Copy link

coveralls commented Dec 1, 2016

Coverage Status

Coverage remained the same at 78.704% when pulling abbc9c2 on fix_lc_traces into 2bcca42 on master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 78.704% when pulling a7b9cd3 on fix_lc_traces into 2bcca42 on master.

@@ -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)
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is what it looks like on my IDE, I think it is reasonable indenting. Putting .buildSpan on the next line would simply move the block to the left by a few characters. Could you elaborate on why the current indenting is insane? Perhaps github is rendering things differently?
image

@coveralls
Copy link

Coverage Status

Coverage remained the same at 78.704% when pulling 66bf80d on fix_lc_traces into 2bcca42 on master.

3 similar comments
@coveralls
Copy link

Coverage Status

Coverage remained the same at 78.704% when pulling 66bf80d on fix_lc_traces into 2bcca42 on master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 78.704% when pulling 66bf80d on fix_lc_traces into 2bcca42 on master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 78.704% when pulling 66bf80d on fix_lc_traces into 2bcca42 on master.

@coveralls
Copy link

coveralls commented Dec 2, 2016

Coverage Status

Coverage remained the same at 78.704% when pulling 66bf80d on fix_lc_traces into 2bcca42 on master.

@vprithvi vprithvi merged commit 0d902d8 into master Dec 2, 2016
@vprithvi vprithvi deleted the fix_lc_traces branch December 2, 2016 05:02
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants