zipkin-instrumentation-cujojs-rest
Advanced tools
Comparing version 0.18.3 to 0.18.4-alpha.7
{ | ||
"name": "zipkin-instrumentation-cujojs-rest", | ||
"version": "0.18.3", | ||
"version": "0.18.4-alpha.7+3913fd5", | ||
"description": "Interceptor for instrumenting HTTP calls from the cujoJS rest library", | ||
@@ -8,3 +8,5 @@ "main": "lib/index.js", | ||
"build": "babel src -d lib", | ||
"test": "mocha --exit --require ../../test/helper.js", | ||
"test": "mocha --require ../../test/helper.js --require @babel/register && karma start --single-run --browsers ChromeHeadless,FirefoxHeadless ../../karma.conf.js", | ||
"test-browser": "karma start --single-run --browsers ChromeHeadless ../../karma.conf.js", | ||
"test-debug": "mocha --inspect-brk --exit --require ../../test/helper.js", | ||
"prepublish": "npm run build" | ||
@@ -16,10 +18,6 @@ }, | ||
"devDependencies": { | ||
"@babel/cli": "7.1.5", | ||
"@babel/core": "7.1.5", | ||
"express": "^4.13.4", | ||
"mocha": "^5.2.0", | ||
"rest": "^1.3.2", | ||
"zipkin": "^0.18.3" | ||
"zipkin": "^0.18.4-alpha.7+3913fd5" | ||
}, | ||
"gitHead": "ee17b9fc76796f4ce340cbac7a43a29a2970ac3a" | ||
"gitHead": "3913fd50c6ed9e7a7fce104729bb52b554eaf024" | ||
} |
@@ -1,84 +0,130 @@ | ||
const {Tracer, ExplicitContext} = require('zipkin'); | ||
const express = require('express'); | ||
const sinon = require('sinon'); | ||
const {expect} = require('chai'); | ||
const { | ||
maybeMiddleware, | ||
newSpanRecorder, | ||
expectB3Headers, | ||
expectSpan | ||
} = require('../../../test/testFixture'); | ||
const {ExplicitContext, Tracer} = require('zipkin'); | ||
const rest = require('rest'); | ||
const restInterceptor = require('../src/restInterceptor'); | ||
describe('cujojs rest interceptor - integration test', () => { | ||
it('should add headers to requests', done => { | ||
const app = express(); | ||
app.get('/abc', (req, res) => { | ||
res.status(202).json({ | ||
traceId: req.header('X-B3-TraceId'), | ||
spanId: req.header('X-B3-SpanId') | ||
}); | ||
}); | ||
// NOTE: CujoJS/rest sends all http status to success callback | ||
describe('CujoJS/rest instrumentation - integration test', () => { | ||
const serviceName = 'weather-app'; | ||
const remoteServiceName = 'weather-api'; | ||
const server = app.listen(0, () => { | ||
const record = sinon.spy(); | ||
const recorder = {record}; | ||
const ctxImpl = new ExplicitContext(); | ||
const tracer = new Tracer({recorder, ctxImpl}); | ||
let server; | ||
let baseURL = ''; // default to relative path, for browser-based tests | ||
tracer.scoped(() => { | ||
const client = rest.wrap(restInterceptor, { | ||
tracer, | ||
serviceName: 'caller', | ||
remoteServiceName: 'callee' | ||
}); | ||
const port = server.address().port; | ||
const host = '127.0.0.1'; | ||
const urlPath = '/abc'; | ||
const url = `http://${host}:${port}${urlPath}`; | ||
client(url).then(successResponse => { | ||
const responseData = JSON.parse(successResponse.entity); | ||
server.close(); | ||
before((done) => { | ||
const middleware = maybeMiddleware(); | ||
if (middleware !== null) { | ||
server = middleware.listen(0, () => { | ||
baseURL = `http://127.0.0.1:${server.address().port}`; | ||
done(); | ||
}); | ||
} else { // Inside a browser | ||
done(); | ||
} | ||
}); | ||
const annotations = record.args.map(args => args[0]); | ||
after(() => { | ||
if (server) server.close(); | ||
}); | ||
// All annotations should have the same trace id and span id | ||
const traceId = annotations[0].traceId.traceId; | ||
const spanId = annotations[0].traceId.spanId; | ||
annotations.forEach(ann => expect(ann.traceId.traceId).to.equal(traceId)); | ||
annotations.forEach(ann => expect(ann.traceId.spanId).to.equal(spanId)); | ||
let spans; | ||
let tracer; | ||
expect(annotations[0].annotation.annotationType).to.equal('ServiceName'); | ||
expect(annotations[0].annotation.serviceName).to.equal('caller'); | ||
beforeEach(() => { | ||
spans = []; | ||
tracer = new Tracer({ctxImpl: new ExplicitContext(), recorder: newSpanRecorder(spans)}); | ||
}); | ||
expect(annotations[1].annotation.annotationType).to.equal('Rpc'); | ||
expect(annotations[1].annotation.name).to.equal('GET'); | ||
function popSpan() { | ||
expect(spans).to.not.be.empty; // eslint-disable-line no-unused-expressions | ||
return spans.pop(); | ||
} | ||
expect(annotations[2].annotation.annotationType).to.equal('BinaryAnnotation'); | ||
expect(annotations[2].annotation.key).to.equal('http.path'); | ||
expect(annotations[2].annotation.value).to.equal(urlPath); | ||
function getClient() { | ||
return rest.wrap(restInterceptor, {tracer, serviceName, remoteServiceName}); | ||
} | ||
expect(annotations[3].annotation.annotationType).to.equal('ClientSend'); | ||
function url(path) { | ||
return `${baseURL}${path}?index=10&count=300`; | ||
} | ||
expect(annotations[4].annotation.annotationType).to.equal('ServerAddr'); | ||
expect(annotations[4].annotation.serviceName).to.equal('callee'); | ||
function successSpan(path) { | ||
return ({ | ||
name: 'get', | ||
kind: 'CLIENT', | ||
localEndpoint: {serviceName}, | ||
remoteEndpoint: {serviceName: remoteServiceName}, | ||
tags: { | ||
'http.path': path, | ||
'http.status_code': '202' | ||
} | ||
}); | ||
} | ||
expect(annotations[5].annotation.annotationType).to.equal('BinaryAnnotation'); | ||
expect(annotations[5].annotation.key).to.equal('http.status_code'); | ||
expect(annotations[5].annotation.value).to.equal('202'); | ||
it('should add headers to requests', () => { | ||
const path = '/weather/wuhan'; | ||
return getClient()(url(path)) | ||
.then(response => expectB3Headers(popSpan(), JSON.parse(response.entity))); | ||
}); | ||
expect(annotations[6].annotation.annotationType).to.equal('ClientRecv'); | ||
it('should support get request', () => { | ||
const path = '/weather/wuhan'; | ||
return getClient()(url(path)) | ||
.then(() => expectSpan(popSpan(), successSpan(path))); | ||
}); | ||
const traceIdOnServer = responseData.traceId; | ||
expect(traceIdOnServer).to.equal(traceId); | ||
it('should report 404 in tags', () => { | ||
const path = '/pathno'; | ||
return getClient()(url(path)) | ||
.then(() => expectSpan(popSpan(), { | ||
name: 'get', | ||
kind: 'CLIENT', | ||
localEndpoint: {serviceName}, | ||
remoteEndpoint: {serviceName: remoteServiceName}, | ||
tags: { | ||
'http.path': path, | ||
'http.status_code': '404', | ||
error: '404' | ||
} | ||
})); | ||
}); | ||
const spanIdOnServer = responseData.spanId; | ||
expect(spanIdOnServer).to.equal(spanId); | ||
it('should report 400 in tags', () => { | ||
const path = '/weather/securedTown'; | ||
return getClient()(url(path)) | ||
.then(() => expectSpan(popSpan(), { | ||
name: 'get', | ||
kind: 'CLIENT', | ||
localEndpoint: {serviceName}, | ||
remoteEndpoint: {serviceName: remoteServiceName}, | ||
tags: { | ||
'http.path': path, | ||
'http.status_code': '400', | ||
error: '400' | ||
} | ||
})); | ||
}); | ||
done(); | ||
}, errorResponse => { | ||
if (errorResponse instanceof Error) { | ||
done(errorResponse); | ||
} else { | ||
server.close(); | ||
done(new Error(`The request failed: ${errorResponse.error.toString()}`)); | ||
} | ||
}); | ||
}); | ||
}); | ||
it('should report 500 in tags', () => { | ||
const path = '/weather/bagCity'; | ||
return getClient()(url(path)) | ||
.then(() => expectSpan(popSpan(), { | ||
name: 'get', | ||
kind: 'CLIENT', | ||
localEndpoint: {serviceName}, | ||
remoteEndpoint: {serviceName: remoteServiceName}, | ||
tags: { | ||
'http.path': path, | ||
'http.status_code': '500', | ||
error: '500' | ||
} | ||
})); | ||
}); | ||
}); |
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
7335
2
192
1