forked from signalfx/signalfx-nodejs-tracing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcore.js
98 lines (90 loc) · 2.23 KB
/
core.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
'use strict'
const benchmark = require('./benchmark')
const proxyquire = require('proxyquire')
const Uint64BE = require('int64-buffer').Uint64BE
const platform = require('../src/platform')
const node = require('../src/platform/node')
platform.use(node)
const Config = require('../src/config')
const SignalFxTracer = require('../src/tracer')
const SignalFxSpanContext = require('../src/opentracing/span_context')
const TextMapPropagator = require('../src/opentracing/propagation/text_map')
const Writer = proxyquire('../src/writer', {
'./platform': { request: () => Promise.resolve() }
})
const Sampler = require('../src/sampler')
const format = require('../src/format')
const encode = require('../src/encode')
const config = new Config('benchmark', { service: 'benchmark' })
const suite = benchmark('core')
let tracer
let spanContext
let propagator
let carrier
let writer
let sampler
const traceStub = require('./stubs/trace')
const spanStub = require('./stubs/span')
suite
.add('SignalFxTracer#startSpan', {
onStart () {
tracer = new SignalFxTracer(config)
},
fn () {
tracer.startSpan()
}
})
.add('TextMapPropagator#inject', {
onStart () {
propagator = new TextMapPropagator()
carrier = {}
spanContext = new SignalFxSpanContext({
traceId: new Uint64BE(0x12345678, 0x12345678),
spanId: new Uint64BE(0x12345678, 0x12345678),
baggageItems: { foo: 'bar' }
})
},
fn () {
propagator.inject(spanContext, carrier)
}
})
.add('TextMapPropagator#extract', {
onStart () {
propagator = new TextMapPropagator()
carrier = {
'x-datadog-trace-id': '1234567891234567',
'x-datadog-parent-id': '1234567891234567',
'ot-baggage-foo': 'bar'
}
},
fn () {
propagator.extract(carrier)
}
})
.add('Writer#append', {
onStart () {
writer = new Writer({ sample: () => {} }, {})
},
fn () {
writer.append(spanStub)
}
})
.add('Sampler#isSampled', {
onStart () {
sampler = new Sampler(0.5)
},
fn () {
sampler.isSampled()
}
})
.add('format', {
fn () {
format(spanStub)
}
})
.add('encode', {
fn () {
encode(traceStub)
}
})
suite.run()