fix(guzzle): distributed tracing header injection in HyperF/Swoole environments#3544
Merged
fix(guzzle): distributed tracing header injection in HyperF/Swoole environments#3544
Conversation
Use install_hook with pre-hook to inject headers into PSR-7 request before it reaches any handler (curl or CoroutineHandler). This ensures headers are propagated in HyperF/Swoole environments where CoroutineHandler reads headers directly from the request object. Fixes distributed tracing continuity for Guzzle in coroutine contexts.
Benchmarks [ tracer ]Benchmark execution time: 2025-12-30 15:48:29 Comparing candidate commit 27f1648 in PR branch Found 1 performance improvements and 8 performance regressions! Performance is the same for 185 metrics, 0 unstable metrics. scenario:MessagePackSerializationBench/benchMessagePackSerialization
scenario:MessagePackSerializationBench/benchMessagePackSerialization-opcache
scenario:SamplingRuleMatchingBench/benchRegexMatching1
scenario:SamplingRuleMatchingBench/benchRegexMatching2
scenario:SamplingRuleMatchingBench/benchRegexMatching3
scenario:SamplingRuleMatchingBench/benchRegexMatching4
scenario:SpanBench/benchDatadogAPI
scenario:SpanBench/benchOpenTelemetryAPI
scenario:TraceSerializationBench/benchSerializeTrace
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #3544 +/- ##
==========================================
- Coverage 61.75% 61.63% -0.12%
==========================================
Files 139 139
Lines 13051 13051
Branches 1712 1712
==========================================
- Hits 8059 8044 -15
- Misses 4228 4242 +14
- Partials 764 765 +1 see 3 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
Leiyks
approved these changes
Jan 5, 2026
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.
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