1

I have three microservices, communicating via Kafka. I am using Brave's @Tracer. The trace id is generated consistently however the parentId is different in microservices 2 and 3. What can we generate consistent parentId all over the microservices?

Thanks.

JustLift
  • 153
  • 1
  • 7
  • 17

1 Answers1

1

What version of Sleuth are you using? If it's 3.x, please use Sleuth's Tracer instead of Brave's.

Since Spans are representing operations, the spanId will be different for every Span, the parentId is really mean the Id of the previous (parent) Span so it is completely normal if the parentId is not the same for two different Spans (if they don't share the same parent).

Please see the docs: https://docs.spring.io/spring-cloud-sleuth/docs/current/reference/htmlsingle/#getting-started-terminology

enter image description here

The parentIds of the Spans here are the following:

  • Span A: null
  • Span B: A
  • Span C: B
  • Span D: C
  • Span E: D
  • Span F: C
  • Span G: F
Jonatan Ivanov
  • 4,895
  • 2
  • 15
  • 30
  • I am using spring-cloud-starter-sleuth : 3.0.3. I've changed to Sleuth's Tracer from Brave's Tracer however the parentID are still different. My scenario: Microservice (MS)1 is producer sends the message to topic1. MS2 picks up the message and sends to topic2. MS3 picks up the message. Here, MS2's parentID should be MS1 spanID and MS3's parentID should be MS2's spanID. TraceID are same. spanID and parentID are all different therefore I cannot track the message in sequence. – JustLift Sep 27 '21 at 17:52
  • If you have intermediate spans (e.g.: Sleuth automatically creates Spans for Kafka) and you are creating your own spans, this can be the case. What do you see in Zipkin does that view make sense? (Btw, not every use-case is supported by Sleuth, e.g.: using an async consumer through a blocking queue is not supported). – Jonatan Ivanov Sep 27 '21 at 18:07
  • I have not integrated Zipkin. I've simple introduced sleuth jar in all microservices, which started to log out appname, traceID, spanID. Then in consumer microservices (MS2 and MS3), I am now using Sleuth's Tracer, @Autowired. To capture traceId, spanId and parentId, I am using tracer.currentSpan().context().traceId(), tracer.currentSpan().context().spanId() and tracer.currentSpan().context().parentId() respectively. TraceID is unique all across microservices. I wonder if I need extra configurations for parentID to correlated between microservices too. Thanks. – JustLift Sep 27 '21 at 18:28
  • `parentId` is correlated but if you don't emit log events during a span, that spanID (+ its `parentId`) will not be logged. E.g.: spanA -> spanB -> spanC, if you don't emit log events during spanB, you will see the behavior that you experience. I suggest to check this with Zipkin locally: https://github.com/jonatan-ivanov/local-services/blob/main/zipkin/docker-compose.yml – Jonatan Ivanov Sep 28 '21 at 19:12
  • I will give a go. Thanks. – JustLift Sep 29 '21 at 20:03
  • I'm still getting this issue of parentId is not being matched. Sleuth automatically generates traceid spanId, parentId on each consumers. When you say "emit log events", do I have to configure any extra code when consuming the message in consumer? – JustLift Oct 04 '21 at 13:35