Comparing version 0.13.0 to 0.14.0
@@ -38,3 +38,3 @@ // TypeScript type definitions | ||
local<V>(name: string, callback: () => V): V; | ||
createRootId(): TraceId; | ||
createRootId(isSampled?: option.IOption, isDebug?: boolean): TraceId; | ||
createChildId(): TraceId; | ||
@@ -273,3 +273,3 @@ letId<V>(traceId: TraceId, callback: () => V): V; | ||
class ConsoleRecorder implements Recorder { | ||
constructor(args?: { logger?: Logger }); | ||
constructor(logger?: (message: string) => void); | ||
record: (rec: Record) => void; | ||
@@ -276,0 +276,0 @@ } |
@@ -24,2 +24,3 @@ 'use strict'; | ||
var jsonEncoder = require('./jsonEncoder'); | ||
var parseRequestUrl = require('./parseUrl'); | ||
@@ -41,3 +42,4 @@ module.exports = { | ||
model: model, | ||
jsonEncoder: jsonEncoder | ||
jsonEncoder: jsonEncoder, | ||
parseRequestUrl: parseRequestUrl | ||
}; |
@@ -9,2 +9,3 @@ 'use strict'; | ||
var Request = require('../request'); | ||
var parseRequestUrl = require('../parseUrl'); | ||
@@ -36,5 +37,8 @@ function requiredArg(name) { | ||
var _parseRequestUrl = parseRequestUrl(url), | ||
path = _parseRequestUrl.path; | ||
this.tracer.recordServiceName(this.serviceName); | ||
this.tracer.recordRpc(method.toUpperCase()); | ||
this.tracer.recordBinary('http.url', url); | ||
this.tracer.recordBinary('http.path', path); | ||
this.tracer.recordAnnotation(new Annotation.ClientSend()); | ||
@@ -41,0 +45,0 @@ if (this.remoteServiceName) { |
@@ -7,3 +7,7 @@ 'use strict'; | ||
var Annotation = require('../annotation'); | ||
var Header = require('../httpHeaders'); | ||
var InetAddress = require('../InetAddress'); | ||
var TraceId = require('../tracer/TraceId'); | ||
var parseRequestUrl = require('../parseUrl'); | ||
@@ -14,5 +18,2 @@ var _require = require('../option'), | ||
var TraceId = require('../tracer/TraceId'); | ||
var Annotation = require('../annotation'); | ||
function stringToBoolean(str) { | ||
@@ -44,2 +45,3 @@ return str === '1' || str === 'true'; | ||
serviceName = _ref$serviceName === undefined ? tracer.localEndpoint.serviceName : _ref$serviceName, | ||
host = _ref.host, | ||
_ref$port = _ref.port, | ||
@@ -52,2 +54,3 @@ port = _ref$port === undefined ? requiredArg('port') : _ref$port; | ||
this.serviceName = serviceName; | ||
this.host = host && new InetAddress(host); | ||
this.port = port; | ||
@@ -75,12 +78,6 @@ } | ||
} else { | ||
if (readHeader(Header.Flags) !== None) { | ||
var currentId = this.tracer.id; | ||
var idWithFlags = new TraceId({ | ||
traceId: currentId.traceId, | ||
parentId: currentId.parentId, | ||
spanId: currentId.spanId, | ||
sampled: currentId.sampled, | ||
flags: readHeader(Header.Flags) | ||
}); | ||
return new Some(idWithFlags); | ||
if (readHeader(Header.Flags) !== None || readHeader(Header.Sampled) !== None) { | ||
var sampled = readHeader(Header.Sampled) === None ? None : readHeader(Header.Sampled).map(stringToBoolean); | ||
var flags = readHeader(Header.Flags).flatMap(stringToIntOption).getOrElse(0); | ||
return new Some(this.tracer.createRootId(sampled, flags === 1)); | ||
} else { | ||
@@ -101,11 +98,11 @@ return new Some(this.tracer.createRootId()); | ||
var _parseRequestUrl = parseRequestUrl(requestUrl), | ||
path = _parseRequestUrl.path; | ||
this.tracer.recordServiceName(this.serviceName); | ||
this.tracer.recordRpc(method.toUpperCase()); | ||
this.tracer.recordBinary('http.url', requestUrl); | ||
this.tracer.recordBinary('http.path', path); | ||
this.tracer.recordAnnotation(new Annotation.ServerRecv()); | ||
this.tracer.recordAnnotation(new Annotation.LocalAddr({ port: this.port })); | ||
this.tracer.recordAnnotation(new Annotation.LocalAddr({ host: this.host, port: this.port })); | ||
if (id.flags !== 0 && id.flags != null) { | ||
this.tracer.recordBinary(Header.Flags, id.flags.toString()); | ||
} | ||
return id; | ||
@@ -112,0 +109,0 @@ } |
@@ -28,3 +28,3 @@ 'use strict'; | ||
this.timestamp = timestamp; | ||
this.value = value; | ||
this.value = value.toString(); | ||
} | ||
@@ -89,3 +89,3 @@ Annotation.prototype.toString = function toString() { | ||
Span.prototype.putTag = function putTag(key, value) { | ||
this.tags[key] = value; | ||
this.tags[key] = value.toString(); | ||
}; | ||
@@ -92,0 +92,0 @@ Span.prototype.setDebug = function setDebug(debug) { |
@@ -109,2 +109,8 @@ 'use strict'; | ||
function verifyIsNotOptional(data) { | ||
if (data != null && isOptional(data)) { | ||
throw new Error('Error: data (' + data + ') is an Option!'); | ||
} | ||
} | ||
function fromNullable(nullable) { | ||
@@ -121,2 +127,3 @@ if (nullable != null) { | ||
module.exports.verifyIsOptional = verifyIsOptional; | ||
module.exports.verifyIsNotOptional = verifyIsNotOptional; | ||
module.exports.fromNullable = fromNullable; |
@@ -78,2 +78,5 @@ 'use strict'; | ||
value: function createRootId() { | ||
var isSampled = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : None; | ||
var isDebug = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; | ||
var rootSpanId = randomTraceId(); | ||
@@ -85,6 +88,10 @@ var traceId = this.traceId128Bit ? new Some(randomTraceId() + rootSpanId) : None; | ||
spanId: rootSpanId, | ||
sampled: None, | ||
flags: 0 | ||
sampled: isSampled, | ||
flags: isDebug ? 1 : 0 | ||
}); | ||
id._sampled = this.sampler.shouldSample(id); | ||
if (isSampled === None) { | ||
id._sampled = this.sampler.shouldSample(id); | ||
} | ||
return id; | ||
@@ -186,4 +193,4 @@ } | ||
this.id.sampled.ifPresent(function (sampled) { | ||
// sampled present is different than sampled == true | ||
if (!sampled) return; | ||
_this2.recorder.record(new Record({ | ||
@@ -190,0 +197,0 @@ traceId: _this2.id, |
@@ -10,3 +10,4 @@ 'use strict'; | ||
None = _require.None, | ||
verifyIsOptional = _require.verifyIsOptional; | ||
verifyIsOptional = _require.verifyIsOptional, | ||
verifyIsNotOptional = _require.verifyIsNotOptional; | ||
@@ -29,2 +30,3 @@ var TraceId = function () { | ||
verifyIsOptional(parentId); | ||
verifyIsNotOptional(spanId); | ||
verifyIsOptional(sampled); | ||
@@ -31,0 +33,0 @@ this._traceId = traceId; |
{ | ||
"name": "zipkin", | ||
"version": "0.13.0", | ||
"version": "0.14.0", | ||
"description": "The core tracer for zipkin.js", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -22,2 +22,3 @@ const option = require('./option'); | ||
const jsonEncoder = require('./jsonEncoder'); | ||
const parseRequestUrl = require('./parseUrl'); | ||
@@ -39,3 +40,4 @@ module.exports = { | ||
model, | ||
jsonEncoder | ||
jsonEncoder, | ||
parseRequestUrl | ||
}; |
const Annotation = require('../annotation'); | ||
const Request = require('../request'); | ||
const parseRequestUrl = require('../parseUrl'); | ||
@@ -22,6 +23,7 @@ function requiredArg(name) { | ||
const traceId = this.tracer.id; | ||
const {path} = parseRequestUrl(url); | ||
this.tracer.recordServiceName(this.serviceName); | ||
this.tracer.recordRpc(method.toUpperCase()); | ||
this.tracer.recordBinary('http.url', url); | ||
this.tracer.recordBinary('http.path', path); | ||
this.tracer.recordAnnotation(new Annotation.ClientSend()); | ||
@@ -28,0 +30,0 @@ if (this.remoteServiceName) { |
@@ -0,5 +1,7 @@ | ||
const Annotation = require('../annotation'); | ||
const Header = require('../httpHeaders'); | ||
const InetAddress = require('../InetAddress'); | ||
const TraceId = require('../tracer/TraceId'); | ||
const parseRequestUrl = require('../parseUrl'); | ||
const {Some, None} = require('../option'); | ||
const TraceId = require('../tracer/TraceId'); | ||
const Annotation = require('../annotation'); | ||
@@ -30,6 +32,8 @@ function stringToBoolean(str) { | ||
serviceName = tracer.localEndpoint.serviceName, | ||
port = requiredArg('port') | ||
host, | ||
port = requiredArg('port'), | ||
}) { | ||
this.tracer = tracer; | ||
this.serviceName = serviceName; | ||
this.host = host && new InetAddress(host); | ||
this.port = port; | ||
@@ -55,12 +59,7 @@ } | ||
} else { | ||
if (readHeader(Header.Flags) !== None) { | ||
const currentId = this.tracer.id; | ||
const idWithFlags = new TraceId({ | ||
traceId: currentId.traceId, | ||
parentId: currentId.parentId, | ||
spanId: currentId.spanId, | ||
sampled: currentId.sampled, | ||
flags: readHeader(Header.Flags) | ||
}); | ||
return new Some(idWithFlags); | ||
if (readHeader(Header.Flags) !== None || readHeader(Header.Sampled) !== None) { | ||
const sampled = readHeader(Header.Sampled) === None ? | ||
None : readHeader(Header.Sampled).map(stringToBoolean); | ||
const flags = readHeader(Header.Flags).flatMap(stringToIntOption).getOrElse(0); | ||
return new Some(this.tracer.createRootId(sampled, flags === 1)); | ||
} else { | ||
@@ -75,12 +74,10 @@ return new Some(this.tracer.createRootId()); | ||
const id = this.tracer.id; | ||
const {path} = parseRequestUrl(requestUrl); | ||
this.tracer.recordServiceName(this.serviceName); | ||
this.tracer.recordRpc(method.toUpperCase()); | ||
this.tracer.recordBinary('http.url', requestUrl); | ||
this.tracer.recordBinary('http.path', path); | ||
this.tracer.recordAnnotation(new Annotation.ServerRecv()); | ||
this.tracer.recordAnnotation(new Annotation.LocalAddr({port: this.port})); | ||
this.tracer.recordAnnotation(new Annotation.LocalAddr({host: this.host, port: this.port})); | ||
if (id.flags !== 0 && id.flags != null) { | ||
this.tracer.recordBinary(Header.Flags, id.flags.toString()); | ||
} | ||
return id; | ||
@@ -87,0 +84,0 @@ } |
@@ -23,3 +23,3 @@ function Endpoint({serviceName, ipv4, port}) { | ||
this.timestamp = timestamp; | ||
this.value = value; | ||
this.value = value.toString(); | ||
} | ||
@@ -82,3 +82,3 @@ Annotation.prototype.toString = function toString() { | ||
Span.prototype.putTag = function putTag(key, value) { | ||
this.tags[key] = value; | ||
this.tags[key] = value.toString(); | ||
}; | ||
@@ -85,0 +85,0 @@ Span.prototype.setDebug = function setDebug(debug) { |
@@ -84,2 +84,8 @@ const None = { | ||
function verifyIsNotOptional(data) { | ||
if (data != null && isOptional(data)) { | ||
throw new Error(`Error: data (${data}) is an Option!`); | ||
} | ||
} | ||
function fromNullable(nullable) { | ||
@@ -96,2 +102,3 @@ if (nullable != null) { | ||
module.exports.verifyIsOptional = verifyIsOptional; | ||
module.exports.verifyIsNotOptional = verifyIsNotOptional; | ||
module.exports.fromNullable = fromNullable; |
@@ -54,3 +54,3 @@ const {None, Some, fromNullable} = require('../option'); | ||
createRootId() { | ||
createRootId(isSampled = None, isDebug = false) { | ||
const rootSpanId = randomTraceId(); | ||
@@ -64,6 +64,10 @@ const traceId = this.traceId128Bit | ||
spanId: rootSpanId, | ||
sampled: None, | ||
flags: 0 | ||
sampled: isSampled, | ||
flags: isDebug ? 1 : 0 | ||
}); | ||
id._sampled = this.sampler.shouldSample(id); | ||
if (isSampled === None) { | ||
id._sampled = this.sampler.shouldSample(id); | ||
} | ||
return id; | ||
@@ -157,4 +161,4 @@ } | ||
this.id.sampled.ifPresent(sampled => { | ||
// sampled present is different than sampled == true | ||
if (!sampled) return; | ||
this.recorder.record(new Record({ | ||
@@ -161,0 +165,0 @@ traceId: this.id, |
@@ -1,2 +0,2 @@ | ||
const {Some, None, verifyIsOptional} = require('../option'); | ||
const {Some, None, verifyIsOptional, verifyIsNotOptional} = require('../option'); | ||
@@ -8,2 +8,3 @@ class TraceId { | ||
verifyIsOptional(parentId); | ||
verifyIsNotOptional(spanId); | ||
verifyIsOptional(sampled); | ||
@@ -10,0 +11,0 @@ this._traceId = traceId; |
@@ -17,3 +17,6 @@ const sinon = require('sinon'); | ||
const url = 'http://127.0.0.1:80/weather?index=10&count=300'; | ||
const port = '80'; | ||
const host = '127.0.0.1'; | ||
const urlPath = '/weather'; | ||
const url = `http://${host}:${port}${urlPath}?index=10&count=300`; | ||
tracer.scoped(() => { | ||
@@ -36,4 +39,4 @@ instrumentation.recordRequest({}, url, 'GET'); | ||
expect(annotations[2].annotation.annotationType).to.equal('BinaryAnnotation'); | ||
expect(annotations[2].annotation.key).to.equal('http.url'); | ||
expect(annotations[2].annotation.value).to.equal(url); | ||
expect(annotations[2].annotation.key).to.equal('http.path'); | ||
expect(annotations[2].annotation.value).to.equal(urlPath); | ||
@@ -40,0 +43,0 @@ expect(annotations[3].annotation.annotationType).to.equal('ClientSend'); |
@@ -14,5 +14,6 @@ const sinon = require('sinon'); | ||
const instrumentation = new HttpServer({tracer, serviceName: 'service-a', port: 80}); | ||
const url = '/foo'; | ||
ctxImpl.scoped(() => { | ||
const id = instrumentation.recordRequest('POST', '/foo', () => None); | ||
const id = instrumentation.recordRequest('POST', url, () => None); | ||
tracer.recordBinary('message', 'hello from within app'); | ||
@@ -39,4 +40,4 @@ instrumentation.recordResponse(id, 202); | ||
expect(annotations[2].annotation.annotationType).to.equal('BinaryAnnotation'); | ||
expect(annotations[2].annotation.key).to.equal('http.url'); | ||
expect(annotations[2].annotation.value).to.equal('/foo'); | ||
expect(annotations[2].annotation.key).to.equal('http.path'); | ||
expect(annotations[2].annotation.value).to.equal(url); | ||
@@ -58,57 +59,152 @@ expect(annotations[3].annotation.annotationType).to.equal('ServerRecv'); | ||
it('should receive trace info from the client', () => { | ||
const record = sinon.spy(); | ||
const recorder = {record}; | ||
const ctxImpl = new ExplicitContext(); | ||
const tracer = new Tracer({recorder, ctxImpl}); | ||
const headers = { | ||
const traceContextCases = [ | ||
{ | ||
'X-B3-TraceId': 'aaa', | ||
'X-B3-SpanId': 'bbb', | ||
'X-B3-Flags': '1' | ||
}; | ||
const port = 80; | ||
const url = `http://127.0.0.1:${port}`; | ||
const instrumentation = new HttpServer({tracer, serviceName: 'service-a', port}); | ||
const readHeader = function(name) { return headers[name] ? new Some(headers[name]) : None; }; | ||
ctxImpl.scoped(() => { | ||
const id = instrumentation.recordRequest('POST', url, readHeader); | ||
tracer.recordBinary('message', 'hello from within app'); | ||
instrumentation.recordResponse(id, 202); | ||
}, | ||
{ | ||
'X-B3-TraceId': 'aaa', | ||
'X-B3-SpanId': 'bbb', | ||
'X-B3-Sampled': '1' | ||
} | ||
]; | ||
traceContextCases.forEach((headers, index) => { | ||
it(`should extract trace from the client and record annotations case ${index}`, () => { | ||
const record = sinon.spy(); | ||
const recorder = {record}; | ||
const ctxImpl = new ExplicitContext(); | ||
const tracer = new Tracer({recorder, ctxImpl}); | ||
const port = 80; | ||
const host = '127.0.0.1'; | ||
const url = `http://${host}:${port}`; | ||
const instrumentation = new HttpServer({tracer, serviceName: 'service-a', port}); | ||
const readHeader = function(name) { | ||
return headers[name] ? new Some(headers[name]) : None; | ||
}; | ||
ctxImpl.scoped(() => { | ||
const id = instrumentation.recordRequest('POST', url, readHeader); | ||
tracer.recordBinary('message', 'hello from within app'); | ||
instrumentation.recordResponse(id, 202); | ||
}); | ||
const annotations = record.args.map(args => args[0]); | ||
annotations.forEach(ann => expect(ann.traceId.traceId).to.equal('aaa')); | ||
annotations.forEach(ann => expect(ann.traceId.spanId).to.equal('bbb')); | ||
expect(annotations[0].annotation.annotationType).to.equal('ServiceName'); | ||
expect(annotations[0].annotation.serviceName).to.equal('service-a'); | ||
expect(annotations[1].annotation.annotationType).to.equal('Rpc'); | ||
expect(annotations[1].annotation.name).to.equal('POST'); | ||
expect(annotations[2].annotation.annotationType).to.equal('BinaryAnnotation'); | ||
expect(annotations[2].annotation.key).to.equal('http.path'); | ||
expect(annotations[2].annotation.value).to.equal('/'); | ||
expect(annotations[3].annotation.annotationType).to.equal('ServerRecv'); | ||
expect(annotations[4].annotation.annotationType).to.equal('LocalAddr'); | ||
expect(annotations[5].annotation.annotationType).to.equal('BinaryAnnotation'); | ||
expect(annotations[5].annotation.key).to.equal('message'); | ||
expect(annotations[5].annotation.value).to.equal('hello from within app'); | ||
expect(annotations[6].annotation.annotationType).to.equal('BinaryAnnotation'); | ||
expect(annotations[6].annotation.key).to.equal('http.status_code'); | ||
expect(annotations[6].annotation.value).to.equal('202'); | ||
expect(annotations[7].annotation.annotationType).to.equal('ServerSend'); | ||
}); | ||
const annotations = record.args.map(args => args[0]); | ||
}); | ||
annotations.forEach(ann => expect(ann.traceId.traceId).to.equal('aaa')); | ||
annotations.forEach(ann => expect(ann.traceId.spanId).to.equal('bbb')); | ||
const samplingFlagCases = [ | ||
{headers: {'X-B3-Flags': '0'}, hasAnnotations: null}, | ||
{headers: {'X-B3-Flags': '1'}, hasAnnotations: true}, | ||
{headers: {'X-B3-Sampled': '0'}, hasAnnotations: false}, | ||
{headers: {'X-B3-Sampled': '1'}, hasAnnotations: true}, | ||
{headers: {'X-B3-Sampled': 'true'}, hasAnnotations: true}, | ||
{headers: {'X-B3-Sampled': 'false'}, hasAnnotations: false}, | ||
{headers: {'X-B3-Sampled': '0', 'X-B3-Flags': '0'}, hasAnnotations: false}, | ||
{headers: {'X-B3-Sampled': '0', 'X-B3-Flags': '1'}, hasAnnotations: true}, | ||
{headers: {'X-B3-Sampled': '1', 'X-B3-Flags': '0'}, hasAnnotations: true}, | ||
{headers: {'X-B3-Sampled': '1', 'X-B3-Flags': '1'}, hasAnnotations: true}, | ||
]; | ||
expect(annotations[0].annotation.annotationType).to.equal('ServiceName'); | ||
expect(annotations[0].annotation.serviceName).to.equal('service-a'); | ||
samplingFlagCases.forEach(({headers, hasAnnotations}) => { | ||
const caseName = []; | ||
expect(annotations[1].annotation.annotationType).to.equal('Rpc'); | ||
expect(annotations[1].annotation.name).to.equal('POST'); | ||
if (headers['X-B3-Flags']) { | ||
caseName.push(`flags=${headers['X-B3-Flags']}`); | ||
} | ||
expect(annotations[2].annotation.annotationType).to.equal('BinaryAnnotation'); | ||
expect(annotations[2].annotation.key).to.equal('http.url'); | ||
expect(annotations[2].annotation.value).to.equal(url); | ||
if (headers['X-B3-Sampled']) { | ||
caseName.push(`sampled=${headers['X-B3-Sampled']}`); | ||
} | ||
expect(annotations[3].annotation.annotationType).to.equal('ServerRecv'); | ||
if (caseName.length === 0) { | ||
caseName.push('no-flags'); | ||
} | ||
expect(annotations[4].annotation.annotationType).to.equal('LocalAddr'); | ||
it(`should receive sampling flags from the client with ${caseName.join(', ')}`, () => { | ||
const record = sinon.spy(); | ||
const recorder = {record}; | ||
const ctxImpl = new ExplicitContext(); | ||
const tracer = new Tracer({recorder, ctxImpl}); | ||
expect(annotations[5].annotation.annotationType).to.equal('BinaryAnnotation'); | ||
expect(annotations[5].annotation.key).to.equal('X-B3-Flags'); | ||
expect(annotations[5].annotation.value).to.equal('1'); | ||
const port = 80; | ||
const url = `http://127.0.0.1:${port}`; | ||
const instrumentation = new HttpServer({tracer, serviceName: 'service-a', port}); | ||
expect(annotations[6].annotation.annotationType).to.equal('BinaryAnnotation'); | ||
expect(annotations[6].annotation.key).to.equal('message'); | ||
expect(annotations[6].annotation.value).to.equal('hello from within app'); | ||
expect(annotations[7].annotation.annotationType).to.equal('BinaryAnnotation'); | ||
expect(annotations[7].annotation.key).to.equal('http.status_code'); | ||
expect(annotations[7].annotation.value).to.equal('202'); | ||
const readHeader = function(name) { | ||
return headers[name] ? new Some(headers[name]) : None; | ||
}; | ||
expect(annotations[8].annotation.annotationType).to.equal('ServerSend'); | ||
ctxImpl.scoped(() => { | ||
const id = instrumentation.recordRequest('POST', url, readHeader); | ||
tracer.recordBinary('message', 'hello from within app'); | ||
instrumentation.recordResponse(id, 202); | ||
}); | ||
const annotations = record.args.map(args => args[0]); | ||
if (hasAnnotations === true) { | ||
annotations.forEach(ann => expect(ann.traceId.traceId).to.not.be.empty); | ||
annotations.forEach(ann => expect(ann.traceId.spanId).to.not.be.empty); | ||
expect(annotations[0].annotation.annotationType).to.equal('ServiceName'); | ||
expect(annotations[0].annotation.serviceName).to.equal('service-a'); | ||
expect(annotations[1].annotation.annotationType).to.equal('Rpc'); | ||
expect(annotations[1].annotation.name).to.equal('POST'); | ||
expect(annotations[2].annotation.annotationType).to.equal('BinaryAnnotation'); | ||
expect(annotations[2].annotation.key).to.equal('http.path'); | ||
expect(annotations[2].annotation.value).to.equal('/'); | ||
expect(annotations[3].annotation.annotationType).to.equal('ServerRecv'); | ||
expect(annotations[4].annotation.annotationType).to.equal('LocalAddr'); | ||
expect(annotations[5].annotation.annotationType).to.equal('BinaryAnnotation'); | ||
expect(annotations[5].annotation.key).to.equal('message'); | ||
expect(annotations[5].annotation.value).to.equal('hello from within app'); | ||
expect(annotations[6].annotation.annotationType).to.equal('BinaryAnnotation'); | ||
expect(annotations[6].annotation.key).to.equal('http.status_code'); | ||
expect(annotations[6].annotation.value).to.equal('202'); | ||
expect(annotations[7].annotation.annotationType).to.equal('ServerSend'); | ||
} else if (hasAnnotations === false) { | ||
// nothing should be recorded | ||
expect(annotations.length).to.equal(0); | ||
} | ||
}); | ||
}); | ||
it('should properly report the URL with a query string', () => { | ||
it('should properly report the path excluding the query string', () => { | ||
const record = sinon.spy(); | ||
@@ -120,4 +216,6 @@ const recorder = {record}; | ||
const port = 80; | ||
const host = '127.0.0.1'; | ||
const urlPath = '/foo'; | ||
const instrumentation = new HttpServer({tracer, serviceName: 'service-a', port}); | ||
const url = `http://127.0.0.1:${port}/foo?abc=123`; | ||
const url = `http://${host}:${port}${urlPath}?abc=123`; | ||
ctxImpl.scoped(() => { | ||
@@ -131,4 +229,4 @@ const id = instrumentation.recordRequest('GET', url, () => None); | ||
expect(annotations[2].annotation.annotationType).to.equal('BinaryAnnotation'); | ||
expect(annotations[2].annotation.key).to.equal('http.url'); | ||
expect(annotations[2].annotation.value).to.equal(url); | ||
expect(annotations[2].annotation.key).to.equal('http.path'); | ||
expect(annotations[2].annotation.value).to.equal(urlPath); | ||
}); | ||
@@ -169,18 +267,75 @@ | ||
const headers = { | ||
'X-B3-TraceId': 'aaa', | ||
'X-B3-SpanId': 'bbb', | ||
'X-B3-Flags': '1', | ||
'X-B3-Sampled': 'true' | ||
}; | ||
const headersCases = [ | ||
{ | ||
'X-B3-TraceId': 'aaa', | ||
'X-B3-SpanId': 'bbb', | ||
'X-B3-Flags': '1', | ||
'X-B3-Sampled': 'true' | ||
}, | ||
{ | ||
'X-B3-Flags': '1', | ||
'X-B3-Sampled': 'true' | ||
} | ||
]; | ||
const port = 80; | ||
const url = `http://127.0.0.1:${port}`; | ||
const instrumentation = new HttpServer({tracer, serviceName: 'service-a', port}); | ||
const readHeader = function(name) { return headers[name] ? new Some(headers[name]) : None; }; | ||
headersCases.forEach(headers => { | ||
const port = 80; | ||
const url = `http://127.0.0.1:${port}`; | ||
const instrumentation = new HttpServer({tracer, serviceName: 'service-a', port}); | ||
const readHeader = function(name) { | ||
return headers[name] ? new Some(headers[name]) : None; | ||
}; | ||
ctxImpl.scoped(() => { | ||
const id = instrumentation.recordRequest('POST', url, readHeader); | ||
expect(id._sampled.value).to.equal(true); | ||
}); | ||
}); | ||
}); | ||
it('should allow the host to be overridden', () => { | ||
const record = sinon.spy(); | ||
const recorder = {record}; | ||
const ctxImpl = new ExplicitContext(); | ||
const tracer = new Tracer({recorder, ctxImpl}); | ||
const instrumentation = new HttpServer({ | ||
tracer, | ||
serviceName: 'service-a', | ||
host: '1.1.1.1', | ||
port: 80 | ||
}); | ||
ctxImpl.scoped(() => { | ||
const id = instrumentation.recordRequest('POST', url, readHeader); | ||
expect(id._sampled.value).to.equal(true); | ||
const id = instrumentation.recordRequest('POST', '/test-url', () => None); | ||
instrumentation.recordResponse(id, 202); | ||
}); | ||
const localAddr = record.args | ||
.map(args => args[0].annotation) | ||
.find(annotation => annotation.annotationType === 'LocalAddr'); | ||
expect(localAddr.host.addr).to.equal('1.1.1.1'); | ||
}); | ||
it('should work if the host option is not defined', () => { | ||
const record = sinon.spy(); | ||
const recorder = {record}; | ||
const ctxImpl = new ExplicitContext(); | ||
const tracer = new Tracer({recorder, ctxImpl}); | ||
const instrumentation = new HttpServer({ | ||
tracer, | ||
serviceName: 'service-a', | ||
port: 80 | ||
}); | ||
ctxImpl.scoped(() => { | ||
const id = instrumentation.recordRequest('POST', '/test-url', () => None); | ||
instrumentation.recordResponse(id, 202); | ||
}); | ||
const localAddr = record.args | ||
.map(args => args[0].annotation) | ||
.find(annotation => annotation.annotationType === 'LocalAddr'); | ||
expect(localAddr.host.addr).not.to.equal(undefined); | ||
}); | ||
}); |
@@ -59,2 +59,34 @@ const TraceId = require('../src/tracer/TraceId'); | ||
}); | ||
const annotationTypesCases = [[10, '10'], [true, 'true'], [{}], [[]]]; | ||
annotationTypesCases.forEach(([annotationValue, expectedValue]) => { | ||
it(`should convert ${typeof annotationValue} annotation values to strings`, () => { | ||
const span = new Span(new TraceId({ | ||
traceId: new Some('a'), | ||
spanId: 'b', | ||
})); | ||
span.addAnnotation(101239, annotationValue); | ||
if (expectedValue !== undefined) { | ||
expect(span.annotations[0].value).to.equal(expectedValue); | ||
} | ||
}); | ||
}); | ||
const tagTypesCases = [[10, '10'], [true, 'true'], [{}], [[]]]; | ||
tagTypesCases.forEach(([tagValue, expectedValue]) => { | ||
it(`should convert ${typeof tagValue} tag values to strings`, () => { | ||
const span = new Span(new TraceId({ | ||
traceId: new Some('a'), | ||
spanId: 'b', | ||
})); | ||
span.putTag('c', tagValue); | ||
if (expectedValue !== undefined) { | ||
expect(span.tags.c).to.equal(expectedValue); | ||
} | ||
}); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
341073
63
4449