-
Notifications
You must be signed in to change notification settings - Fork 858
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
SpanContext hides the TraceId/SpanId implementations #1594
Conversation
I apologize for the size of this PR. Most of it is mechanical changes in types, so hopefully review will go quickly. |
Codecov Report
@@ Coverage Diff @@
## master #1594 +/- ##
============================================
- Coverage 91.16% 91.12% -0.04%
- Complexity 991 995 +4
============================================
Files 117 117
Lines 3668 3664 -4
Branches 340 345 +5
============================================
- Hits 3344 3339 -5
- Misses 218 219 +1
Partials 106 106
Continue to review full report at Codecov.
|
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.
Thanks!
api/src/main/java/io/opentelemetry/trace/BigendianEncoding.java
Outdated
Show resolved
Hide resolved
api/src/main/java/io/opentelemetry/trace/BigendianEncoding.java
Outdated
Show resolved
Hide resolved
api/src/main/java/io/opentelemetry/trace/BigendianEncoding.java
Outdated
Show resolved
Hide resolved
...ns/trace_propagators/src/main/java/io/opentelemetry/extensions/trace/propagation/Common.java
Show resolved
Hide resolved
...ain/java/io/opentelemetry/extensions/trace/propagation/B3PropagatorInjectorSingleHeader.java
Outdated
Show resolved
Hide resolved
api/src/main/java/io/opentelemetry/trace/propagation/HttpTraceContext.java
Outdated
Show resolved
Hide resolved
@anuraaga I think I got all of your comments addressed. Thanks so much for taking the time to give it a thorough review! |
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.
Just nits, thanks!
api/src/main/java/io/opentelemetry/trace/BigendianEncoding.java
Outdated
Show resolved
Hide resolved
api/src/main/java/io/opentelemetry/trace/BigendianEncoding.java
Outdated
Show resolved
Hide resolved
for (int i = 0; i < value.length(); i++) { | ||
char b = value.charAt(i); | ||
// 48..57 && 97..102 are valid | ||
if ((b < 48 || b > 57) && (b < 97 || b > 102)) { |
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'm pretty sure they're the same, and maybe it's just me but I find writing the same code as the comment would be more readable
if ((b < 48 || b > 57) && (b < 97 || b > 102)) { | |
if (!(b >= 48 && b <= 57) || !(b >= 97 && b <= 102)) { |
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.
heh. I agree with you. However, what you pasted isn't correct (IDEA says it's always true!). I'll figure out how to make it what you intended. :)
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.
check out the update. I think it's now much easier to understand.
.../java/io/opentelemetry/extensions/trace/propagation/B3PropagatorInjectorMultipleHeaders.java
Outdated
Show resolved
Hide resolved
...ropagators/src/main/java/io/opentelemetry/extensions/trace/propagation/JaegerPropagator.java
Show resolved
Hide resolved
...pagators/src/main/java/io/opentelemetry/extensions/trace/propagation/OtTracerPropagator.java
Outdated
Show resolved
Hide resolved
...pagators/src/main/java/io/opentelemetry/extensions/trace/propagation/OtTracerPropagator.java
Outdated
Show resolved
Hide resolved
opentracing_shim/src/test/java/io/opentelemetry/opentracingshim/testbed/TestUtils.java
Outdated
Show resolved
Hide resolved
ok, all nits have been de-nitted! |
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.
LGTM thanks
I'm going to hold off a few days to merge this, both to delay to after the 0.8.0 release, and to give others (@carlosalberto and @bogdandrutu) to chime in with any issue they might have, as this is a significant API change. |
abstract String getTraceId(); | ||
|
||
abstract String getSpanId(); |
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.
return CharSequence
instead?
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 we discussed this, and decided to keep it as String for now. We can always open it up to CharSequence later, since it's a broader interface, I 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.
You can change return types that easily. If clients expect String
they will break on CharSequence
. You can widen input, not output
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.
true, but this isn't a public method!
*/ | ||
public static SpanId getInvalid() { | ||
return INVALID; | ||
public static int getBase16Length() { |
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.
Hex? If you used hex in SpanContext method names.
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! should fix this. good catch.
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
return new String(result); | ||
} | ||
|
||
private static char[] getBuffer() { |
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/getBuffer/getTemporaryBuffer?
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
*/ | ||
public void copyLowerBase16To(char[] dest, int destOffset) { | ||
BigendianEncoding.longToBase16String(id, dest, destOffset); | ||
public static byte[] bytesFromLowerBase16(String src, int srcOffset) { |
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.
Same, use Hex if you decided to use that in the SC
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.
agreed. 👍
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
@@ -59,8 +60,13 @@ public static SpanContext getInvalid() { | |||
* @since 0.1.0 | |||
*/ | |||
public static SpanContext create( | |||
TraceId traceId, SpanId spanId, TraceFlags traceFlags, TraceState traceState) { | |||
return new AutoValue_SpanContext(traceId, spanId, traceFlags, traceState, /* remote=*/ false); | |||
String traceId, String spanId, TraceFlags traceFlags, TraceState traceState) { |
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.
name the params traceIdHex, spanIdHex
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
� This is the 1st commit message: WIP on converting to String-based SpanContext don't hand out the byte arrays publicly, but require making copies make sure to hand out fresh invalid byte arrays. Use strings for span and trace ids. Switch over to CharSequence instead of String for the ids Fix a couple of places that were casting to String Add some simple wrappers for the generated longs to save converting until the last moment to the character-based representation. introduce a reusable threadlocal char buffer for generating random ids. update for changes from upstream Change the SpanContext to store the ids as Strings internally Change the id access methods on SpanContext to be clearly labeled as the base16 representations Add a new create method that allows specifying offsets for traceId and spanId CharSequences Provide an option for creating a SpanContext from longs or Strings, optionally. fix a typo update from upstream � The commit message #2 will be skipped: � don't hand out the byte arrays publicly, but require making copies
Co-authored-by: Anuraag Agrawal <[email protected]>
…tensions/trace/propagation/B3PropagatorInjectorSingleHeader.java Co-authored-by: Anuraag Agrawal <[email protected]>
Co-authored-by: Anuraag Agrawal <[email protected]>
Co-authored-by: Anuraag Agrawal <[email protected]>
Amazing job @jkwatson sorry for the late review! |
Awesome! |
Having abstract methods with default visibility makes the class not able to be subclassed by other packages. Changing to protected to maintain the intended restrictions from open-telemetry#1594, but allowing it to be subclassed.
This removes the usage of wrapper classes for the ids.
Changes the SpanContext creation methods to accept
CharSequence
s and an offset for the ids.Changes the IdGenerator interface to generate String ids.
Relevant issue: #1314
Extensive discussion about this took place in this draft PR: #1374