diff --git a/lib/context/method-descriptor-builder.js b/lib/context/method-descriptor-builder.js index e3c8fd41..a6295cd2 100644 --- a/lib/context/method-descriptor-builder.js +++ b/lib/context/method-descriptor-builder.js @@ -214,6 +214,9 @@ function makeFunctionName(namedGroup) { if (computedGroups && computedGroups.length > 0 && namedGroup.methodName) { return computedGroups.groups.functionName + namedGroup.methodName } + if (functionName === '' && typeof namedGroup.type === 'string' && typeof namedGroup.methodName === 'string') { + return namedGroup.methodName + } return namedGroup.functionName } diff --git a/test/context/make-method-descriptor-builder.test.js b/test/context/make-method-descriptor-builder.test.js index 616aeeca..5b1aa2e0 100644 --- a/test/context/make-method-descriptor-builder.test.js +++ b/test/context/make-method-descriptor-builder.test.js @@ -7,6 +7,8 @@ const test = require('tape') const { captureNamedGroup } = require('../../lib/context/make-method-descriptor-builder') const MethodDescriptorBuilder = require('../../lib/context/method-descriptor-builder') +const KoaMethodDescriptorBuilder = require('../../lib/context/koa-method-descriptor-builder') +const ExpressMethodDescriptorBuilder = require('../../lib/context/express-method-descriptor-builder') const actualCallStack = `Error at patchLayer (/Users/test/workspace/pinpoint/pinpoint-node-agent/lib/instrumentation/module/express.js:83:65) @@ -53,6 +55,24 @@ test('express makeMethodDescriptorBuilder', (t) => { actualMethodDescriptor = MethodDescriptorBuilder.make(undefined, actual).build() t.equal(actualMethodDescriptor.getApiDescriptor(), 'FunctionName()') + const stacks = actualCallStack.split(/\r?\n/) + actual = captureNamedGroup(stacks[3]) //at Function.app. [as get] (/Users/test/workspace/pinpoint/pinpoint-node-agent/node_modules/express/lib/application.js:481:30) + t.equal(actual.type, 'Function', 'className') + t.equal(actual.fileName, 'application.js', 'fileName') + t.equal(actual.functionName, 'app.', 'functionName') + t.equal(actual.lineNumber, '481', 'lineNumber') + t.true(actual.location.endsWith('express/lib/'), 'location') + t.equal(actual.methodName, 'get', 'methodName') + + const methodDescriptor = ExpressMethodDescriptorBuilder.make(MethodDescriptorBuilder.make('express', actual)).build() + t.equal(methodDescriptor.apiDescriptor, 'express.Function.app.get(path, callback)', 'apiDescriptor') + t.equal(methodDescriptor.className, 'Function', 'className') + t.equal(methodDescriptor.fullName, 'express.app.get(path, callback)', 'fileName') + t.equal(methodDescriptor.lineNumber, 481, 'lineNumber') + t.true(methodDescriptor.location.endsWith('express/lib/application.js'), 'location') + t.equal(methodDescriptor.methodName, 'get', 'methodName') + t.equal(methodDescriptor.objectPath, 'app.get', 'objectPath') + t.end() }) @@ -82,6 +102,7 @@ at Test.bound [as run] (/Users/test/workspace/pinpoint/pinpoint-node-agent/node_ 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) @@ -91,5 +112,15 @@ test('koa makeMethodDescriptorBuilder', (t) => { t.equal(actual.lineNumber, '202', 'lineNumber') t.true(actual.location.endsWith('koa-router/lib/'), 'location') t.equal(actual.methodName, 'get', 'methodName') + + const methodDescriptor = KoaMethodDescriptorBuilder.make(MethodDescriptorBuilder.make('koa', actual)).build() + t.equal(methodDescriptor.apiDescriptor, 'koa.Router.get(ctx, next)', 'apiDescriptor') + t.equal(methodDescriptor.className, 'Router', 'className') + t.equal(methodDescriptor.fullName, 'koa.get(ctx, next)', 'fullName') + t.equal(methodDescriptor.lineNumber, 202, 'lineNumber') + t.true(methodDescriptor.location.endsWith('koa-router/lib/router.js'), 'location') + t.equal(methodDescriptor.methodName, 'get', 'methodName') + t.equal(methodDescriptor.objectPath, 'get', 'objectPath') + t.end() }) \ No newline at end of file