Skip to content

Commit

Permalink
[pinpoint-apm#101] handler and HTTP methods express function are merged
Browse files Browse the repository at this point in the history
  • Loading branch information
feelform committed Dec 9, 2021
1 parent 21db17e commit 1a4b059
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 22 deletions.
13 changes: 11 additions & 2 deletions lib/context/make-method-descriptor-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,19 @@
'use strict'

const MethodDescriptorBuilder = require('./method-descriptor-builder')
const makeMethodDescriptorBuilder = (moduleName, index) => {
const makeMethodDescriptorBuilder = (moduleName, index, handlerIndex) => {
const callstack = {}
Error.captureStackTrace(callstack, makeMethodDescriptorBuilder)
return MethodDescriptorBuilder.make(moduleName, captureNamedGroup(stringStackOfCallStack(callstack, index)))

const builder = MethodDescriptorBuilder.make(moduleName, captureNamedGroup(stringStackOfCallStack(callstack, index)))

if (handlerIndex && typeof handlerIndex === 'number') {
const handlerBuilder = MethodDescriptorBuilder.make(moduleName, captureNamedGroup(stringStackOfCallStack(callstack, handlerIndex)))
builder.setLineNumber(handlerBuilder.getLineNumber())
.setLocation(handlerBuilder.getLocation())
.setFileName(handlerBuilder.getFileName())
}
return builder
}

const stringStackOfCallStack = (callstack, index) => {
Expand Down
12 changes: 12 additions & 0 deletions lib/context/method-descriptor-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,28 @@ class MethodDescriptorBuilder {
return this
}

getLineNumber() {
return this.lineNumber
}

setLocation(location) {
this.location = location
return this
}

getLocation() {
return this.location
}

setFileName(fileName) {
this.fileName = fileName
return this
}

getFileName() {
return this.fileName
}

build() {
const apiDescriptor = this.apiDescriptor || this.computedApiDescriptor
const fullName = this.fullName || this.computedFullName
Expand Down
2 changes: 1 addition & 1 deletion lib/instrumentation/module/express.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ module.exports = function (agent, version, express) {
if (!layer[layerPatchedSymbol]) {
layer[layerPatchedSymbol] = true

const appAllbuilder = ExpressMethodDescriptorBuilder.make(makeMethodDescriptorBuilder(MODULE_NAME, indexOfRoute(objectName)))
const appAllbuilder = ExpressMethodDescriptorBuilder.make(makeMethodDescriptorBuilder(MODULE_NAME, indexOfRoute(objectName), indexOfHandle(objectName)))
const appAllMethodDescriptor = apiMetaService.cacheApiWithBuilder(appAllbuilder)
const handlerBuilder = makeMethodDescriptorBuilder(undefined, indexOfHandle(objectName))
const handlerMethodDescriptor = apiMetaService.cacheApiWithBuilder(handlerBuilder)
Expand Down
38 changes: 19 additions & 19 deletions test/instrumentation/module/express.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ test(`${testName1} Should record request in basic route`, function (t) {

let actualBuilder = new MethodDescriptorBuilder('express', 'app.get')
.setParameterDescriptor('(path, callback)')
.setLineNumber(481)
.setFileName('application.js')
.setLineNumber(33)
.setFileName('express.test.js')
const actualMethodDescriptor = apiMetaService.cacheApiWithBuilder(actualBuilder)
let spanEvent = trace.storage.storage[1]
t.equal(actualMethodDescriptor.apiId, spanEvent.apiId, 'apiId')
Expand All @@ -50,7 +50,7 @@ test(`${testName1} Should record request in basic route`, function (t) {
t.true(actualMethodDescriptor.apiDescriptor.startsWith('express.Function.app.get(path, callback)'), 'apiDescriptor')
t.equal(actualMethodDescriptor.className, 'Function', 'className')
t.equal(actualMethodDescriptor.fullName, 'express.app.get(path, callback)', 'fullName')
t.equal(actualMethodDescriptor.lineNumber, 481, 'lineNumber')
t.equal(actualMethodDescriptor.lineNumber, 33, 'lineNumber')
t.equal(actualMethodDescriptor.methodName, 'get', 'methodName')
t.equal(actualMethodDescriptor.moduleName, 'express', 'moduleName')
t.equal(actualMethodDescriptor.objectPath, 'app.get', 'objectPath')
Expand Down Expand Up @@ -78,8 +78,8 @@ test(`${testName1} Should record request in basic route`, function (t) {

let actualBuilder = new MethodDescriptorBuilder('express', 'app.post')
.setParameterDescriptor('(path, callback)')
.setLineNumber(481)
.setFileName('application.js')
.setLineNumber(72)
.setFileName('express.test.js')
const actualMethodDescriptor = apiMetaService.cacheApiWithBuilder(actualBuilder)
let spanEvent = trace.storage.storage[1]
t.equal(actualMethodDescriptor.apiId, spanEvent.apiId, 'apiId')
Expand All @@ -88,11 +88,11 @@ test(`${testName1} Should record request in basic route`, function (t) {
t.true(actualMethodDescriptor.apiDescriptor.startsWith('express.Function.app.post(path, callback)'), 'apiDescriptor')
t.equal(actualMethodDescriptor.className, 'Function', 'className')
t.equal(actualMethodDescriptor.fullName, 'express.app.post(path, callback)', 'fullName')
t.equal(actualMethodDescriptor.lineNumber, 481, 'lineNumber')
t.equal(actualMethodDescriptor.lineNumber, 72, 'lineNumber')
t.equal(actualMethodDescriptor.methodName, 'post', 'methodName')
t.equal(actualMethodDescriptor.moduleName, 'express', 'moduleName')
t.equal(actualMethodDescriptor.objectPath, 'app.post', 'objectPath')
t.true(actualMethodDescriptor.location.endsWith('application.js'), 'location')
t.true(actualMethodDescriptor.location.endsWith('express.test.js'), 'location')

actualBuilder = new MethodDescriptorBuilder(undefined, '<anonymous>')
.setLineNumber(72)
Expand All @@ -114,8 +114,8 @@ test(`${testName1} Should record request in basic route`, function (t) {
const trace = agent.traceContext.currentTraceObject()
let actualBuilder = new MethodDescriptorBuilder('express', 'app.get')
.setParameterDescriptor('(path, callback)')
.setLineNumber(481)
.setFileName('application.js')
.setLineNumber(110)
.setFileName('express.test.js')
const actualMethodDescriptor = apiMetaService.cacheApiWithBuilder(actualBuilder)
let spanEvent = trace.storage.storage[1]
t.equal(actualMethodDescriptor.apiId, spanEvent.apiId, 'apiId')
Expand All @@ -124,11 +124,11 @@ test(`${testName1} Should record request in basic route`, function (t) {
t.true(actualMethodDescriptor.apiDescriptor.startsWith('express.Function.app.get(path, callback)'), 'apiDescriptor')
t.equal(actualMethodDescriptor.className, 'Function', 'className')
t.equal(actualMethodDescriptor.fullName, 'express.app.get(path, callback)', 'fullName')
t.equal(actualMethodDescriptor.lineNumber, 481, 'lineNumber')
t.equal(actualMethodDescriptor.lineNumber, 110, 'lineNumber')
t.equal(actualMethodDescriptor.methodName, 'get', 'methodName')
t.equal(actualMethodDescriptor.moduleName, 'express', 'moduleName')
t.equal(actualMethodDescriptor.objectPath, 'app.get', 'objectPath')
t.true(actualMethodDescriptor.location.endsWith('application.js'), 'location')
t.true(actualMethodDescriptor.location.endsWith('express.test.js'), 'location')

actualBuilder = new MethodDescriptorBuilder(undefined, '<anonymous>')
.setLineNumber(110)
Expand Down Expand Up @@ -216,8 +216,8 @@ test(`${testName1} Should record request in basic route`, function (t) {
function throwHandleTest(trace, t) {
let actualBuilder = new MethodDescriptorBuilder('express', 'app.get')
.setParameterDescriptor('(path, callback)')
.setLineNumber(481)
.setFileName('application.js')
.setLineNumber(150)
.setFileName('express.test.js')
const actualMethodDescriptor = apiMetaService.cacheApiWithBuilder(actualBuilder)
let spanEvent = trace.storage.storage[3]
t.equal(actualMethodDescriptor.apiId, spanEvent.apiId, 'apiId')
Expand All @@ -226,11 +226,11 @@ function throwHandleTest(trace, t) {
t.true(actualMethodDescriptor.apiDescriptor.startsWith('express.Function.app.get(path, callback)'), 'apiDescriptor')
t.equal(actualMethodDescriptor.className, 'Function', 'className')
t.equal(actualMethodDescriptor.fullName, 'express.app.get(path, callback)', 'fullName')
t.equal(actualMethodDescriptor.lineNumber, 481, 'lineNumber')
t.equal(actualMethodDescriptor.lineNumber, 150, 'lineNumber')
t.equal(actualMethodDescriptor.methodName, 'get', 'methodName')
t.equal(actualMethodDescriptor.moduleName, 'express', 'moduleName')
t.equal(actualMethodDescriptor.objectPath, 'app.get', 'objectPath')
t.true(actualMethodDescriptor.location.endsWith('application.js'), 'location')
t.true(actualMethodDescriptor.location.endsWith('express.test.js'), 'location')
t.equal(spanEvent.sequence, 0, 'sequence')
t.equal(spanEvent.depth, 1, 'spanEvent.depth')

Expand Down Expand Up @@ -274,8 +274,8 @@ function throwHandleTest(trace, t) {
function nextErrorHandleTest(trace, t) {
let actualBuilder = new MethodDescriptorBuilder('express', 'app.get')
.setParameterDescriptor('(path, callback)')
.setLineNumber(481)
.setFileName('application.js')
.setLineNumber(157)
.setFileName('express.test.js')
const actualMethodDescriptor = apiMetaService.cacheApiWithBuilder(actualBuilder)
let spanEvent = trace.storage.storage[3]
t.equal(actualMethodDescriptor.apiId, spanEvent.apiId, 'apiId')
Expand All @@ -284,11 +284,11 @@ function nextErrorHandleTest(trace, t) {
t.true(actualMethodDescriptor.apiDescriptor.startsWith('express.Function.app.get(path, callback)'), 'apiDescriptor')
t.equal(actualMethodDescriptor.className, 'Function', 'className')
t.equal(actualMethodDescriptor.fullName, 'express.app.get(path, callback)', 'fullName')
t.equal(actualMethodDescriptor.lineNumber, 481, 'lineNumber')
t.equal(actualMethodDescriptor.lineNumber, 157, 'lineNumber')
t.equal(actualMethodDescriptor.methodName, 'get', 'methodName')
t.equal(actualMethodDescriptor.moduleName, 'express', 'moduleName')
t.equal(actualMethodDescriptor.objectPath, 'app.get', 'objectPath')
t.true(actualMethodDescriptor.location.endsWith('application.js'), 'location')
t.true(actualMethodDescriptor.location.endsWith('express.test.js'), 'location')
t.equal(spanEvent.sequence, 0, 'sequence')
t.equal(spanEvent.depth, 1, 'spanEvent.depth')

Expand Down

0 comments on commit 1a4b059

Please sign in to comment.