Skip to content

Commit 30651f9

Browse files
committed
[#389] Support Exception Chain Metadata (PExceptionMetaData)
1 parent d7a9db6 commit 30651f9

File tree

8 files changed

+89
-4
lines changed

8 files changed

+89
-4
lines changed

lib/context/trace/call-stack.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
'use strict'
88

99
const SpanEventBuilder = require('./span-event-builder')
10-
const SpanEventRecorder = require('./span-event-recorder2')
10+
const SpanEventRecorder = require('./span-event-recorder')
1111

1212
/**
1313
* DefaultCallStack.java in Java agent
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**
2+
* Pinpoint Node.js Agent
3+
* Copyright 2020-present NAVER Corp.
4+
* Apache License v2.0
5+
*/
6+
7+
'use strict'
8+
9+
const { nextExceptionId } = require('./id-generator')
10+
11+
class Exception {
12+
constructor(className, message, startTime) {
13+
this.className = className
14+
this.message = message
15+
this.startTime = startTime
16+
this.exceptionId = nextExceptionId()
17+
this.exceptionDepth = 1
18+
this.frameStack = []
19+
}
20+
}
21+
22+
class ExceptionBuilder {
23+
constructor(error) {
24+
this.error = error
25+
}
26+
27+
build() {
28+
return new Exception(
29+
this.error.name || 'Error',
30+
this.error.message || '',
31+
Date.now()
32+
)
33+
}
34+
}
35+
36+
module.exports = {
37+
Exception,
38+
ExceptionBuilder
39+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* Pinpoint Node.js Agent
3+
* Copyright 2020-present NAVER Corp.
4+
* Apache License v2.0
5+
*/
6+
7+
'use strict'
8+
9+
class Exceptions {
10+
constructor(traceRoot, span, exceptions) {
11+
this.traceRoot = traceRoot
12+
this.span = span
13+
this.exceptions = exceptions
14+
}
15+
}
16+
17+
class ExceptionsBuilder {
18+
constructor(traceRoot) {
19+
this.traceRoot = traceRoot
20+
this.exceptions = []
21+
}
22+
23+
setSpan(span) {
24+
this.span = span
25+
return this
26+
}
27+
28+
addException(exception) {
29+
this.exceptions.push(exception)
30+
return this
31+
}
32+
33+
build() {
34+
return new Exceptions(this.traceRoot, this.span, this.exceptions)
35+
}
36+
}
37+
38+
module.exports = {
39+
Exceptions,
40+
ExceptionsBuilder
41+
}

lib/context/trace/id-generator.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ const continuedTransactionId = new LongIdGenerator(-1001)
1616
const disabledId = new LongIdGenerator(-1002)
1717
// INITIAL_CONTINUED_DISABLED_ID in AtomicIdGenerator.java
1818
const continueDisabledId = new LongIdGenerator(-1003)
19+
// INITIAL_EXCEPTION_ID
20+
const exceptionId = new LongIdGenerator(1)
1921

2022
module.exports = {
2123
nextTransactionId: function () {
@@ -41,5 +43,8 @@ module.exports = {
4143
},
4244
getContinuedDisabledId: function () {
4345
return continueDisabledId
46+
},
47+
nextExceptionId: function () {
48+
return exceptionId.next(1)
4449
}
4550
}

lib/context/trace/trace.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
'use strict'
88

9-
const SpanEventRecorder = require('./span-event-recorder2')
9+
const SpanEventRecorder = require('./span-event-recorder')
1010
const SpanRecorder = require('./span-recorder')
1111
const CallStack = require('./call-stack')
1212
const StackId = require('./stack-id')

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pinpoint-node-agent",
3-
"version": "1.3.0",
3+
"version": "1.4.0",
44
"type": "commonjs",
55
"main": "./index.js",
66
"types": "./index.d.ts",

test/agent.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ test('Should initialize agent', function (t) {
1111

1212
const agent = require('./support/agent-singleton-mock')
1313
t.ok(agent)
14-
t.equal(agent.agentInfo.agentVersion, '1.3.0', 'agent version from package.json')
14+
t.equal(agent.agentInfo.agentVersion, '1.4.0', 'agent version from package.json')
1515
})

0 commit comments

Comments
 (0)