Skip to content

Commit

Permalink
Merge pull request newrelic#1393 from NodeJS-agent/psvet/fix-hapi-pre
Browse files Browse the repository at this point in the history
NODE-1713 Fix Hapi 'pre' config wrapping
  • Loading branch information
Bryan Clement authored and GitHub Enterprise committed Mar 23, 2018
2 parents 6b45283 + 7837b6e commit 24d3f1c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
4 changes: 4 additions & 0 deletions lib/instrumentation/hapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ function wrapPreHandlers(shim, container, path) {
return _wrapPreHandler(handler)
})
}
// The 'pre' option also allows strings pointing to methods registered via
// server.method() (ie: 'methodName(args)'). For the most part, these should
// be simple utility functions, but may be something we want to wrap in the future.
return container

function _wrapPreHandler(handler) {
return shim.recordMiddleware(
Expand Down
8 changes: 8 additions & 0 deletions test/versioned/hapi/hapi-pre-17/router-v16.tap.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ tap.test('Hapi router introspection', function(t) {
t.test('using `pre` config option', function(t) {
agent.on('transactionFinished', utils.verifier(t))

server.method('test', function(arg, next) {
t.ok(agent.getTransaction(), 'transaction available in server method')
next()
})

var route = {
method: 'GET',
path: '/test/{id}',
Expand All @@ -99,6 +104,9 @@ tap.test('Hapi router introspection', function(t) {
t.ok(agent.getTransaction(), 'transaction available in plain `pre` function')
reply()
},
{
method: 'test'
},
[
{
method: function nested(req, reply) {
Expand Down
4 changes: 2 additions & 2 deletions test/versioned/restify/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"node": "^0.10"
},
"dependencies": {
"restify": ">=5.0.0 <6.3.4 || >6.3.4",
"restify": ">=5.0.0 <6.3.4 || >6.3.4 <7",
"express": "4.16"
},
"files": [
Expand All @@ -41,7 +41,7 @@
"node": ">=0.11.0"
},
"dependencies": {
"restify": ">=5.0.0",
"restify": ">=5.0.0 <7",
"express": "4.16"
},
"files": [
Expand Down

0 comments on commit 24d3f1c

Please sign in to comment.