Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

zipkin

Package Overview
Dependencies
Maintainers
1
Versions
59
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

zipkin - npm Package Compare versions

Comparing version 0.1.9 to 0.2.0

src/batch-recorder.js

24

index.js

@@ -0,14 +1,19 @@

const option = require('./src/option');
const Annotation = require('./src/annotation');
const TraceId = require('./src/TraceId');
const Tracer = require('./src/tracer');
const TraceId = require('./src/tracer/TraceId');
const sampler = require('./src/tracer/sampler');
const HttpHeaders = require('./src/httpHeaders');
const InetAddress = require('./src/InetAddress');
const option = require('./src/option');
const ZipkinTracer = require('./src/ZipkinTracer');
const consoleTracer = require('./src/consoleTracer');
const trace = require('./src/trace');
const BatchRecorder = require('./src/batch-recorder');
const ConsoleRecorder = require('./src/console-recorder');
const serializeSpan = require('./src/serializeSpan');
const sampler = require('./src/sampler');
const ExplicitContext = require('./src/explicit-context');
module.exports = {
trace,
Tracer,
TraceId,

@@ -19,6 +24,7 @@ option,

HttpHeaders,
ZipkinTracer,
consoleTracer,
BatchRecorder,
ConsoleRecorder,
serializeSpan,
ExplicitContext,
sampler
};
{
"name": "zipkin",
"version": "0.1.9",
"version": "0.2.0",
"description": "The core tracer for zipkin.js",

@@ -10,3 +10,3 @@ "main": "index.js",

},
"author": "Openzipkin <openzipkin.alt@gmail.com>",
"author": "OpenZipkin <openzipkin.alt@gmail.com>",
"license": "Apache-2.0",

@@ -16,3 +16,2 @@ "repository": "https://github.com/openzipkin/zipkin-js",

"base64-js": "^1.1.2",
"continuation-local-storage": "^3.1.7",
"network-address": "^1.1.0",

@@ -19,0 +18,0 @@ "thrift": "^0.9.3"

const None = {
type: 'None',
map: function map() {
get type() {
return 'None';
},
map() {
return None;
},
ifPresent: function ifPresent() {},
flatMap: function flatMap() {
ifPresent() {},
flatMap() {
return None;
},
getOrElse: function getOrElse(f) {
getOrElse(f) {
if (f instanceof Function) {

@@ -17,10 +19,14 @@ return f();

},
equals: function equals(other) {
equals(other) {
return other.type === 'None';
},
toString: function toString() {
toString() {
return 'None';
},
get present() {
return false;
}
};
class Some {

@@ -48,4 +54,9 @@ constructor(value) {

}
get present() {
return true;
}
get type() {
return 'Some';
}
}
Some.prototype.type = 'Some';

@@ -52,0 +63,0 @@ // Used to validate input arguments

@@ -1,2 +0,2 @@

const randomTraceId = require('../src/randomTraceId');
const randomTraceId = require('../src/tracer/randomTraceId');

@@ -3,0 +3,0 @@ describe('random trace id', () => {

@@ -1,8 +0,10 @@

const {MutableSpan} = require('../src/internalRepresentations');
const TraceId = require('../src/TraceId');
const {Sampler, CountingSampler} = require('../src/sampler');
const TraceId = require('../src/tracer/TraceId');
const {Sampler, CountingSampler} = require('../src/tracer/sampler');
const {Some, None} = require('../src/option');
function makeTestSpan({flags = 0, sampled = None}) {
return new MutableSpan(new TraceId({
const T = new Some(true);
const F = new Some(false);
function makeTestTraceId({flags = 0, sampled = None}) {
return new TraceId({
traceId: new Some('abc'),

@@ -13,3 +15,3 @@ parentId: new Some('123'),

flags
}));
});
}

@@ -21,12 +23,19 @@

const sampler = new Sampler(neverSample);
expect(sampler.shouldSample(makeTestSpan({flags: 1}))).to.equal(true);
expect(
sampler.shouldSample(makeTestTraceId({flags: 1}))
).to.eql(T);
});
it('should respect the "sampled" property', () => {
it('should respect the "sampled" property when true', () => {
const neverSample = () => false;
const sampler = new Sampler(neverSample());
expect(sampler.shouldSample(makeTestSpan({sampled: new Some(true)}))).to.equal(true);
expect(
sampler.shouldSample(makeTestTraceId({sampled: T}))
).to.eql(T);
});
it('should respect the "sampled" property when false', () => {
const alwaysSample = () => true;
const sampler2 = new Sampler(alwaysSample());
expect(sampler2.shouldSample(makeTestSpan({sampled: new Some(false)}))).to.equal(false);
expect(
sampler2.shouldSample(makeTestTraceId({sampled: F}))
).to.eql(F);
});

@@ -48,6 +57,6 @@ });

const sampler = new CountingSampler(0.25);
const s = () => sampler.shouldSample(makeTestSpan({}));
const s = () => sampler.shouldSample(makeTestTraceId({}));
const sampled = [s(), s(), s(), s(), s(), s(), s(), s(), s()];
const expected = [true, false, false, false, true, false, false, false, true];
const expected = [T, F, F, F, T, F, F, F, T];

@@ -59,6 +68,6 @@ expect(sampled).to.deep.equal(expected);

const sampler = new CountingSampler(0.5);
const s = () => sampler.shouldSample(makeTestSpan({}));
const s = () => sampler.shouldSample(makeTestTraceId({}));
const sampled = [s(), s(), s(), s(), s(), s(), s(), s(), s()];
const expected = [true, false, true, false, true, false, true, false, true];
const expected = [T, F, T, F, T, F, T, F, T];

@@ -70,6 +79,6 @@ expect(sampled).to.deep.equal(expected);

const sampler = new CountingSampler(0);
const s = () => sampler.shouldSample(makeTestSpan({}));
const s = () => sampler.shouldSample(makeTestTraceId({}));
const sampled = [s(), s(), s(), s(), s(), s(), s(), s(), s()];
const expected = [false, false, false, false, false, false, false, false, false];
const expected = [F, F, F, F, F, F, F, F, F];

@@ -76,0 +85,0 @@ expect(sampled).to.deep.equal(expected);

@@ -1,2 +0,2 @@

const TraceId = require('../src/TraceId');
const TraceId = require('../src/tracer/TraceId');
const serializeSpan = require('../src/serializeSpan');

@@ -3,0 +3,0 @@ const {

@@ -1,22 +0,34 @@

const trace = require('../src/trace');
describe('trace', () => {
const sinon = require('sinon');
const Tracer = require('../src/tracer');
const {Sampler} = require('../src/tracer/sampler');
const ExplicitContext = require('../src/explicit-context');
const {Some} = require('../src/option');
describe('Tracer', () => {
it('should make parent and child spans', () => {
trace.withContext(() => {
trace.setId(trace.cleanId());
const parentId = trace.nextId();
trace.setId(parentId);
const recorder = {
record: () => {}
};
const ctxImpl = new ExplicitContext();
const tracer = new Tracer({ctxImpl, recorder});
trace.withContext(() => {
const childId = trace.nextId();
trace.setId(childId);
ctxImpl.scoped(() => {
tracer.setId(tracer.createRootId());
const parentId = tracer.createChildId();
tracer.setId(parentId);
expect(trace.id().traceId).to.equal(parentId.traceId);
expect(trace.id().parentId).to.equal(parentId.spanId);
ctxImpl.scoped(() => {
const childId = tracer.createChildId();
tracer.setId(childId);
trace.withContext(() => {
const grandchildId = trace.nextId();
trace.setId(grandchildId);
expect(tracer.id.traceId).to.equal(parentId.traceId);
expect(tracer.id.parentId).to.equal(parentId.spanId);
expect(trace.id().traceId).to.equal(childId.traceId);
expect(trace.id().parentId).to.equal(childId.spanId);
ctxImpl.scoped(() => {
const grandChildId = tracer.createChildId();
tracer.setId(grandChildId);
expect(tracer.id.traceId).to.equal(childId.traceId);
expect(tracer.id.parentId).to.equal(childId.spanId);
});

@@ -26,2 +38,28 @@ });

});
function runTest(bool, done) {
const recorder = {
record: sinon.spy()
};
const ctxImpl = new ExplicitContext();
const sampler = new Sampler(() => bool);
const tracer = new Tracer({
sampler,
recorder,
ctxImpl
});
ctxImpl.scoped(() => {
const rootTracerId = tracer.createRootId();
expect(rootTracerId.sampled).to.eql(new Some(bool));
done();
});
}
it('should set sampled flag when shouldSample is true', done => {
runTest(true, done);
});
it('should set sampled flag when shouldSample is false', done => {
runTest(false, done);
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc