Repository navigation
[Server] Allow context propagation into handler fibers - #670
Merged
chr-hertel merged 3 commits intoNov 8, 2026
Merged
Conversation
bbdu3
requested review from
CodeWithKyrian,
Nyholm,
chr-hertel and
soyuka
as code owners
November 5, 2026 09:56
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are recorded for the optional handler-fiber context-propagation hook.
No open issues 🎉
What changed in this PR
Adds an optional context-propagation hook for SDK-managed handler fibers, addressing #583 without introducing an OpenTelemetry dependency or changing fiber scheduling.
Changes:
- Introduces
FiberFactoryInterfaceandBuilder::setFiberFactory()for both protocol eras, includingbuildStateless(). - Documents explicit OpenTelemetry context propagation while preserving default behavior.
- Adds regression coverage for context isolation, suspension/resumption, errors, and cleanup.
| File | Description |
|---|---|
tests/Unit/Server/FiberFactoryTest.php |
Tests context propagation and cleanup across HTTP and stdio. |
tests/Unit/Fixtures/ContextFiberFactory.php |
Provides a context-tracking factory for tests. |
src/Server/Stateless/StatelessProtocol.php |
Uses the optional factory for modern-era handler fibers. |
src/Server/Protocol.php |
Uses the optional factory for handshake-era handler fibers. |
src/Server/FiberFactoryInterface.php |
Defines the factory contract and callback-preservation requirements. |
src/Server/Builder.php |
Adds factory configuration and passes it to both protocols. |
docs/run/server-builder.md |
Explains factory usage with an OpenTelemetry example. |
CHANGELOG.md |
Records the new server integration hook. |
Review effort: Balanced
Signed-off-by: bbdu3 <ergouyang854@gamil.com>
chr-hertel
force-pushed
the
codex/fiber-context-factory
branch
from
November 8, 2026 13:12
536b2b1 to
7d9bc33
Compare
Member
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #583 - adds
Builder::setFiberContext()andFiberContextInterface, so an integration can carry execution context, e.g. the active OpenTelemetry context, into handler fibers in both protocol eras.wrap()runs in the context of the caller, the returned closure runs in the fiber - the SDK keeps creating the fiber itselffinallyonly ran on the next GC run