Skip to content

Commit

Permalink
Allow host to be overridden in httpServer instrumentation (openzipkin…
Browse files Browse the repository at this point in the history
  • Loading branch information
Roman Coedo committed Jul 10, 2018
1 parent 5ec1c8d commit c2ea28e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
11 changes: 7 additions & 4 deletions packages/zipkin/src/instrumentation/httpServer.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
const Annotation = require('../annotation');
const Header = require('../httpHeaders');
const {Some, None} = require('../option');
const InetAddress = require('../InetAddress');
const TraceId = require('../tracer/TraceId');
const Annotation = require('../annotation');
const parseRequestUrl = require('../parseUrl');
const {Some, None} = require('../option');

function stringToBoolean(str) {
return str === '1' || str === 'true';
Expand All @@ -28,10 +29,12 @@ class HttpServerInstrumentation {
constructor({
tracer = requiredArg('tracer'),
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;
}

Expand Down Expand Up @@ -78,7 +81,7 @@ class HttpServerInstrumentation {
this.tracer.recordRpc(method.toUpperCase());
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}));

return id;
}
Expand Down
20 changes: 20 additions & 0 deletions packages/zipkin/test/httpServerInstrumentation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,4 +248,24 @@ describe('Http Server Instrumentation', () => {
});
});
});

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', '/test-url', () => None);
instrumentation.recordResponse(id, 202);
});

const localAddr = record.args
.map(args => args[0].annotation)
.find(annotation => annotation.annotationType === 'LocalAddr')

expect(localAddr).to.not.be.undefined
expect(localAddr.host.addr).to.equal('1.1.1.1')
});
});

0 comments on commit c2ea28e

Please sign in to comment.