Skip to content

Commit 7de0630

Browse files
committed
[#389] Support Exception Chain Metadata (PExceptionMetaData)
1 parent 738df48 commit 7de0630

File tree

3 files changed

+85
-0
lines changed

3 files changed

+85
-0
lines changed
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
}

0 commit comments

Comments
 (0)