-
Notifications
You must be signed in to change notification settings - Fork 745
Description
Describe your environment
OS: Window 11
Python version: Python 3.12
SDK version: 1.37.0
API version: 1.37.0
What happened?
When a child span is created within the context of a parent span using start_as_current_span, the child span should be consistently linked to its parent with a 100% success rate.
Specifically, there are problems when the child span is started immediately after (or with little to no instructions in between) the parent span
Steps to Reproduce
# Example usage in Kafka consumer
def kafka_consumer():
for msg in consumer:
with tracer.start_as_current_span("parent_span") as parent_span:
# light logic
print("hello")
# Child span created immediately - race condition occurs here
with tracer.start_as_current_span("child_span") as child_span:
dummy_fun()
Expected Result
By exporting the traces to Signoz, I expected a 100% conversion rate between "parent_span" and "child_span".
Actual Result
The conversion rate is about 50%, meaning that some child span didn't load correctly the context
Additional context
A simple workaround is to add a time.sleep(0.00001) between the creation of the two spans:
# Example usage in Kafka consumer
def kafka_consumer():
for msg in consumer:
with tracer.start_as_current_span("parent_span") as parent_span:
# light logic
print("hello")
time.sleep(0.00001)
# Child span created immediately - race condition occurs here
with tracer.start_as_current_span("child_span") as child_span:
dummy_fun()
Would you like to implement a fix?
No
Tip
React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1
or me too
, to help us triage it. Learn more here.