Skip to content

Commit 4932f78

Browse files
committed
feat(trace): add stop callback
1 parent 6216023 commit 4932f78

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

lib/trace.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ var traceNoop = {
1010
sendMemorySnapshot: function () {},
1111
recordMetric: function () {},
1212
incrementMetric: function () {},
13-
stop: function () {}
13+
stop: function (cb) {
14+
if (typeof cb === 'function') {
15+
cb()
16+
}
17+
}
1418
}
1519

1620
function Trace (config) {
@@ -63,8 +67,11 @@ Trace.prototype.recordMetric = function (name, value) {
6367
this._agent.customMetrics.record(name, value)
6468
}
6569

66-
Trace.prototype.stop = function () {
70+
Trace.prototype.stop = function (cb) {
6771
this._agent._stopAll()
72+
if (typeof cb === 'function') {
73+
cb()
74+
}
6875
}
6976

7077
module.exports.Trace = Trace

test/e2e/initialization.spec.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,27 @@ test('should get service key',
7575
})
7676
require('@risingstack/trace')
7777
})
78+
79+
test('should stop', {
80+
isolate: 'child-process',
81+
childProcessOpts: {
82+
env: {
83+
TRACE_API_KEY: TRACE_API_KEY,
84+
TRACE_SERVICE_NAME: TRACE_SERVICE_NAME,
85+
TRACE_COLLECT_INTERVAL: 100
86+
}
87+
}
88+
}, function (t) {
89+
t.plan(1)
90+
serviceMocks.mockServiceKeyRequest({
91+
url: TRACE_COLLECTOR_API_URL,
92+
apiKey: TRACE_API_KEY,
93+
callback: function (uri, requestBody) {
94+
}
95+
})
96+
var trace = require('@risingstack/trace')
97+
trace.stop(function (err) {
98+
t.notOk(err, 'no error')
99+
t.end()
100+
})
101+
})

0 commit comments

Comments
 (0)