Skip to content

Conversation

@gregoiredx
Copy link

@gregoiredx gregoiredx commented Dec 17, 2025

Description

ConcurrentMultiSpanProcessor is not "fork safe". This MR tries to solve this problem.

Forking a threaded process is not a good idea in the first place, citing the Python doc, see https://docs.python.org/3/library/multiprocessing.html#contexts-and-start-methods

Note that safely forking a multithreaded process is problematic.

Also, the OTel Python SDK suggest to only initialize the SDK post fork, see https://opentelemetry-python.readthedocs.io/en/latest/examples/fork-process-model/README.html

Nevertheless, on an existing code base, it's not always easy to avoid all forks. So it looks like a good idea to try and make the SDK as fork safe as possible.

Note: BatchProcessor is already relying on register_at_fork used here, see

os.register_at_fork(after_in_child=lambda: weak_reinit()()) # pyright: ignore[reportOptionalCall] pylint: disable=unnecessary-lambda

Fixes #2349

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

See unit test and discussions below.

An equivalent patch is currently running in our stack.

Does This PR Require a Contrib Repo Change?

?

Checklist:

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Dec 17, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: xrmx / name: Riccardo Magliocchetti (7771136)

@gregoiredx gregoiredx force-pushed the fork-safe-concurrent-multi-span-processor branch from 3abcc2e to f98d672 Compare December 17, 2025 13:48
@gregoiredx gregoiredx marked this pull request as ready for review December 22, 2025 08:50
@gregoiredx gregoiredx requested a review from a team as a code owner December 22, 2025 08:50
@xrmx xrmx moved this to Ready for review in @xrmx's Python PR digest Dec 29, 2025
@gregoiredx gregoiredx force-pushed the fork-safe-concurrent-multi-span-processor branch 4 times, most recently from 8e7c298 to 808fe91 Compare January 2, 2026 16:38
@gregoiredx gregoiredx changed the title Make ConcurrentMultiSpanProcessor fork safe Fork safe ConcurrentMultiSpanProcessor Jan 2, 2026
@gregoiredx gregoiredx force-pushed the fork-safe-concurrent-multi-span-processor branch from 808fe91 to 071b2de Compare January 9, 2026 12:33
@gregoiredx gregoiredx force-pushed the fork-safe-concurrent-multi-span-processor branch from 071b2de to ac36ce2 Compare January 9, 2026 12:41
@gregoiredx
Copy link
Author

gregoiredx commented Jan 9, 2026

@DylanRussell thanks a lot for the review.
The first pass of the CI wasn't successful.
I applied two fixes:

There's another test which failed but it doesn't look like it's related to my change, see https://github.com/open-telemetry/opentelemetry-python/actions/runs/20662185256/job/59826483790#step:6:39

Can you relaunch the CI please?

@gregoiredx
Copy link
Author

There's still a CI step failing but I have no idea how I can fix this. It looks like a bug/flakiness in the CI workflow
https://github.com/open-telemetry/opentelemetry-python/actions/runs/20852250476/job/59913535963#step:6:22

Updating https://github.com/open-telemetry/opentelemetry-python.git (2b1e6540d049eb4abcf09d445cec06ae389aa1e4)
  × Failed to download and build `opentelemetry-api @
  │ git+[https://github.com/open-telemetry/opentelemetry-python.git@2b1e6540d049eb4abcf09d445cec06ae389aa1e4#egg=opentelemetry-api&subdirectory=opentelemetry-api`](https://github.com/open-telemetry/opentelemetry-python.git@2b1e6540d049eb4abcf09d445cec06ae389aa1e4#egg=opentelemetry-api&subdirectory=opentelemetry-api%60)
  ├─▶ Git operation failed
  ├─▶ failed to find branch, tag, or commit
  │   `2b1e6540d049eb4abcf09d445cec06ae389aa1e4`

@DylanRussell
Copy link
Contributor

Yeah don't worry about that it's a very common flake that randomly occurs on tests, some sort of race condition I think

@xrmx xrmx moved this from Ready for review to Approved PRs in @xrmx's Python PR digest Jan 12, 2026
@gregoiredx
Copy link
Author

can we relaunch the failing tests? Or merge? the failures look like flaky tests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Approved PRs

Development

Successfully merging this pull request may close these issues.

ConcurrentMultiSpanProcessor threadpool should be reset after process forked

3 participants