open-telemetry / open-telemetry/opentelemetry-python

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

Open
#4,748 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
2.6k
Forks
1k
Avg merge
4d 15h
Merged PRs (30d)
19

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the auto_instrumentation.initialize() entry point shown in the report and trace how it creates or configures the tracer provider during the Gunicorn post_fork hook. Reproduce the example with the PyroscopeSpanProcessor, then verify that spans from auto-instrumented components receive the processor as well as the manually created probe span.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
observability-sre
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.