Skip to content

Commit

Permalink
[#104] koa moudle callstack parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
feelform committed Jan 27, 2022
1 parent 68866b9 commit e91162a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 14 deletions.
2 changes: 1 addition & 1 deletion lib/instrumentation/module/koa-router.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
46 changes: 34 additions & 12 deletions test/context/make-method-descriptor-builder.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.<computed> [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.<computed> [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 (<anonymous>)
at outgoingRequest (/Users/feelform/workspace/pinpoint/pinpoint-node-agent/test/utils/ant-path-matcher.test.js:194:12)
at Test.<anonymous> (/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.<anonymous> (/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')
Expand Down Expand Up @@ -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 (<anonymous>)
t.equal(actual.type, undefined, 'className')
Expand All @@ -70,4 +70,26 @@ test('makeMethodDescriptorBuilder exception case', (t) => {
t.equal(actualMethodDescriptor.getLineNumber(), undefined, 'lineNumber actualMethodDescriptor')
t.equal(actualMethodDescriptor.getLocation(), '<anonymous>', '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.<computed> [as get] (/Users/test/workspace/pinpoint/pinpoint-node-agent/node_modules/koa-router/lib/router.js:202:10)
at Test.<anonymous> (/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.<computed> [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, '<computed>', 'functionName')
t.equal(actual.lineNumber, '202', 'lineNumber')
t.true(actual.location.endsWith('koa-router/lib/'), 'location')
t.equal(actual.methodName, 'get', 'methodName')
t.end()
})
2 changes: 1 addition & 1 deletion test/context/method-descriptor-builder.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (?<type>\w+(?=\.))?\.?(?<functionName>[^\s]+)(?: \[as (?<methodName>\w+)\])? \(.+\/(?<fileName>[^:/]+):(?<lineNumber>[0-9]+):(?<columnNumber>[0-9]+)\)$/

let stack = 'at Function.app.<computed> [as get] (/Users/feelform/workspace/pinpoint/pinpoint-node-agent/node_modules/express/lib/application.js:481:30)'
Expand Down

0 comments on commit e91162a

Please sign in to comment.