roadrunner-server / roadrunner-plugins

📦 Home for the roadrunner plugins
MIT License
25 stars 9 forks source link

feat(http): New Relic HTTP middleware #87

Closed rustatian closed 3 years ago

rustatian commented 3 years ago

Reason for This PR

closes: #85

Description of Changes

config:

http:
  address: 127.0.0.1:15389
  middleware: [ "new_relic" ]
  new_relic:
    app_name: "app"
    license_key: "key"
  pool:
    num_workers: 10
    allocate_timeout: 60s
    destroy_timeout: 60s

License key and application name could be set via environment variables: (leave app_name and license_key empty)

To set the New Relic attributes, the PHP worker should send headers values witing the rr_newrelic header key. Attributes should be separated by the :, for example foo:bar, where foo is a key and bar is a value. New Relic attributes sent from the worker will not appear in the HTTP response, they will be sent directly to the New Relic.

To see the sample of the PHP library, see the @arku31 implementation: https://github.com/arku31/roadrunner-newrelic

The special key which PHP may set to overwrite the transaction name is: transaction_name. For example: transaction_name:foo means: set transaction name as foo. By default, RequestURI is used as the transaction name.

PHP:

        $resp = new \Nyholm\Psr7\Response();
        $rrNewRelic = [
            'shopId:1', //custom data
            'auth:password', //custom data
            'transaction_name:test_transaction' //name - special key to override the name. By default it will use requestUri.
        ];

        $resp = $resp->withHeader('rr_newrelic', $rrNewRelic);

New Relic:

image

image

image

License Acceptance

By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license.

PR Checklist

[Author TODO: Meet these criteria.] [Reviewer TODO: Verify that these criteria are met. Request changes if not]

codecov[bot] commented 3 years ago

Codecov Report

Merging #87 (6724c93) into master (8ceaeca) will decrease coverage by 0.44%. The diff coverage is 72.50%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #87      +/-   ##
==========================================
- Coverage   68.93%   68.49%   -0.45%     
==========================================
  Files         119      118       -1     
  Lines        9993     9947      -46     
==========================================
- Hits         6889     6813      -76     
- Misses       2429     2460      +31     
+ Partials      675      674       -1     
Impacted Files Coverage Δ
http/handler/response.go 47.61% <60.71%> (-47.21%) :arrow_down:
http/handler/handler.go 84.88% <100.00%> (+2.22%) :arrow_up:
http/handler/request.go 78.48% <100.00%> (+1.26%) :arrow_up:
jobs/listener.go 35.15% <0.00%> (-12.50%) :arrow_down:
sqs/sqsjobs/item.go 67.10% <0.00%> (-5.93%) :arrow_down:
jobs/metrics.go 95.91% <0.00%> (-4.09%) :arrow_down:
server/plugin.go 64.81% <0.00%> (-1.24%) :arrow_down:
jobs/plugin.go 61.35% <0.00%> (-0.49%) :arrow_down:
http/handler/errors.go
... and 3 more

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 8ceaeca...6724c93. Read the comment docs.