Skip to content

Commit 5e09f87

Browse files
koenpuntDanielMSchmidt
authored andcommitted
fix: pass sampler to Tracer instead of SpanCreator
* pass sampler to Tracer instead of SpanCreator the SpanCreator doesn't accept a sampler property, and thus specifying a sampler had no effect * update Changelog
1 parent ee2b64e commit 5e09f87

4 files changed

Lines changed: 14 additions & 8 deletions

File tree

Changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## NEXT
4+
5+
* Fix sampler option. [#87](https://github.com/DanielMSchmidt/zipkin-javascript-opentracing/pull/87)
6+
37
## 2.0.0
48

59
* [Change carrier formats to be openzipkin ones](https://github.com/DanielMSchmidt/zipkin-javascript-opentracing/pull/72)

__mocks__/zipkin.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ module.exports = {
124124
},
125125
option: require("zipkin-option"),
126126
sampler: {
127-
alwaysSampler: jest.fn(() => true)
127+
alwaysSample: jest.fn(() => true),
128+
Sampler: jest.fn()
128129
},
129130
jsonEncoder: {
130131
JSON_V1: jest.fn()

src/__tests__/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const opentracing = require("opentracing");
22
const Tracer = require("../index");
33
const zipkin = require("zipkin");
44
const {
5-
option: { Some, None }
5+
sampler: { Sampler }
66
} = zipkin;
77

88
describe("Opentracing interface", () => {
@@ -494,7 +494,8 @@ describe("Opentracing interface", () => {
494494

495495
expect(zipkin.Tracer).toHaveBeenCalledWith({
496496
ctxImpl: {},
497-
recorder: { id: 42 }
497+
recorder: { id: 42 },
498+
sampler: expect.any(Sampler)
498499
});
499500
});
500501
});

src/index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ const {
22
Annotation,
33
BatchRecorder,
44
ExplicitContext,
5-
Request,
65
TraceId,
76
option: { Some, None },
87
Tracer,
@@ -219,19 +218,20 @@ class Tracing {
219218
);
220219
}
221220

222-
options.sampler = options.sampler || sampler.alwaysSample;
221+
options.sampler =
222+
options.sampler || new sampler.Sampler(sampler.alwaysSample);
223223

224224
this._serviceName = options.serviceName;
225225

226226
this._zipkinTracer = new Tracer({
227227
ctxImpl: new ExplicitContext(),
228-
recorder: options.recorder
228+
recorder: options.recorder,
229+
sampler: options.sampler
229230
});
230231
this._Span = SpanCreator({
231232
tracer: this._zipkinTracer,
232233
serviceName: this._serviceName,
233-
kind: options.kind,
234-
sampler: options.sampler
234+
kind: options.kind
235235
});
236236
}
237237

0 commit comments

Comments
 (0)