Skip to content

Conversation

CagriYonca
Copy link
Contributor

Fixed trace correlation issues, aligned with other tracers through the tracer-test-suite.

@CagriYonca CagriYonca self-assigned this Aug 23, 2025
@CagriYonca CagriYonca added the FUP Fair Usage Policy label Aug 23, 2025
@CagriYonca CagriYonca requested a review from a team as a code owner August 23, 2025 14:24
@CagriYonca CagriYonca added the fix label Aug 23, 2025
@CagriYonca CagriYonca closed this Aug 23, 2025
@CagriYonca CagriYonca force-pushed the fix/kafka-fup-final branch from a72d810 to ea9c383 Compare August 23, 2025 14:38
@CagriYonca CagriYonca reopened this Aug 23, 2025
@CagriYonca CagriYonca force-pushed the fix/kafka-fup-final branch from 3a5c83f to 4dd204f Compare August 25, 2025 08:29
@CagriYonca
Copy link
Contributor Author

CagriYonca commented Aug 25, 2025

A couple of words behind the need for the changes.

Let's say we have two distributed environments: env A as a producer and env B as a consumer, and say we have a flask endpoint named send_message(), which receives the call and sends a message to a kafka topic, after sending the message we also make an http call to let's say ibm-producer-api. the consumer checks the topic every 10 seconds, reads the message if any, then makes another http call to ibm-consumer-api.

So the pseudo code is here, trace IDs are given as examples:

env A - producer

  • send_message() endpoint receives a call, WSGI Span is created, trace ID: 100
    • message is sent to kafka topic, kafka-produce span is created, trace ID: 100
    • http call made to ibm.com, urllib3 span is created, trace ID: 100

env B - consumer

  • consumer checks the topic every 10 seconds for any new messages, if any:
    • message is consumed from the kafka topic, kafka-consume span is created, trace ID: 100
    • since there is no active span after the message has been consumed, kafka-consume span is ended, and since the span context was not saved, we lose the trace ID, so the new urllib3 span will have the trace ID: 101

What we want is whether there is a parent span or not, to keep the incoming trace ID alive.

So after this PR, what will happen in the example above is as follows:

env B - consumer

  • consumer checks the topic every 10 seconds for any new messages, if any:
    • message is consumed from the kafka topic, kafka-consume span is created, trace ID: 100
      • kafka-consume span is still alive until we call kafka_consumer.close() or manually close the span using close_consumer_span(). now since the span context information is still there, urllib3 span will also have the trace ID: 100

@CagriYonca CagriYonca force-pushed the fix/kafka-fup-final branch from 4dd204f to f2a54ec Compare August 28, 2025 11:22
@CagriYonca CagriYonca force-pushed the fix/kafka-fup-final branch from f2a54ec to 8ea4071 Compare August 28, 2025 11:23
@CagriYonca CagriYonca requested a review from pvital August 28, 2025 11:28
Copy link
Member

@pvital pvital left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks good to me.

@CagriYonca CagriYonca merged commit 685e2ee into main Aug 28, 2025
17 checks passed
@CagriYonca CagriYonca deleted the fix/kafka-fup-final branch August 28, 2025 12:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix FUP Fair Usage Policy
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants