Skip to content

Instantly share code, notes, and snippets.

@Akaame
Created July 3, 2020 17:08
Show Gist options
  • Save Akaame/ed20c390ac1135ffb2ac4e886d04a99f to your computer and use it in GitHub Desktop.
Save Akaame/ed20c390ac1135ffb2ac4e886d04a99f to your computer and use it in GitHub Desktop.
Sleuth baggage remote-fields error: No extra values are propagated
spring:
application:
name: customer-service
sleuth:
baggage:
remote-fields: principal
log:
slf4j:
whitelisted-mdc-keys:
- principal
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 :)
// ...
}
spring:
application:
name: gateway
sleuth:
baggage:
remote-fields: principal
log:
slf4j:
whitelisted-mdc-keys:
- principal
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