-
Notifications
You must be signed in to change notification settings - Fork 401
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Updated koa instrumentation to properly get the matched route name and to handle changes in @koa/[email protected]
#2486
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -422,7 +422,7 @@ module.exports = (pkg) => { | |
) | ||
}) | ||
|
||
t.test('using multipler routers', (t) => { | ||
t.test('using multiple routers', (t) => { | ||
t.beforeEach(testSetup) | ||
t.afterEach(tearDown) | ||
t.autoend() | ||
|
@@ -546,23 +546,20 @@ module.exports = (pkg) => { | |
nestedRouter.get('/:second', function terminalMiddleware(ctx) { | ||
ctx.body = 'this is a test' | ||
}) | ||
nestedRouter.get('/second', function secondMiddleware(ctx) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I removed this because this middleware is never called but we had logic in |
||
ctx.body = 'want this to set the name' | ||
}) | ||
router.use('/:first', nestedRouter.routes()) | ||
app.use(router.routes()) | ||
|
||
agent.on('transactionFinished', (tx) => { | ||
t.assertSegments(tx.trace.root, [ | ||
'WebTransaction/WebFrameworkUri/Koa/GET//:first/second', | ||
'WebTransaction/WebFrameworkUri/Koa/GET//:first/:second', | ||
[ | ||
'Nodejs/Middleware/Koa/appLevelMiddleware', | ||
['Koa/Router: /', [getNestedSpanName('terminalMiddleware')]] | ||
] | ||
]) | ||
t.equal( | ||
tx.name, | ||
'WebTransaction/WebFrameworkUri/Koa/GET//:first/second', | ||
'WebTransaction/WebFrameworkUri/Koa/GET//:first/:second', | ||
'should be named after last matched route' | ||
) | ||
t.end() | ||
|
@@ -581,23 +578,20 @@ module.exports = (pkg) => { | |
router.get('/:second', function terminalMiddleware(ctx) { | ||
ctx.body = 'this is a test' | ||
}) | ||
router.get('/second', function secondMiddleware(ctx) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is where that test was introduced: newrelic/node-newrelic-koa@4493aab but like i said before it's not actually hitting this handler |
||
ctx.body = 'want this to set the name' | ||
}) | ||
router.prefix('/:first') | ||
app.use(router.routes()) | ||
|
||
agent.on('transactionFinished', (tx) => { | ||
t.assertSegments(tx.trace.root, [ | ||
'WebTransaction/WebFrameworkUri/Koa/GET//:first/second', | ||
'WebTransaction/WebFrameworkUri/Koa/GET//:first/:second', | ||
[ | ||
'Nodejs/Middleware/Koa/appLevelMiddleware', | ||
['Koa/Router: /', ['Nodejs/Middleware/Koa/terminalMiddleware//:first/:second']] | ||
] | ||
]) | ||
t.equal( | ||
tx.name, | ||
'WebTransaction/WebFrameworkUri/Koa/GET//:first/second', | ||
'WebTransaction/WebFrameworkUri/Koa/GET//:first/:second', | ||
'should be named after the last matched path' | ||
) | ||
t.end() | ||
|
@@ -607,6 +601,11 @@ module.exports = (pkg) => { | |
}) | ||
|
||
t.test('using allowedMethods', (t) => { | ||
// `@koa/[email protected]` changed the allowedMethods middleware function from named to arrow function | ||
// update span name for assertions | ||
Comment on lines
+604
to
+605
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wonderful change. Who would want to see function names in stack traces? |
||
const allowedMethodsFnName = semver.gte(pkgVersion, '13.0.0') | ||
? '<anonymous>' | ||
: 'allowedMethods' | ||
t.autoend() | ||
|
||
t.test('with throw: true', (t) => { | ||
|
@@ -622,7 +621,7 @@ module.exports = (pkg) => { | |
agent.on('transactionFinished', (tx) => { | ||
t.assertSegments(tx.trace.root, [ | ||
'WebTransaction/WebFrameworkUri/Koa/GET/(method not allowed)', | ||
['Koa/Router: /', ['Nodejs/Middleware/Koa/allowedMethods']] | ||
['Koa/Router: /', [`Nodejs/Middleware/Koa/${allowedMethodsFnName}`]] | ||
]) | ||
t.equal( | ||
tx.name, | ||
|
@@ -645,7 +644,7 @@ module.exports = (pkg) => { | |
agent.on('transactionFinished', (tx) => { | ||
t.assertSegments(tx.trace.root, [ | ||
'WebTransaction/WebFrameworkUri/Koa/GET/(not implemented)', | ||
['Koa/Router: /', ['Nodejs/Middleware/Koa/allowedMethods']] | ||
['Koa/Router: /', [`Nodejs/Middleware/Koa/${allowedMethodsFnName}`]] | ||
]) | ||
t.equal( | ||
tx.name, | ||
|
@@ -683,7 +682,7 @@ module.exports = (pkg) => { | |
'WebTransaction/NormalizedUri/*', | ||
[ | ||
'Nodejs/Middleware/Koa/errorHandler', | ||
['Koa/Router: /', ['Nodejs/Middleware/Koa/allowedMethods']] | ||
['Koa/Router: /', [`Nodejs/Middleware/Koa/${allowedMethodsFnName}`]] | ||
] | ||
]) | ||
t.equal( | ||
|
@@ -722,7 +721,7 @@ module.exports = (pkg) => { | |
'WebTransaction/WebFrameworkUri/Koa/GET/(method not allowed)', | ||
[ | ||
'Nodejs/Middleware/Koa/baseMiddleware', | ||
['Koa/Router: /', ['Nodejs/Middleware/Koa/allowedMethods']] | ||
['Koa/Router: /', [`Nodejs/Middleware/Koa/${allowedMethodsFnName}`]] | ||
] | ||
]) | ||
t.equal( | ||
|
@@ -753,7 +752,7 @@ module.exports = (pkg) => { | |
agent.on('transactionFinished', (tx) => { | ||
t.assertSegments(tx.trace.root, [ | ||
'WebTransaction/WebFrameworkUri/Koa/GET/(method not allowed)', | ||
['Koa/Router: /', ['Nodejs/Middleware/Koa/allowedMethods']] | ||
['Koa/Router: /', [`Nodejs/Middleware/Koa/${allowedMethodsFnName}`]] | ||
]) | ||
t.equal( | ||
tx.name, | ||
|
@@ -777,7 +776,7 @@ module.exports = (pkg) => { | |
agent.on('transactionFinished', (tx) => { | ||
t.assertSegments(tx.trace.root, [ | ||
'WebTransaction/WebFrameworkUri/Koa/GET/(not implemented)', | ||
['Koa/Router: /', ['Nodejs/Middleware/Koa/allowedMethods']] | ||
['Koa/Router: /', [`Nodejs/Middleware/Koa/${allowedMethodsFnName}`]] | ||
]) | ||
t.equal( | ||
tx.name, | ||
|
@@ -811,7 +810,7 @@ module.exports = (pkg) => { | |
'WebTransaction/WebFrameworkUri/Koa/GET/(method not allowed)', | ||
[ | ||
'Nodejs/Middleware/Koa/appLevelMiddleware', | ||
['Koa/Router: /', ['Nodejs/Middleware/Koa/allowedMethods']] | ||
['Koa/Router: /', [`Nodejs/Middleware/Koa/${allowedMethodsFnName}`]] | ||
] | ||
]) | ||
t.equal( | ||
|
@@ -845,7 +844,7 @@ module.exports = (pkg) => { | |
'WebTransaction/WebFrameworkUri/Koa/GET/(not implemented)', | ||
[ | ||
'Nodejs/Middleware/Koa/appLevelMiddleware', | ||
['Koa/Router: /', ['Nodejs/Middleware/Koa/allowedMethods']] | ||
['Koa/Router: /', [`Nodejs/Middleware/Koa/${allowedMethodsFnName}`]] | ||
] | ||
]) | ||
t.equal( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no reason to find the layer as this setter passes in which layer was matched