@uyu423/pinpoint-node-agent
Version:
Pinpoint node agent provided by NAVER (Personalized version)
41 lines (33 loc) • 941 B
JavaScript
/**
* Pinpoint Node.js Agent
* Copyright 2020-present NAVER Corp.
* Apache License v2.0
*/
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