forked from pinpoint-apm/pinpoint-node-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransaction-id.js
40 lines (33 loc) · 941 Bytes
/
transaction-id.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/**
* Pinpoint Node.js Agent
* Copyright 2020-present NAVER Corp.
* Apache License v2.0
*/
'use strict'
const transactionIdGenerator = require('./sequence-generator').transactionIdGenerator
const DELIMETER = '^'
class TransactionId {
constructor (agentId, agentStartTime, sequence) {
// agnetId + agentStartTime + sequenceNumber
this.agentId = agentId
this.agentStartTime = agentStartTime
if (sequence === null || sequence === undefined) {
this.sequence = "" + transactionIdGenerator.next + ""
} else {
this.sequence = sequence
}
}
toString () {
return [this.agentId, this.agentStartTime, this.sequence].join(DELIMETER)
}
static toTransactionId(str) {
if (str !== null && str !== undefined) {
const r = str.split(DELIMETER)
if (r.length === 3) {
return new TransactionId(r[0], r[1], r[2])
}
}
return null
}
}
module.exports = TransactionId