-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransaction_tracer.js
51 lines (46 loc) · 1.15 KB
/
transaction_tracer.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
41
42
43
44
45
46
47
48
49
50
51
"use strict";
var SeqId = require("seqid")
var EENano = require("eenano")
module.exports = (function getTracer() {
if (global.transactionTracer) {
return global.transactionTracer
}
global.transactionTracer = new Tracer()
return global.transactionTracer
})()
function Tracer() {
if (!(this instanceof Tracer)) {
return new Tracer()
}
this.idgen = new SeqId()
this.ee = new EENano()
}
Tracer.prototype.start = function (metadata) {
var id = this.idgen.next()
this.ee.emit("start", new TraceMessage(id, metadata))
return id
}
Tracer.prototype.continue = function (id, metadata) {
this.ee.emit("continue", new TraceMessage(id, metadata))
return id
}
Tracer.prototype.end = function (id, metadata) {
this.ee.emit("end", new TraceMessage(id, metadata))
return id
}
Tracer.prototype.onStart = function (handler) {
this.ee.on("start", handler)
return this
}
Tracer.prototype.onContinue = function (handler) {
this.ee.on("continue", handler)
return this
}
Tracer.prototype.onEnd = function (handler) {
this.ee.on("end", handler)
return this
}
function TraceMessage(id, metadata) {
this.id = id
this.metadata = metadata || null
}