-1

I have an application that is sending messages through AWS Services and I am manually adding the headers to the message via,

    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());

On the consumer application I am attempting to read the attributes and build a new 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));

The headers are being successfully extracted from the Headers but it will fail when parsing the parseSpanId due to invalid length causing the creation of the new TraceContext to fail.

  /** 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;
}

Is there any method to continue a span when receiving headers from Sleuth 1.3 > 2.0? Or must all applications be on the same version?

Darren Forsythe
  • 10,712
  • 4
  • 43
  • 54

1 Answers1

1

This was actually an issue with how the headers were being sent. The headers were not calling Span.idToHex(...) thus failing the checks.

Darren Forsythe
  • 10,712
  • 4
  • 43
  • 54