Skip to content

Conversation

@brettmc
Copy link
Contributor

@brettmc brettmc commented Jun 17, 2025

In certain circumstances (eg Curl handler and middlewares configured such that no additional promise chaining occurs), our post transfer hook can receive an already-resolved Promise. Since it's already resolved, our extra callbacks won't be applied in a timely fashion (they're instead added to a queue and will be processed as part of a shutdown handler, if not triggered by something earlier).
The upshot of this is a lot of memory being held on to for each request, and it seems that the default config when we use guzzle as our SDK exporter will trigger this. The spans for export are non-recording, so nothing user-visible happens, but the non-recording spans and promise callbacks are held in memory, seemingly forever or until shutdown.
The fix for this is to check is the promise is already resolved, and if so force our extra promise to resolve.

Fixes: open-telemetry/opentelemetry-php#1623

In certain circumstances (eg Curl handler and middlewares configured such that no additional promise chaining
occurs, our post transfer hook can receive an already-resolved Promise. Since it's already resolved, our
extra callbacks won't be applied in a timely fashion (they're instead added to a queue and will be processed
as part of a shutdown handler, if not triggered by something earlier).
The upshot of this is a lot of memory being held on to for each request, and it seems that the default config
when we use guzzle as our SDK exporter will trigger this. The spans for export are non-recording, so nothing
user-visible happens, but the non-recording spans and promise callbacks are held in memory, seemingly forever
or until shutdown.
The fix for this is to check is the promise is already resolved, and if so force our extra promise to resolve.
@brettmc brettmc requested a review from a team as a code owner June 17, 2025 06:08
@codecov
Copy link

codecov bot commented Jun 17, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.82%. Comparing base (1d5099d) to head (28adc0d).
Report is 2 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##               main     #393   +/-   ##
=========================================
  Coverage     82.82%   82.82%           
- Complexity     1948     1949    +1     
=========================================
  Files           142      142           
  Lines          8142     8142           
=========================================
  Hits           6744     6744           
  Misses         1398     1398           
Flag Coverage Δ
Aws 92.59% <ø> (ø)
Context/Swoole 0.00% <ø> (ø)
Instrumentation/AwsSdk 81.13% <ø> (ø)
Instrumentation/CakePHP 20.40% <ø> (ø)
Instrumentation/CodeIgniter 73.55% <ø> (ø)
Instrumentation/Curl 90.42% <ø> (ø)
Instrumentation/Doctrine 92.72% <ø> (ø)
Instrumentation/ExtAmqp 88.48% <ø> (ø)
Instrumentation/ExtRdKafka 86.11% <ø> (ø)
Instrumentation/Guzzle 75.58% <100.00%> (ø)
Instrumentation/HttpAsyncClient 78.04% <ø> (ø)
Instrumentation/IO 70.68% <ø> (ø)
Instrumentation/Laravel 63.91% <ø> (ø)
Instrumentation/MongoDB 74.28% <ø> (ø)
Instrumentation/MySqli 95.81% <ø> (ø)
Instrumentation/OpenAIPHP 87.21% <ø> (ø)
Instrumentation/PDO 94.21% <ø> (ø)
Instrumentation/Psr14 76.47% <ø> (ø)
Instrumentation/Psr15 89.15% <ø> (ø)
Instrumentation/Psr16 97.50% <ø> (ø)
Instrumentation/Psr18 77.46% <ø> (ø)
Instrumentation/Psr3 67.01% <ø> (ø)
Instrumentation/Psr6 97.61% <ø> (ø)
Instrumentation/ReactPHP 99.45% <ø> (ø)
Instrumentation/Slim 86.11% <ø> (ø)
Instrumentation/Symfony 84.74% <ø> (ø)
Instrumentation/Yii 77.50% <ø> (ø)
Logs/Monolog 100.00% <ø> (ø)
Propagation/Instana 98.11% <ø> (ø)
Propagation/ServerTiming 100.00% <ø> (ø)
Propagation/TraceResponse 100.00% <ø> (ø)
ResourceDetectors/Azure 91.66% <ø> (ø)
ResourceDetectors/Container 93.02% <ø> (ø)
ResourceDetectors/DigitalOcean 100.00% <ø> (ø)
Sampler/RuleBased 33.51% <ø> (ø)
Shims/OpenTracing 92.45% <ø> (ø)
Symfony 87.81% <ø> (ø)
Utils/Test 87.53% <ø> (ø)

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 80.24% <100.00%> (ø)

Continue to review full report in Codecov by Sentry.

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

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

@brettmc brettmc merged commit 7d534a0 into open-telemetry:main Jun 17, 2025
148 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.

Memory leak if guzzle is used for OTLP over http/protobuf and auto-guzzle-instrumentation is installed

3 participants