Skip to content

Commit

Permalink
Create README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
b-viguier authored Mar 16, 2021
1 parent c16ee58 commit 553ba8d
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# newrelic-guzzle-http-host
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`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/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.

:warning: This library is a *workaround* relying on the current implementation of the newrelic extension!
Test it carefully before to use it with a new extension release.
See explanations section below for more details.

ℹ️An official feature request has been submitted to NewRelic team.

## Installation

```
composer require bedrockstreaming/newrelic-guzzle-http-host
```
That's all! The script is automatically imported thanks to [Composer autoloader](https://getcomposer.org/doc/04-schema.md#files).

ℹ️ You can also copy the content of [`newrelic_hook.php`](newrelic_hook.php) directly in your project.

## Explanations

The [newrelic extension](https://github.com/newrelic/newrelic-php-agent) [defines a Php function](https://github.com/newrelic/newrelic-php-agent/blob/3f93ee47f80703d46d8fccd53be7d6b80361a594/agent/lib_guzzle6.c#L433-L461),
a [Guzzle](https://github.com/guzzle/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.

0 comments on commit 553ba8d

Please sign in to comment.