apm-agent-php icon indicating copy to clipboard operation
apm-agent-php copied to clipboard

guzzle async and curl_multi auto-instrumentation

Open brettmc opened this issue 4 years ago • 4 comments

Describe the bug Documentation says that curl extension will be auto instrumented and have distributed trace headers applied to any request. Using guzzlehttp/guzzle v7.3.0 with default curl handler, whilst making aync calls ($client->getAsync('example.com')->wait()), did not add distributed trace headers or create a span. Whilst debugging this with @michaelhyatt I found that by default, guzzle uses both curl and curl_multi - and evidently uses curl_multi for async requests: https://github.com/guzzle/guzzle/blob/master/src/Utils.php#L89

If I force a plain curl handler, then I do get distributed trace headers:

<?php
$handler = new \GuzzleHttp\Handler\CurlHandler();
$stack = \GuzzleHttp\HandlerStack::create($handler);
$client = new \GuzzleHttp\Client(['handler' => $stack]);
$response = $client->getAsync('example.com')->wait();
echo $response->getBody()->getContents();

Secondly, the documentation also says that guzzle itself will be instrumented, but I see no signs of this happening.

OS: centos:7 plus debian:buster in docker PHP: 7.4.20 apm-agent-php: 1.1 (installed from rpm + deb)

To Reproduce Steps to reproduce the behavior:

  1. Use this script:
<?php
$client = new \GuzzleHttp\Client();
$response = $client->getAsync('example.com')->wait();
echo $response->getBody()->getContents();
  1. Then load the page/execute the script
  2. Then check traces in kibana
  3. You should see a transaction with a single span. However, if you use CurlHandler() only, you will see a child span for the http request.

Expected behavior Expect to see a transaction with 3 spans: parent, guzzle, curl.

brettmc avatar Jun 10 '21 04:06 brettmc

Also worth noting: forcing the use of CurlHandler breaks guzzle's async feature, all requests happen sequentially.

brettmc avatar Jun 11 '21 00:06 brettmc

This would be a great improvement, as curl_multi is also the default on the Symfony PSR18 client.

mfadul24 avatar Oct 06 '22 11:10 mfadul24

Big +1 from me and my team.

jlindblom-godaddy avatar May 08 '24 16:05 jlindblom-godaddy