diff --git a/lib/instrumentation/module/koa-router.js b/lib/instrumentation/module/koa-router.js index ee45ef1c..f9b98e96 100644 --- a/lib/instrumentation/module/koa-router.js +++ b/lib/instrumentation/module/koa-router.js @@ -41,7 +41,7 @@ module.exports = function (agent, version, router) { return layer } - const builder = KoaMethodDescriptorBuilder.make(makeMethodDescriptorBuilder('koa', 3, 4)) + const builder = KoaMethodDescriptorBuilder.make(makeMethodDescriptorBuilder('koa', 2, 3)) const methodDescriptor = apiMetaService.cacheApiWithBuilder(builder) layer.stack[handlerIndex] = async function (ctx, next) { const name = fn.name || 'AnonymousFunction' diff --git a/test/context/make-method-descriptor-builder.test.js b/test/context/make-method-descriptor-builder.test.js index ea769dc2..616aeeca 100644 --- a/test/context/make-method-descriptor-builder.test.js +++ b/test/context/make-method-descriptor-builder.test.js @@ -9,20 +9,20 @@ const { captureNamedGroup } = require('../../lib/context/make-method-descriptor- const MethodDescriptorBuilder = require('../../lib/context/method-descriptor-builder') const actualCallStack = `Error -at patchLayer (/Users/feelform/workspace/pinpoint/pinpoint-node-agent/lib/instrumentation/module/express.js:83:65) -at Function.route (/Users/feelform/workspace/pinpoint/pinpoint-node-agent/lib/instrumentation/module/express.js:73:9) -at Function.app. [as get] (/Users/feelform/workspace/pinpoint/pinpoint-node-agent/node_modules/express/lib/application.js:481:30) -at /Users/feelform/workspace/pinpoint/pinpoint-node-agent/test/utils/ant-path-matcher.test.js:206:13 +at patchLayer (/Users/test/workspace/pinpoint/pinpoint-node-agent/lib/instrumentation/module/express.js:83:65) +at Function.route (/Users/test/workspace/pinpoint/pinpoint-node-agent/lib/instrumentation/module/express.js:73:9) +at Function.app. [as get] (/Users/test/workspace/pinpoint/pinpoint-node-agent/node_modules/express/lib/application.js:481:30) +at /Users/test/workspace/pinpoint/pinpoint-node-agent/test/utils/ant-path-matcher.test.js:206:13 at new Promise () -at outgoingRequest (/Users/feelform/workspace/pinpoint/pinpoint-node-agent/test/utils/ant-path-matcher.test.js:194:12) -at Test. (/Users/feelform/workspace/pinpoint/pinpoint-node-agent/test/utils/ant-path-matcher.test.js:181:11) -at Test.bound [as _cb] (/Users/feelform/workspace/pinpoint/pinpoint-node-agent/node_modules/tape/lib/test.js:80:32) -at Test.run (/Users/feelform/workspace/pinpoint/pinpoint-node-agent/node_modules/tape/lib/test.js:96:10) -at Test.bound [as run] (/Users/feelform/workspace/pinpoint/pinpoint-node-agent/node_modules/tape/lib/test.js:80:32) -at Immediate.next [as _onImmediate] (/Users/feelform/workspace/pinpoint/pinpoint-node-agent/node_modules/tape/lib/results.js:83:19) +at outgoingRequest (/Users/test/workspace/pinpoint/pinpoint-node-agent/test/utils/ant-path-matcher.test.js:194:12) +at Test. (/Users/test/workspace/pinpoint/pinpoint-node-agent/test/utils/ant-path-matcher.test.js:181:11) +at Test.bound [as _cb] (/Users/test/workspace/pinpoint/pinpoint-node-agent/node_modules/tape/lib/test.js:80:32) +at Test.run (/Users/test/workspace/pinpoint/pinpoint-node-agent/node_modules/tape/lib/test.js:96:10) +at Test.bound [as run] (/Users/test/workspace/pinpoint/pinpoint-node-agent/node_modules/tape/lib/test.js:80:32) +at Immediate.next [as _onImmediate] (/Users/test/workspace/pinpoint/pinpoint-node-agent/node_modules/tape/lib/results.js:83:19) at processImmediate (internal/timers.js:456:21)` -test('makeMethodDescriptorBuilder', (t) => { +test('express makeMethodDescriptorBuilder', (t) => { let actual = captureNamedGroup('at new functionName (internal/modules/cjs/loader.js:699:10)') t.equal(actual.type, undefined, 'className') t.equal(actual.fileName, 'loader.js', 'fileName') @@ -56,7 +56,7 @@ test('makeMethodDescriptorBuilder', (t) => { t.end() }) -test('makeMethodDescriptorBuilder exception case', (t) => { +test('express makeMethodDescriptorBuilder exception case', (t) => { const stacks = actualCallStack.split(/\r?\n/) let actual = captureNamedGroup(stacks[5]) //at new Promise () t.equal(actual.type, undefined, 'className') @@ -70,4 +70,26 @@ test('makeMethodDescriptorBuilder exception case', (t) => { t.equal(actualMethodDescriptor.getLineNumber(), undefined, 'lineNumber actualMethodDescriptor') t.equal(actualMethodDescriptor.getLocation(), '', 'location actualMethodDescriptor') t.end() +}) + +const actualKoaCallStack = `Error +at Router.register (/Users/test/workspace/pinpoint/pinpoint-node-agent/lib/instrumentation/module/koa-router.js:44:55) +at Router. [as get] (/Users/test/workspace/pinpoint/pinpoint-node-agent/node_modules/koa-router/lib/router.js:202:10) +at Test. (/Users/test/workspace/pinpoint/pinpoint-node-agent/test/instrumentation/module/koa.test.js:31:10) +at Test.bound [as _cb] (/Users/test/workspace/pinpoint/pinpoint-node-agent/node_modules/tape/lib/test.js:80:32) +at Test.run (/Users/test/workspace/pinpoint/pinpoint-node-agent/node_modules/tape/lib/test.js:96:10) +at Test.bound [as run] (/Users/test/workspace/pinpoint/pinpoint-node-agent/node_modules/tape/lib/test.js:80:32) +at Immediate.next [as _onImmediate] (/Users/test/workspace/pinpoint/pinpoint-node-agent/node_modules/tape/lib/results.js:83:19) +at processImmediate (internal/timers.js:464:21) +at process.callbackTrampoline (internal/async_hooks.js:130:17)` +test('koa makeMethodDescriptorBuilder', (t) => { + const stacks = actualKoaCallStack.split(/\r?\n/) + let actual = captureNamedGroup(stacks[2]) //at Router. [as get] (/Users/test/workspace/pinpoint/pinpoint-node-agent/node_modules/koa-router/lib/router.js:202:10) + t.equal(actual.type, 'Router', 'className') + t.equal(actual.fileName, 'router.js', 'fileName') + t.equal(actual.functionName, '', 'functionName') + t.equal(actual.lineNumber, '202', 'lineNumber') + t.true(actual.location.endsWith('koa-router/lib/'), 'location') + t.equal(actual.methodName, 'get', 'methodName') + t.end() }) \ No newline at end of file diff --git a/test/context/method-descriptor-builder.test.js b/test/context/method-descriptor-builder.test.js index ac9ba3f0..32321435 100644 --- a/test/context/method-descriptor-builder.test.js +++ b/test/context/method-descriptor-builder.test.js @@ -7,7 +7,7 @@ const test = require('tape') const MethodDescriptorBuilder = require('../../lib/context/method-descriptor-builder') -test('callstack', (t) => { +test('express callstack', (t) => { const regex = /at (?\w+(?=\.))?\.?(?[^\s]+)(?: \[as (?\w+)\])? \(.+\/(?[^:/]+):(?[0-9]+):(?[0-9]+)\)$/ let stack = 'at Function.app. [as get] (/Users/feelform/workspace/pinpoint/pinpoint-node-agent/node_modules/express/lib/application.js:481:30)'