apm-agent-php
apm-agent-php copied to clipboard
curl/guzzle PUT request with body is recorded as a POST
Describe the bug
A PUT request with a body (using CURLOPT_POSTFIELDS) creates a span named POST <url>. Debugging the code shows that CurlHandleTracker::processSetOpt first sets the method as PUT based on CURLOPT_PUT, but later changes it to POST based on CURLOPT_POSTFIELDS.
To Reproduce Steps to reproduce the behavior:
- Use this example script:
<?php
require_once('vendor/autoload.php');
$client = new \GuzzleHttp\Client();
$response = $client->put('https://httpbin.org/put', [
'body' => 'foo',
]);
- Then run the script with debug/trace logging, or observe the result in APM:
2021-10-04 03:07:05.251730+00:00 [DEBUG] [Backend-Comm] [backend_comm.c:57] [sendEventsToApmServer] {"span":{"name":"POST httpbin.org","type":"external","id":"e0db07d713e69b9c","trace_id":"98002e097086991f43a2e0d505867ff3","timestamp":1633316824004506,"duration":1166.457,"outcome":"success","parent_id":"964a0efa3def692f","transaction_id":"964a0efa3def692f","subtype":"http","stacktrace":[{"filename":"\/srv\/app\/vendor\/guzzlehttp\/guzzle\/src\/Handler\/CurlHandler.php","function":"curl_exec()","lineno":44},{"filename":"\/srv\/app\/vendor\/guzzlehttp\/guzzle\/src\/Handler\/Proxy.php","function":"GuzzleHttp\\Handler\\CurlHandler->__invoke()","lineno":28},{"filename":"\/srv\/app\/vendor\/guzzlehttp\/guzzle\/src\/Handler\/Proxy.php","function":"GuzzleHttp\\Handler\\Proxy::GuzzleHttp\\Handler\\{closure}()","lineno":48},{"filename":"\/srv\/app\/vendor\/guzzlehttp\/guzzle\/src\/PrepareBodyMiddleware.php","function":"GuzzleHttp\\Handler\\Proxy::GuzzleHttp\\Handler\\{closure}()","lineno":64},{"filename":"\/srv\/app\/vendor\/guzzlehttp\/guzzle\/src\/Middleware.php","function":"GuzzleHttp\\PrepareBodyMiddleware->__invoke()","lineno":31},{"filename":"\/srv\/app\/vendor\/guzzlehttp\/guzzle\/src\/RedirectMiddleware.php","function":"GuzzleHttp\\Middleware::GuzzleHttp\\{closure}()","lineno":71},{"filename":"\/srv\/app\/vendor\/guzzlehttp\/guzzle\/src\/Middleware.php","function":"GuzzleHttp\\RedirectMiddleware->__invoke()","lineno":63},{"filename":"\/srv\/app\/vendor\/guzzlehttp\/guzzle\/src\/HandlerStack.php","function":"GuzzleHttp\\Middleware::GuzzleHttp\\{closure}()","lineno":75},{"filename":"\/srv\/app\/vendor\/guzzlehttp\/guzzle\/src\/Client.php","function":"GuzzleHttp\\HandlerStack->__invoke()","lineno":331},{"filename":"\/srv\/app\/vendor\/guzzlehttp\/guzzle\/src\/Client.php","function":"GuzzleHttp\\Client->transfer()","lineno":168},{"filename":"\/srv\/app\/vendor\/guzzlehttp\/guzzle\/src\/Client.php","function":"GuzzleHttp\\Client->requestAsync()","lineno":187},{"filename":"\/srv\/app\/vendor\/guzzlehttp\/guzzle\/src\/ClientTrait.php","function":"GuzzleHttp\\Client->request()","lineno":78},{"filename":"\/srv\/app\/apm.php","function":"GuzzleHttp\\Client->put()","lineno":8}],"context":{"destination":{"service":{"name":"https\/\/httpbin.org","resource":"httpbin.org:443","type":"external"}},"http":{"url":"https:\/\/httpbin.org\/put","status_code":200,"method":"POST"}}}}
4, Repeat, removing the request body, and observe that the span name changes to PUT <url>
Expected behavior Span name is reported with PUT