SpanContext hides the TraceId/SpanId implementations#1594
SpanContext hides the TraceId/SpanId implementations#1594jkwatson merged 15 commits intoopen-telemetry:masterfrom
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.
|
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! |
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.
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.
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.
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! |
|
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.
return CharSequence instead?
There was a problem hiding this comment.
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.
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.
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.
Hex? If you used hex in SpanContext method names.
There was a problem hiding this comment.
yes! should fix this. good catch.
| return new String(result); | ||
| } | ||
|
|
||
| private static char[] getBuffer() { |
There was a problem hiding this comment.
s/getBuffer/getTemporaryBuffer?
| */ | ||
| 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.
Same, use Hex if you decided to use that in the SC
| 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.
name the params traceIdHex, spanIdHex
� 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 <anuraaga@gmail.com>
…tensions/trace/propagation/B3PropagatorInjectorSingleHeader.java Co-authored-by: Anuraag Agrawal <anuraaga@gmail.com>
Co-authored-by: Anuraag Agrawal <anuraaga@gmail.com>
Co-authored-by: Anuraag Agrawal <anuraaga@gmail.com>
|
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
CharSequences 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