Skip to content

Commit ad87767

Browse files
committed
[#398] Support Exception Chain Metadata (PExceptionMetaData)
1 parent f00af34 commit ad87767

File tree

2 files changed

+36
-73
lines changed

2 files changed

+36
-73
lines changed

lib/context/trace/span-repository.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ class SpanRepository {
8585
this.dataSender.send(spanBuilder.build())
8686

8787
const exceptions = this.exceptions.concat(this.filterExceptions(spanEvents))
88+
if (exceptions.length < 1) {
89+
return
90+
}
8891
const builder = new ExceptionMetaDataBuilder(spanBuilder.getTraceRoot())
8992
exceptions.forEach(exception => builder.addException(exception))
9093
this.dataSender.send(builder.build())

test/instrumentation/module/express.test.js

Lines changed: 33 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const getServerUrl = (path) => `http://${TEST_ENV.host}:${TEST_ENV.port}${path}`
2727

2828
const testName1 = 'express1'
2929
test(`${testName1} Should record request in basic route`, function (t) {
30-
agent.bindHttpWithCallSite()
30+
agent.bindHttp()
3131

3232
const testName = testName1
3333

@@ -43,18 +43,14 @@ test(`${testName1} Should record request in basic route`, function (t) {
4343
t.equal(trace.spanBuilder.annotations[1].key, annotationKey.HTTP_STATUS_CODE.code, 'HTTP status code')
4444
t.equal(trace.spanBuilder.annotations[1].value, 200, 'response status is 200')
4545

46-
let actualBuilder = new MethodDescriptorBuilder(expected('get', 'app.get'))
47-
.setClassName(expected('app', 'Function'))
48-
.setLineNumber(37)
49-
.setFileName('express.test.js')
46+
let actualBuilder = new MethodDescriptorBuilder('get')
47+
.setClassName('Router')
5048
const actualMethodDescriptor = apiMetaService.cacheApiWithBuilder(actualBuilder)
5149
let spanEvent = trace.spanBuilder.spanEventList[0]
5250
t.equal(actualMethodDescriptor.apiId, spanEvent.apiId, 'apiId')
53-
t.true(actualMethodDescriptor.apiDescriptor.startsWith(expected('app.get', 'Function.app.get')), 'apiDescriptor')
54-
t.equal(actualMethodDescriptor.className, expected('app', 'Function'), 'className')
55-
t.equal(actualMethodDescriptor.lineNumber, 37, 'lineNumber')
51+
t.equal(actualMethodDescriptor.apiDescriptor, 'Router.get', 'apiDescriptor')
52+
t.equal(actualMethodDescriptor.className, 'Router', 'className')
5653
t.equal(actualMethodDescriptor.methodName, 'get', 'methodName')
57-
t.true(actualMethodDescriptor.location.length > 0, 'location')
5854
})
5955
})
6056

@@ -66,37 +62,29 @@ test(`${testName1} Should record request in basic route`, function (t) {
6662
t.equal(trace.spanBuilder.annotations[0].key, annotationKey.HTTP_STATUS_CODE.code, '/express1 HTTP STATUS CODE in annotation zero')
6763
t.equal(trace.spanBuilder.annotations[0].value, 200, '/express1 HTTP STATUS CODE value in annotation zero')
6864

69-
let actualBuilder = new MethodDescriptorBuilder(expected('post', 'app.post'))
70-
.setClassName(expected('app', 'Function'))
71-
.setLineNumber(62)
72-
.setFileName('express.test.js')
65+
let actualBuilder = new MethodDescriptorBuilder('post')
66+
.setClassName('Router')
7367
const actualMethodDescriptor = apiMetaService.cacheApiWithBuilder(actualBuilder)
7468
let spanEvent = trace.spanBuilder.spanEventList[0]
7569
t.equal(actualMethodDescriptor.apiId, spanEvent.apiId, 'apiId')
76-
t.true(actualMethodDescriptor.apiDescriptor.startsWith(expected('app.post', 'Function.app.post')), 'apiDescriptor')
77-
t.equal(actualMethodDescriptor.className, expected('app', 'Function'), 'className')
78-
t.equal(actualMethodDescriptor.lineNumber, 62, 'lineNumber')
70+
t.true(actualMethodDescriptor.apiDescriptor, 'Router.post', 'apiDescriptor')
71+
t.equal(actualMethodDescriptor.className, 'Router', 'className')
7972
t.equal(actualMethodDescriptor.methodName, 'post', 'methodName')
80-
t.true(actualMethodDescriptor.location.endsWith('express.test.js'), 'location')
8173
})
8274
})
8375

8476
app.get('/express2', async (req, res) => {
8577
res.send('ok get')
8678

8779
agent.callbackTraceClose((trace) => {
88-
let actualBuilder = new MethodDescriptorBuilder(expected('get', 'app.get'))
89-
.setClassName(expected('app', 'Function'))
90-
.setLineNumber(84)
91-
.setFileName('express.test.js')
80+
let actualBuilder = new MethodDescriptorBuilder('get')
81+
.setClassName('Router')
9282
const actualMethodDescriptor = apiMetaService.cacheApiWithBuilder(actualBuilder)
9383
let spanEvent = trace.spanBuilder.spanEventList[0]
9484
t.equal(actualMethodDescriptor.apiId, spanEvent.apiId, 'apiId')
95-
t.true(actualMethodDescriptor.apiDescriptor.startsWith(expected('app.get', 'Function.app.get')), 'apiDescriptor')
96-
t.equal(actualMethodDescriptor.className, expected('app', 'Function'), 'className')
97-
t.equal(actualMethodDescriptor.lineNumber, 84, 'lineNumber')
85+
t.true(actualMethodDescriptor.apiDescriptor, 'Router.get', 'apiDescriptor')
86+
t.equal(actualMethodDescriptor.className, 'Router', 'className')
9887
t.equal(actualMethodDescriptor.methodName, 'get', 'methodName')
99-
t.true(actualMethodDescriptor.location.endsWith('express.test.js'), 'location')
10088
})
10189
})
10290

@@ -167,71 +155,55 @@ function throwHandleTest(trace, t) {
167155
t.equal(trace.spanBuilder.annotations[0].key, annotationKey.HTTP_STATUS_CODE.getCode(), '/express3 HTTP_STATUS_CODE annotationKey matching')
168156
t.equal(trace.spanBuilder.annotations[0].value, 500, '/express3 HTTP_STATUS_CODE value matching')
169157

170-
let actualBuilder = new MethodDescriptorBuilder(expected('get', 'app.get'))
171-
.setClassName(expected('app', 'Function'))
172-
.setLineNumber(107)
173-
.setFileName('express.test.js')
158+
let actualBuilder = new MethodDescriptorBuilder('get')
159+
.setClassName('Router')
174160
const actualMethodDescriptor = apiMetaService.cacheApiWithBuilder(actualBuilder)
175161
let spanEvent = trace.spanBuilder.spanEventList[0]
176162
t.equal(actualMethodDescriptor.apiId, spanEvent.apiId, 'apiId')
177-
t.true(actualMethodDescriptor.apiDescriptor.startsWith(expected('app.get', 'Function.app.get')), 'apiDescriptor')
178-
t.equal(actualMethodDescriptor.className, expected('app', 'Function'), 'className')
179-
t.equal(actualMethodDescriptor.lineNumber, 107, 'lineNumber')
163+
t.true(actualMethodDescriptor.apiDescriptor.startsWith('Router.get'), 'apiDescriptor')
164+
t.equal(actualMethodDescriptor.className, 'Router', 'className')
180165
t.equal(actualMethodDescriptor.methodName, 'get', 'methodName')
181-
t.true(actualMethodDescriptor.location.endsWith('express.test.js'), 'location')
182166
t.equal(spanEvent.sequence, 0, 'sequence')
183167
t.equal(spanEvent.depth, 1, 'spanEvent.depth')
184168

185169
actualBuilder = new MethodDescriptorBuilder('use')
186170
.setClassName('Router')
187-
.setLineNumber(120)
188-
.setFileName('express.test.js')
189171
const actualErrorMethodDescriptor = apiMetaService.cacheApiWithBuilder(actualBuilder)
190172
spanEvent = trace.spanBuilder.spanEventList[1]
191173
t.equal(actualErrorMethodDescriptor.apiId, spanEvent.apiId, 'apiId')
192-
t.true(actualErrorMethodDescriptor.apiDescriptor.startsWith('Router.use'), 'apiDescriptor')
174+
t.true(actualErrorMethodDescriptor.apiDescriptor, 'Router.use', 'apiDescriptor')
193175
t.equal(actualErrorMethodDescriptor.className, 'Router', 'className')
194-
t.equal(actualErrorMethodDescriptor.lineNumber, 120, 'lineNumber')
195176
t.equal(actualErrorMethodDescriptor.methodName, 'use', 'methodName')
196-
t.true(actualErrorMethodDescriptor.location.endsWith('express.test.js'), 'location')
197177
t.equal(spanEvent.sequence, 1, 'sequence')
198178
t.equal(spanEvent.depth, 2, 'spanEvent.depth')
199179
t.equal(spanEvent.exceptionInfo.intValue, 1, 'error value')
200-
t.true(spanEvent.exceptionInfo.stringValue.endsWith('express.test.js:110:11'), 'error case')
180+
t.true(spanEvent.exceptionInfo.stringValue.endsWith('express.test.js:98:11'), 'error case')
201181
}
202182

203183
function nextErrorHandleTest(trace, t) {
204-
let actualBuilder = new MethodDescriptorBuilder(expected('get', 'app.get'))
205-
.setClassName(expected('app', 'Function'))
206-
.setLineNumber(114)
207-
.setFileName('express.test.js')
184+
let actualBuilder = new MethodDescriptorBuilder('get')
185+
.setClassName('Router')
208186
const actualMethodDescriptor = apiMetaService.cacheApiWithBuilder(actualBuilder)
209187
let spanEvent = trace.spanBuilder.spanEventList[0]
210188
t.equal(actualMethodDescriptor.apiId, spanEvent.apiId, 'apiId')
211-
t.true(actualMethodDescriptor.apiDescriptor.startsWith(expected('app.get', 'Function.app.get')), 'apiDescriptor')
212-
t.equal(actualMethodDescriptor.className, expected('app', 'Function'), 'className')
213-
t.equal(actualMethodDescriptor.lineNumber, 114, 'lineNumber')
189+
t.true(actualMethodDescriptor.apiDescriptor, 'Router.get', 'apiDescriptor')
190+
t.equal(actualMethodDescriptor.className, 'Router', 'className')
214191
t.equal(actualMethodDescriptor.methodName, 'get', 'methodName')
215-
t.true(actualMethodDescriptor.location.endsWith('express.test.js'), 'location')
216192
t.equal(spanEvent.sequence, 0, 'sequence')
217193
t.equal(spanEvent.depth, 1, 'spanEvent.depth')
218194

219195
actualBuilder = new MethodDescriptorBuilder('use')
220196
.setClassName('Router')
221-
.setLineNumber(120)
222-
.setFileName('express.test.js')
223197
const actualErrorMethodDescriptor = apiMetaService.cacheApiWithBuilder(actualBuilder)
224198
spanEvent = trace.spanBuilder.spanEventList[1]
225199
t.equal(actualErrorMethodDescriptor.apiId, spanEvent.apiId, 'apiId')
226200
t.true(actualErrorMethodDescriptor.apiDescriptor.startsWith('Router.use'), 'apiDescriptor')
227201
t.equal(actualErrorMethodDescriptor.className, 'Router', 'className')
228-
t.equal(actualErrorMethodDescriptor.lineNumber, 120, 'lineNumber')
229202
t.equal(actualErrorMethodDescriptor.methodName, 'use', 'methodName')
230-
t.true(actualErrorMethodDescriptor.location.endsWith('express.test.js'), 'location')
231203
t.equal(spanEvent.sequence, 1, 'sequence')
232204
t.equal(spanEvent.depth, 2, 'spanEvent.depth')
233205
t.equal(spanEvent.exceptionInfo.intValue, 1, 'error value')
234-
t.true(spanEvent.exceptionInfo.stringValue.endsWith('express.test.js:117:10'), 'error case')
206+
t.true(spanEvent.exceptionInfo.stringValue.endsWith('express.test.js:105:10'), 'error case')
235207
}
236208

237209
const testName2 = 'express2'
@@ -341,7 +313,7 @@ test(`${testName4} Should record internal error in express.test.js`, function (t
341313

342314
const testName5 = 'express5'
343315
test(`${testName5} Should record middleware`, function (t) {
344-
agent.bindHttpWithCallSite()
316+
agent.bindHttp()
345317

346318
const testName = testName5
347319

@@ -365,48 +337,36 @@ test(`${testName5} Should record middleware`, function (t) {
365337

366338
app.get(PATH, (req, res) => {
367339
agent.callbackTraceClose((trace) => {
368-
let actualBuilder = new MethodDescriptorBuilder(expected('get', 'app.get'))
369-
.setClassName(expected('app', 'Function'))
370-
.setLineNumber(366)
371-
.setFileName('express.test.js')
340+
let actualBuilder = new MethodDescriptorBuilder('get')
341+
.setClassName('Router')
372342
const actualMethodDescriptor = apiMetaService.cacheApiWithBuilder(actualBuilder)
373343
let spanEvent = trace.spanBuilder.spanEventList[2]
374344
t.equal(actualMethodDescriptor.apiId, spanEvent.apiId, 'apiId')
375-
t.true(actualMethodDescriptor.apiDescriptor.startsWith(expected('app.get', 'Function.app.get')), 'apiDescriptor')
376-
t.equal(actualMethodDescriptor.className, expected('app', 'Function'), 'className')
377-
t.equal(actualMethodDescriptor.lineNumber, 366, 'lineNumber')
345+
t.true(actualMethodDescriptor.apiDescriptor, 'Router.get', 'apiDescriptor')
346+
t.equal(actualMethodDescriptor.className, 'Router', 'className')
378347
t.equal(actualMethodDescriptor.methodName, 'get', 'methodName')
379-
t.true(actualMethodDescriptor.location.endsWith('express.test.js'), 'location')
380348
t.equal(spanEvent.sequence, 2, 'sequence')
381349
t.equal(spanEvent.depth, 1, 'spanEvent.depth')
382350

383351
actualBuilder = new MethodDescriptorBuilder('use')
384352
.setClassName('Router')
385-
.setLineNumber(356)
386-
.setFileName('express.test.js')
387353
const actualMiddleware1MethodDescriptor = apiMetaService.cacheApiWithBuilder(actualBuilder)
388354
spanEvent = trace.spanBuilder.spanEventList[1]
389355
t.equal(actualMiddleware1MethodDescriptor.apiId, spanEvent.apiId, 'apiId')
390-
t.true(actualMiddleware1MethodDescriptor.apiDescriptor.startsWith('Router.use'), 'apiDescriptor')
356+
t.true(actualMiddleware1MethodDescriptor.apiDescriptor, 'Router.use', 'apiDescriptor')
391357
t.equal(actualMiddleware1MethodDescriptor.className, 'Router', 'className')
392-
t.equal(actualMiddleware1MethodDescriptor.lineNumber, 356, 'lineNumber')
393358
t.equal(actualMiddleware1MethodDescriptor.functionName, 'use', 'functionName')
394-
t.true(actualMiddleware1MethodDescriptor.location.endsWith('express.test.js'), 'location')
395359
t.equal(spanEvent.sequence, 1, 'sequence')
396360
t.equal(spanEvent.depth, 1, 'spanEvent.depth')
397361

398362
actualBuilder = new MethodDescriptorBuilder('use')
399363
.setClassName('Router')
400-
.setLineNumber(351)
401-
.setFileName('express.test.js')
402364
const actualMiddleware2MethodDescriptor = apiMetaService.cacheApiWithBuilder(actualBuilder)
403365
spanEvent = trace.spanBuilder.spanEventList[0]
404366
t.equal(actualMiddleware2MethodDescriptor.apiId, spanEvent.apiId, 'apiId')
405-
t.true(actualMiddleware2MethodDescriptor.apiDescriptor.startsWith('Router.use'), 'apiDescriptor')
367+
t.true(actualMiddleware2MethodDescriptor.apiDescriptor, 'Router.use', 'apiDescriptor')
406368
t.equal(actualMiddleware2MethodDescriptor.className, 'Router', 'className')
407-
t.equal(actualMiddleware2MethodDescriptor.lineNumber, 351, 'lineNumber')
408369
t.equal(actualMiddleware2MethodDescriptor.methodName, 'use', 'methodName')
409-
t.true(actualMiddleware2MethodDescriptor.location.endsWith('express.test.js'), 'location')
410370
t.equal(spanEvent.sequence, 0, 'sequence')
411371
t.equal(spanEvent.depth, 1, 'spanEvent.depth')
412372
})
@@ -639,7 +599,7 @@ function throwHandleTestWithoutCallSite(trace, t) {
639599
t.equal(spanEvent.sequence, 1, 'sequence')
640600
t.equal(spanEvent.depth, 2, 'spanEvent.depth')
641601
t.equal(spanEvent.exceptionInfo.intValue, 1, 'error value')
642-
t.true(spanEvent.exceptionInfo.stringValue.endsWith('express.test.js:560:11'), 'error case')
602+
t.true(spanEvent.exceptionInfo.stringValue.endsWith('express.test.js:520:11'), 'error case')
643603
}
644604

645605
function nextErrorHandleTestWithoutCallSite(trace, t) {
@@ -665,7 +625,7 @@ function nextErrorHandleTestWithoutCallSite(trace, t) {
665625
t.equal(spanEvent.sequence, 1, 'sequence')
666626
t.equal(spanEvent.depth, 2, 'spanEvent.depth')
667627
t.equal(spanEvent.exceptionInfo.intValue, 1, 'error value')
668-
t.true(spanEvent.exceptionInfo.stringValue.endsWith('express.test.js:567:10'), 'error case')
628+
t.true(spanEvent.exceptionInfo.stringValue.endsWith('express.test.js:527:10'), 'error case')
669629
}
670630

671631
test('incoming request by Disable Trace requests', (t) => {

0 commit comments

Comments
 (0)