A workaround to report Guzzle requests with correct Host Http header in NewRelic.
In some case, you may use a common proxy for several external calls to various hosts,
using the standard Host
to route your requests.
Unfortunatly, since all of these calls use the same uri, NewRelic will report them as external calls to the same target.
This small script provide a workaround to report the correct endpoint according to the HTTP Host
header.
ℹ️An official feature request has been submitted to NewRelic team.
composer require bedrockstreaming/newrelic-guzzle-http-host
That's all! The script is automatically imported thanks to Composer autoloader.
ℹ️ You can also copy the content of newrelic_hook.php
directly in your project.
The newrelic extension defines a Php function, a Guzzle middleware to report some metrics on each requests sent from Php.
Fortunately, the extension defines this function only if it doesn't already exist… then this workaround define this function before newrelic does 😅.
Original code is copied in this function, but we create a new http requests dedicated to NewRelic reporting, resolving the Http HOST
header.
The original request used by Guzzle stays unchanged.