Skip to content

fix(guzzle): end span when Client::transfer() throws synchronously#629

Merged
bobstrecansky merged 2 commits into
open-telemetry:mainfrom
andreicodrutonofrei-sketch:fix/guzzle-transfer-sync-throw-post-hook
Jul 9, 2026
Merged

fix(guzzle): end span when Client::transfer() throws synchronously#629
bobstrecansky merged 2 commits into
open-telemetry:mainfrom
andreicodrutonofrei-sketch:fix/guzzle-transfer-sync-throw-post-hook

Conversation

@andreicodrutonofrei-sketch

Copy link
Copy Markdown
Contributor

Description

GuzzleHttp\Client::transfer() can throw synchronously before returning a
promise — e.g. when invalid request options are supplied, since applyOptions()
runs outside transfer()'s try/catch. In that case the extension invokes the
transfer post hook with a null return value.

The post hook typed the promise as non-nullable (PromiseInterface $promise), so
the runtime signature check failed: the hook was skipped, the span leaked (never
ended/detached), and an E_CORE_WARNING was emitted:

GuzzleHttp\Client::transfer(): OpenTelemetry: post hook invalid signature,
class=GuzzleHttp\Client function=transfer

This surfaces as a fatal error in error trackers such as Sentry.

Fix

  • Make the post hook's promise parameter nullable (?PromiseInterface $promise).
  • When the promise is null (synchronous throw), end the span — unless it was
    already ended via the exception branch — and return instead of dereferencing
    null.

Test

Adds a regression test that triggers a synchronous throw via a numerically-indexed
headers option and asserts the span is still ended with an error status.

Related

Same class of "post hook invalid signature / span leak on throw" issue previously
fixed for other instrumentations:

@andreicodrutonofrei-sketch
andreicodrutonofrei-sketch requested a review from a team as a code owner June 22, 2026 20:09
@welcome

welcome Bot commented Jun 22, 2026

Copy link
Copy Markdown

Thanks for opening your first pull request! If you haven't yet signed our Contributor License Agreement (CLA), then please do so that we can accept your contribution. A link should appear shortly in this PR if you have not already signed one.

@linux-foundation-easycla

linux-foundation-easycla Bot commented Jun 22, 2026

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: andreicodrutonofrei-sketch / name: Andrei-Codrut Onofrei (6f778d1)

@codecov

codecov Bot commented Jun 23, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 80.50%. Comparing base (edc589d) to head (d3e58e5).
⚠️ Report is 12 commits behind head on main.

Files with missing lines Patch % Lines
...strumentation/Guzzle/src/GuzzleInstrumentation.php 80.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##               main     #629      +/-   ##
============================================
+ Coverage     80.46%   80.50%   +0.04%     
- Complexity     1669     1671       +2     
============================================
  Files           116      116              
  Lines          6265     6269       +4     
============================================
+ Hits           5041     5047       +6     
+ Misses         1224     1222       -2     
Flag Coverage Δ
Context/Swoole 0.00% <ø> (ø)
Exporter/Instana 49.80% <ø> (ø)
Instrumentation/AwsSdk 82.14% <ø> (ø)
Instrumentation/CakePHP 20.42% <ø> (ø)
Instrumentation/CodeIgniter 79.31% <ø> (ø)
Instrumentation/Curl 86.88% <ø> (ø)
Instrumentation/Doctrine 92.82% <ø> (ø)
Instrumentation/ExtAmqp 88.80% <ø> (ø)
Instrumentation/Guzzle 79.76% <80.00%> (+3.51%) ⬆️
Instrumentation/HttpAsyncClient 78.94% <ø> (ø)
Instrumentation/HttpConfig 28.76% <ø> (ø)
Instrumentation/IO 0.00% <ø> (ø)
Instrumentation/Laravel 76.37% <ø> (ø)
Instrumentation/MongoDB 76.84% <ø> (ø)
Instrumentation/MySqli 93.39% <ø> (ø)
Instrumentation/OpenAIPHP 86.71% <ø> (ø)
Instrumentation/PostgreSql 91.36% <ø> (ø)
Instrumentation/Psr14 77.41% <ø> (ø)
Instrumentation/Psr15 89.74% <ø> (ø)
Instrumentation/Psr16 97.43% <ø> (ø)
Instrumentation/Psr18 79.41% <ø> (ø)
Instrumentation/Psr6 97.56% <ø> (ø)
Instrumentation/Session 94.28% <ø> (ø)
Instrumentation/Slim 84.21% <ø> (ø)
Propagation/CloudTrace 90.69% <ø> (ø)
Propagation/Instana 98.07% <ø> (ø)
Propagation/ServerTiming 94.73% <ø> (ø)
Propagation/TraceResponse 94.73% <ø> (ø)
ResourceDetectors/Azure 91.66% <ø> (ø)
ResourceDetectors/DigitalOcean 100.00% <ø> (ø)
Sampler/Xray 78.38% <ø> (ø)
Shims/OpenTracing 92.99% <ø> (ø)
SqlCommenter 95.58% <ø> (ø)
Utils/Test 87.79% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...strumentation/Guzzle/src/GuzzleInstrumentation.php 84.81% <80.00%> (+3.47%) ⬆️

Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update edc589d...d3e58e5. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@andreicodrutonofrei-sketch
andreicodrutonofrei-sketch force-pushed the fix/guzzle-transfer-sync-throw-post-hook branch from 6f778d1 to eee81ca Compare June 23, 2026 19:07
}

$this->assertCount(1, $this->storage);
$span = $this->storage->offsetGet(0);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests are failing, possibly around here. Are you able to run them locally to fix?

@andreicodrutonofrei-sketch andreicodrutonofrei-sketch Jun 24, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @ChrisLightfootWild, yes, I will work on fixing them as soon as possible.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you point me in the direction of what tests should I be focused on? For example the CodeIgniter ones fail for different reasons.

@bobstrecansky
bobstrecansky merged commit 685d4e4 into open-telemetry:main Jul 9, 2026
131 of 175 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants