-
Notifications
You must be signed in to change notification settings - Fork 232
Reduce visibility of TextMapCodec.contextFromString to package scope #519
Reduce visibility of TextMapCodec.contextFromString to package scope #519
Conversation
Signed-off-by: Isaac Hier <ihier@uber.com>
assertEquals(traceId, contextFromStr.getTraceId()); | ||
assertEquals(spanId, contextFromStr.getSpanId()); | ||
assertEquals(parentId, contextFromStr.getParentId()); | ||
assertEquals(flags, contextFromStr.getFlags()); |
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.
don't see how removing this makes the test equivalent. But this whole test can move to text codec test, since it's not really testing the context toString
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.
Right let me fix that.
assertEquals(expectedContext.getTraceId(), actualContext.getTraceId()); | ||
assertEquals(expectedContext.getSpanId(), actualContext.getSpanId()); | ||
assertEquals(expectedContext.getParentId(), actualContext.getParentId()); | ||
assertEquals(expectedContext.getFlags(), actualContext.getFlags()); |
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.
removing it is not equivalent. But you can change L215 to use TextMapCodec's extract method.
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 am not sure if this still applies. See testSpanToString in TextMapCodec
.
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.
Here's what I am thinking. The method is called testSpanToString
. Such method should belong in SpanTest class, not the codecs. But it's not actually testing span.toString()
, only spanContext.contextAsString()
. So let's separate these.
- to test
span.toString()
, we can simply compare with an exact literal string (including the operation name). - what is the contract of
contextAsString()
? Do we, strictly speaking, care if the output matches the output of the codec? What if we use a different codec in the future? I think it mattered more when span context had the oppositefromString()
method, but nowcontextAsString()
seems merely a dependency ofspan.toString()
, nothing more. Or is it used elsewhere? If not, we can not test it at all (since it's covered byspan.toString()
test), and we can consider making it package viz.
Counter-proposal: keep the test here (since it's testing Span's behavior, not the codec), but
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.
But what? :)
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.
sorry, a left over
Codecov Report
@@ Coverage Diff @@
## master #519 +/- ##
===========================================
+ Coverage 88.26% 88.37% +0.1%
Complexity 500 500
===========================================
Files 65 65
Lines 1849 1849
Branches 239 239
===========================================
+ Hits 1632 1634 +2
+ Misses 141 138 -3
- Partials 76 77 +1
Continue to review full report at Codecov.
|
Signed-off-by: Isaac Hier <ihier@uber.com>
byte flags = (byte) 129; | ||
|
||
// I use MIN_VALUE because the most significant bit, and thats when | ||
// we want to make sure the hex number is positive. |
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 comment looks like some old left-over. Doesn't seem to make any sense now.
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.
Signed-off-by: Isaac Hier <ihier@uber.com>
Signed-off-by: Isaac Hier <ihier@uber.com>
Signed-off-by: Isaac Hier <ihier@uber.com>
@@ -78,7 +78,7 @@ public static JaegerSpanContext contextFromString(String value) | |||
|
|||
@Override | |||
public void inject(JaegerSpanContext spanContext, TextMap carrier) { | |||
carrier.put(contextKey, encodedValue(spanContext.contextAsString())); | |||
carrier.put(contextKey, encodedValue(spanContext.toString())); |
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 think it's a good idea to rely on toString() for marshaling purposes.
Maybe do the same thing as with fromString, move contextAsString() from SpanContext to TextMapCodec, but keep it public so that SpanContext.toString() can call it.
Signed-off-by: Isaac Hier <ihier@uber.com>
assertEquals(expectedContext.getFlags(), actualContext.getFlags()); | ||
String operation = "test-operation"; | ||
JaegerSpan span = tracer.buildSpan(operation).start(); | ||
String expectedString = span.context().toString() + " - " + operation; |
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.
prod == prod. Please test for exact string.
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.
You mean I should use a string literal instead of expectedString
? Not sure what the suggestion is.
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, expectedString = "some literal value"
. Otherwise you are just comparing outputs of two prod functions. If we change the representation used by the codec, technically this test should fail since span.toString() would change.
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.
Right. Will do.
Signed-off-by: Isaac Hier <ihier@uber.com>
Signed-off-by: Isaac Hier <ihier@uber.com>
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.
🎉
Which problem is this PR solving?
Short description of the changes