-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
45 lines (39 loc) · 943 Bytes
/
index.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
"use strict";
const opentelemetry = require('@opentelemetry/api');
class TraceBridge {
constructor() {
this.spans_ = {};
this.tracer_ = opentelemetry.trace.getTracer("mirakc")
}
process(trace, trans) {
if (!trace.sc) {
return;
}
if (!(trace.sc.id in this.spans_)) {
let opts = {
attributes: trace.sc.kv,
startTime: trace.ts,
};
if (trace.sc.pi in this.spans_) {
opts.parent = this.spans_[trace.sc.pi];
}
this.spans_[trace.sc.id] = this.tracer_.startSpan(trace.sc.nm, opts);
}
const span = this.spans_[trace.sc.id];
switch (trace.nm) {
case 'start':
break;
case 'end':
span.end(trace.ts);
delete this.spans_[trace.sc.id];
break;
default:
if (trans) {
trace = trans(trace);
}
span.addEvent(trace.nm, trace.kv, trace.ts)
break;
}
}
}
module.exports = { TraceBridge };