Skip to content

Commit 553ba8d

Browse files
authored
Create README.md
1 parent c16ee58 commit 553ba8d

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

README.md

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# newrelic-guzzle-http-host
2+
A workaround to report Guzzle requests with correct Host Http header in NewRelic.
3+
4+
In some case, you may use a common proxy for several external calls to various hosts,
5+
using the standard [`Host`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Host) to route your requests.
6+
Unfortunatly, since all of these calls use the same uri, NewRelic will report them as external calls to the same target.
7+
8+
This small script provide a workaround to report the correct endpoint according to the HTTP `Host` header.
9+
10+
:warning: This library is a *workaround* relying on the current implementation of the newrelic extension!
11+
Test it carefully before to use it with a new extension release.
12+
See explanations section below for more details.
13+
14+
ℹ️An official feature request has been submitted to NewRelic team.
15+
16+
## Installation
17+
18+
```
19+
composer require bedrockstreaming/newrelic-guzzle-http-host
20+
```
21+
That's all! The script is automatically imported thanks to [Composer autoloader](https://getcomposer.org/doc/04-schema.md#files).
22+
23+
ℹ️ You can also copy the content of [`newrelic_hook.php`](newrelic_hook.php) directly in your project.
24+
25+
## Explanations
26+
27+
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),
28+
a [Guzzle](https://github.com/guzzle/guzzle) middleware to report some metrics on each requests sent from Php.
29+
30+
31+
Fortunately, the extension defines this function only if it doesn't already exist… then this workaround define this function before newrelic does 😅.
32+
Original code is copied in this function, but we create a new http requests dedicated to NewRelic reporting, resolving the Http `HOST` header.
33+
The original request used by Guzzle stays unchanged.
34+

0 commit comments

Comments
 (0)