Created
July 3, 2020 17:08
-
-
Save Akaame/ed20c390ac1135ffb2ac4e886d04a99f to your computer and use it in GitHub Desktop.
Sleuth baggage remote-fields error: No extra values are propagated
This file contains hidden or 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
spring: | |
application: | |
name: customer-service | |
sleuth: | |
baggage: | |
remote-fields: principal | |
log: | |
slf4j: | |
whitelisted-mdc-keys: | |
- principal |
This file contains hidden or 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
public Customer create(@RequestBody @Valid CreateCustomerRequest request, @RequestHeader HttpHeaders headers) { | |
// headers has x-b3-traceid , x-b3-spanid , x-b3-parentspanid and x-b3-sampled | |
Span currentSpan = tracer.currentSpan(); | |
List<BaggageField> baggages = ExtraBaggageContext.getAllFields(currentSpan.context()); // empty | |
Map<String, String> keys = BaggageField.getAllValues(currentSpan.context()); // empty | |
CurrentTraceContext ctc = Tracing.current().currentTraceContext(); | |
String value = BaggageField.getByName(currentSpan.context(), "principal").getValue(); // NPE :) | |
// ... | |
} |
This file contains hidden or 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
spring: | |
application: | |
name: gateway | |
sleuth: | |
baggage: | |
remote-fields: principal | |
log: | |
slf4j: | |
whitelisted-mdc-keys: | |
- principal |
This file contains hidden or 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
Span currentSpan = tracer.currentSpan(); | |
String baggageKey = "principal"; | |
String baggageValue = jwtVerifier.getSubjectId(token); // any value is okay | |
BaggageField baggageField = BaggageField.create(baggageKey); | |
baggageField.updateValue(currentSpan.context(), baggageValue); | |
try(Tracer.SpanInScope ws = tracer.withSpanInScope(currentSpan)) | |
{ | |
// currentSpan.tag(baggageKey, baggageValue); // Tried both | |
Tags.BAGGAGE_FIELD.tag(baggageField, currentSpan); | |
} | |
finally { | |
currentSpan.finish(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment