我有一个通过AWS服务发送消息的应用程序,并且我正在通过以下方式手动将标题添加到消息中
final Map<String, Object> braveHeaders = new HashMap<>();
braveHeaders.put(Span.TRACE_ID_NAME, span.getTraceId());
braveHeaders.put(Span.PARENT_ID_NAME, span.getParents().stream().findFirst().orElse(0L));
braveHeaders.put(Span.SAMPLED_NAME, span.isExportable());
braveHeaders.put(Span.SPAN_FLAGS, span.getBaggage());
braveHeaders.put(Span.SPAN_NAME_NAME, span.getName());
braveHeaders.put(Span.SPAN_EXPORT_NAME, span.getName());
braveHeaders.put(Span.SPAN_ID_NAME, span.getSpanId());
在消费者应用程序上,我试图读取属性并建立新的Span,
JsonNode braveTree = objectMapper.readTree(brave.asText());
// configure a function that extracts the trace context from a request
TraceContext.Extractor<JsonNode> extractor = tracing.propagation().extractor(
(carrier, key) -> carrier.get(key).asText());
// when a server receives a request, it joins or starts a new trace
Span span = tracing.tracer().nextSpan(extractor.extract(braveTree));
正在从标头中成功提取标头,但是在解析parseSpanId
时,标头将由于无效长度而失败,从而导致创建新的TraceContext失败。
/** Parses the span id from the input string. Returns true if the ID is valid. */
final <C, K> boolean parseSpanId(Propagation.Getter<C, K> getter, C carrier, K key) {
String spanIdString = getter.get(carrier, key);
if (isNull(key, spanIdString)) return false;
int length = spanIdString.length();
if (invalidIdLength(key, length, 16)) return false;
spanId = lenientLowerHexToUnsignedLong(spanIdString, 0, length);
if (spanId == 0) {
maybeLogNotLowerHex(key, spanIdString);
return false;
}
return true;
}
从Sleuth 1.3> 2.0接收标头时,是否有任何方法可以继续跨度?还是所有应用程序都必须使用相同版本?
答案 0 :(得分:1)
这实际上是标题发送方式的问题。标头未调用Span.idToHex(...)
,因此检查失败。