-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a configurable id formatter (#15)
* adding string and uuid based id extractors * making string id formatter as default and bug fix
- Loading branch information
1 parent
01b65bf
commit cfc977e
Showing
7 changed files
with
104 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
.../java/com/expedia/www/spring/cloud/sleuth/haystack/reporter/idextractors/IdExtractor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.expedia.www.spring.cloud.sleuth.haystack.reporter.idextractors; | ||
|
||
import zipkin2.Span; | ||
|
||
public interface IdExtractor { | ||
Object getTraceId(Span span); | ||
|
||
Object getSpanId(Span span); | ||
|
||
Object getParentSpanId(Span span); | ||
} |
24 changes: 24 additions & 0 deletions
24
...com/expedia/www/spring/cloud/sleuth/haystack/reporter/idextractors/StringIdExtractor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.expedia.www.spring.cloud.sleuth.haystack.reporter.idextractors; | ||
|
||
import zipkin2.Span; | ||
|
||
public class StringIdExtractor implements IdExtractor { | ||
|
||
@Override | ||
public String getTraceId(Span span) { | ||
return span.traceId(); | ||
} | ||
|
||
@Override | ||
public String getSpanId(Span span) { | ||
return span.id(); | ||
} | ||
|
||
@Override | ||
public String getParentSpanId(Span span) { | ||
if (span.parentId() == null) { | ||
return ""; | ||
} | ||
return span.parentId(); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...a/com/expedia/www/spring/cloud/sleuth/haystack/reporter/idextractors/UUIDIdExtractor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.expedia.www.spring.cloud.sleuth.haystack.reporter.idextractors; | ||
|
||
import brave.internal.HexCodec; | ||
import zipkin2.Span; | ||
|
||
import java.util.UUID; | ||
|
||
public class UUIDIdExtractor implements IdExtractor { | ||
|
||
@Override | ||
public String getTraceId(Span span) { | ||
final Long lowTraceId = HexCodec.lowerHexToUnsignedLong(span.traceId()); | ||
final Long highTraceId = span.traceId().length() == 32 ? HexCodec.lowerHexToUnsignedLong(span.traceId(), 0) : 0; | ||
|
||
final UUID traceId = new UUID(highTraceId, lowTraceId); | ||
return traceId.toString(); | ||
} | ||
|
||
@Override | ||
public String getSpanId(Span span) { | ||
return new UUID(0, HexCodec.lowerHexToUnsignedLong(span.id())).toString(); | ||
} | ||
|
||
@Override | ||
public String getParentSpanId(Span span) { | ||
if (span.parentId() == null) { | ||
return ""; | ||
} | ||
return new UUID(0, HexCodec.lowerHexToUnsignedLong(span.parentId())).toString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters