Skip to content

Bug Report: Parent-Child Span Context Propagation Race Condition #4756

@bebbo203

Description

@bebbo203

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions