fix distributed tracing header injection for Guzzle in HyperF/Swoole environments #3544
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.
Description
Problem
Distributed tracing headers were not being injected in HyperF/Swoole environments, breaking trace continuity to downstream services.
Root Cause
CoroutineHandlerinstead of curl when running in Swoole coroutinesCoroutineHandlerreads headers from the PSR-7 request object, not curl optionstrace_method), which run AFTER the request is sent—too late to inject headersOld flow:
Solution
Use
install_hookinstead oftrace_methodto add a pre-hook that injects distributed tracing headers into the PSR-7 request object BEFORE the handler executes.New flow:
Important: The pre-hook must always call
overrideArguments(), even when no headers are injected. Perext/hook/uhook.c:Changes
transfer()instrumentation fromtrace_methodtoinstall_hookoverrideArguments()is always called (required for JIT compatibility)Testing
Verified by customer in production HyperF/Swoole environment: https://datadoghq.atlassian.net/browse/APMS-17909
Reviewer checklist