File tree Expand file tree Collapse file tree
core/src/main/java/com/expedia/www/haystack/client Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2222/**
2323 * Generates UUIDs as ids for Traces and Spans.
2424 * <p/>
25- * Given that the span only needs to be unique within a trace, the UUID for spans will only contain the least
26- * significant bits and will be left padded with zeroes.
27- * <p/>
2825 * Consider using the TimeBasedUUIDGenerator which is more performant.
29- * <p/>
26+ *
3027 * @see com.expedia.www.haystack.client.idgenerators.TimeBasedUUIDGenerator
3128 */
3229public class RandomUUIDGenerator implements IdGenerator {
@@ -35,9 +32,4 @@ public class RandomUUIDGenerator implements IdGenerator {
3532 public UUID generate () {
3633 return UUID .randomUUID ();
3734 }
38-
39- @ Override
40- public UUID generateSpanId () {
41- return new UUID (0 , UUID .randomUUID ().getLeastSignificantBits ());
42- }
4335}
Original file line number Diff line number Diff line change 1616 */
1717package com .expedia .www .haystack .client .idgenerators ;
1818
19-
2019import java .util .UUID ;
2120
2221import static com .fasterxml .uuid .Generators .timeBasedGenerator ;
2322
2423/**
2524 * Generates UUIDs as ids for Traces and Spans.
26- * <p/>
27- * Given that the span only needs to be unique within a trace, the UUID for spans will only contain the least
28- * significant bits and will be left padded with zeroes.
2925 */
3026public class TimeBasedUUIDGenerator implements IdGenerator {
3127
3228 @ Override
3329 public UUID generate () {
3430 return timeBasedGenerator ().generate ();
3531 }
36-
37- @ Override
38- public UUID generateSpanId () {
39- return new UUID (0 , timeBasedGenerator ().generate ().getLeastSignificantBits ());
40- }
4132}
Original file line number Diff line number Diff line change @@ -40,4 +40,19 @@ public interface Codex<R,T> {
4040 */
4141 T decode (R value );
4242
43+ default T decodeTraceId (R value ) {
44+ return decode (value );
45+ }
46+
47+ default T decodeSpanId (R value ) {
48+ return decode (value );
49+ }
50+
51+ default T decodeBaggage (R value ) {
52+ return decode (value );
53+ }
54+
55+ default T decodeKey (R value ) {
56+ return decode (value );
57+ }
4358}
Original file line number Diff line number Diff line change @@ -78,18 +78,18 @@ public SpanContext extract(TextMap carrier) {
7878 final Map <String , String > baggage = new HashMap <>();
7979
8080 for (Map .Entry <String , String > entry : carrier ) {
81- final String decodedKey = keyCodex .decode (entry .getKey ());
81+ final String decodedKey = keyCodex .decodeKey (entry .getKey ());
8282 final String decodedKeyLowerCase = decodedKey .toLowerCase ();
8383
8484 if (decodedKeyLowerCase .startsWith (convention .baggagePrefix ().toLowerCase (Locale .ROOT ))) {
8585 baggage .put (decodedKey .substring (convention .baggagePrefix ().length ()),
86- valueCodex .decode (entry .getValue ()));
86+ valueCodex .decodeBaggage (entry .getValue ()));
8787 } else if (containsIgnoreCase (convention .traceIdKeyAliases (), decodedKeyLowerCase )) {
88- traceId = valueCodex .decode (entry .getValue ());
88+ traceId = valueCodex .decodeTraceId (entry .getValue ());
8989 } else if (containsIgnoreCase (convention .parentIdKeyAliases (), decodedKeyLowerCase )) {
90- parentId = valueCodex .decode (entry .getValue ());
90+ parentId = valueCodex .decodeSpanId (entry .getValue ());
9191 } else if (containsIgnoreCase (convention .spanIdKeyAliases (), decodedKeyLowerCase )) {
92- spanId = valueCodex .decode (entry .getValue ());
92+ spanId = valueCodex .decodeSpanId (entry .getValue ());
9393 }
9494 }
9595
You can’t perform that action at this time.
0 commit comments