Skip to content

Can't add span processor in post_fork when using initialize() #4748

@beaugunderson

Description

@beaugunderson

Describe your environment

OS: Ubuntu
Python version: Python 3.13.37
API version: "opentelemetry-distro[otlp]>=0.57b0"

What happened?

this is in my gunicorn post_fork:

def post_fork(server: Arbiter, worker: CanvasUvicornWorker) -> None:
    from opentelemetry.instrumentation.auto_instrumentation import initialize
    initialize()

    PYROSCOPE_URL = os.getenv("PYROSCOPE_URL")
    PYROSCOPE_USER = os.getenv("PYROSCOPE_USER")
    PYROSCOPE_PASSWORD = os.getenv("PYROSCOPE_PASSWORD")

    if PYROSCOPE_URL and PYROSCOPE_USER and PYROSCOPE_PASSWORD:
        pyroscope.configure(
            application_name="home-app",
            server_address=PYROSCOPE_URL,
            basic_auth_username=PYROSCOPE_USER,
            basic_auth_password=PYROSCOPE_PASSWORD,
            sample_rate=100,  # default is 100
            detect_subprocesses=True,
            oncpu=True,  # report cpu time only; default is True
            gil_only=True,
            enable_logging=True,
            tags={
                "customer": os.getenv("CUSTOMER_IDENTIFIER"),
            },
        )

        tp = trace.get_tracer_provider()
        tp.add_span_processor(PyroscopeSpanProcessor())

        tr = tp.get_tracer("probe")

        with tr.start_as_current_span("pyro-probe"):
            pass

My pyro-probe span does have a pyroscope.span.id, but none of the spans generated from the auto-instrumentation do.

What is the correct way to add a span processor to the tracer provider that the initialize() method generates?

Steps to Reproduce

See above code.

Expected Result

All spans contain a pyroscope.span.id (this is specific to this span processor, but the general expected result is that the span processor runs for all spans, not just ones created in this block).

Actual Result

Any span generated from auto-instrumentation does not have the span processor added afterwards run.

Additional context

No response

Would you like to implement a fix?

None

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