File tree Expand file tree Collapse file tree
core/src/main/java/com/expedia/www/haystack/client/idgenerators Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1717package com .expedia .www .haystack .client .idgenerators ;
1818
1919public interface IdGenerator {
20- Object generateTraceId ();
2120
22- Object generateSpanId ();
21+ /**
22+ * Generates a unique id
23+ * @deprecated This method was deprecated in 0.3.1. Use {@link #generateTraceId()} and {@link #generateSpanId()} instead
24+ */
25+ @ Deprecated
26+ Object generate ();
27+
28+ /**
29+ * Generates a random unique identifier for a trace.
30+ */
31+ default Object generateTraceId () {
32+ return generate ();
33+ }
34+
35+ /**
36+ * Generates a random identifier for a span. It should be unique within a trace.
37+ */
38+ default Object generateSpanId () {
39+ return generate ();
40+ }
2341}
Original file line number Diff line number Diff line change 1616 */
1717package com .expedia .www .haystack .client .idgenerators ;
1818
19-
20- import com .expedia .www .haystack .client .idgenerators .IdGenerator ;
21-
2219import java .util .concurrent .ThreadLocalRandom ;
2320
21+ /**
22+ * Generates random and unique Longs as ids for Traces and Spans.
23+ */
2424public class LongIdGenerator implements IdGenerator {
2525
2626 @ Override
27- public Long generateTraceId () {
28- return ThreadLocalRandom .current ().nextLong (Long .MAX_VALUE );
29- }
30-
31- @ Override
32- public Long generateSpanId () {
27+ public Long generate () {
3328 return ThreadLocalRandom .current ().nextLong (Long .MAX_VALUE );
3429 }
3530}
Original file line number Diff line number Diff line change 1919
2020import java .util .UUID ;
2121
22+ /**
23+ * Generates UUIDs as ids for Traces and Spans.
24+ * <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/>
28+ * Consider using the TimeBasedUUIDGenerator which is more performant.
29+ * <p/>
30+ * @see com.expedia.www.haystack.client.idgenerators.TimeBasedUUIDGenerator
31+ */
2232public class RandomUUIDGenerator implements IdGenerator {
2333
2434 @ Override
25- public UUID generateTraceId () {
35+ public UUID generate () {
2636 return UUID .randomUUID ();
2737 }
2838
Original file line number Diff line number Diff line change 1717package com .expedia .www .haystack .client .idgenerators ;
1818
1919
20- import com .fasterxml .uuid .Generators ;
21-
2220import java .util .UUID ;
2321
22+ import static com .fasterxml .uuid .Generators .timeBasedGenerator ;
23+
24+ /**
25+ * 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.
29+ */
2430public class TimeBasedUUIDGenerator implements IdGenerator {
2531
2632 @ Override
27- public UUID generateTraceId () {
28- return Generators . timeBasedGenerator ().generate ();
33+ public UUID generate () {
34+ return timeBasedGenerator ().generate ();
2935 }
3036
3137 @ Override
32- public Object generateSpanId () {
33- return Generators . timeBasedGenerator ().generate ();
38+ public UUID generateSpanId () {
39+ return new UUID ( 0 , timeBasedGenerator ().generate (). getLeastSignificantBits () );
3440 }
3541}
You can’t perform that action at this time.
0 commit comments