From 0a982292ca289f52d5c639c1ac0ebd8e25e84aea Mon Sep 17 00:00:00 2001 From: David Kiss Date: Wed, 24 Feb 2016 11:13:14 +0100 Subject: [PATCH] refactor(agent): protocol support --- lib/consts.js | 3 +++ lib/instrumentations/core/http/request.js | 2 ++ lib/instrumentations/core/http/request.spec.js | 6 ++++-- lib/instrumentations/core/http/server.js | 5 ++++- lib/instrumentations/core/http/server.spec.js | 16 ++++++++++------ 5 files changed, 23 insertions(+), 9 deletions(-) diff --git a/lib/consts.js b/lib/consts.js index a446c3a..97df75a 100644 --- a/lib/consts.js +++ b/lib/consts.js @@ -1,5 +1,8 @@ module.exports = { MUST_COLLECT: { ERROR: '1' + }, + PROTOCOLS: { + HTTP: 'http' } } diff --git a/lib/instrumentations/core/http/request.js b/lib/instrumentations/core/http/request.js index 5b6f1e3..e83fc1a 100644 --- a/lib/instrumentations/core/http/request.js +++ b/lib/instrumentations/core/http/request.js @@ -56,6 +56,7 @@ function wrapRequest (originalHttpRequest, agent, mustCollectStore) { collectorDataBag = { id: requestId, spanId: spanId, + protocol: consts.PROTOCOLS.HTTP, host: requestParams.host, url: util.formatDataUrl(requestParams.path), time: clientSendTime, @@ -110,6 +111,7 @@ function wrapRequest (originalHttpRequest, agent, mustCollectStore) { var collectorDataBag = { id: requestId, spanId: spanId, + protocol: consts.PROTOCOLS.HTTP, host: requestParams.host, url: util.formatDataUrl(requestParams.path), statusCode: incomingMessage.statusCode, diff --git a/lib/instrumentations/core/http/request.spec.js b/lib/instrumentations/core/http/request.spec.js index 75af03f..ca8f10b 100644 --- a/lib/instrumentations/core/http/request.spec.js +++ b/lib/instrumentations/core/http/request.spec.js @@ -95,7 +95,8 @@ describe('The http.request wrapper module', function () { method: 'GET', mustCollect: undefined, time: 12345678, - url: '/' + url: '/', + protocol: 'http' }) expect(agent.clientReceive).to.be.calledWith({ @@ -104,7 +105,8 @@ describe('The http.request wrapper module', function () { mustCollect: undefined, spanId: spanId, statusCode: 200, - url: '/' + url: '/', + protocol: 'http' }) expect(original).to.be.calledWith({ diff --git a/lib/instrumentations/core/http/server.js b/lib/instrumentations/core/http/server.js index 81007ad..10f9fbc 100644 --- a/lib/instrumentations/core/http/server.js +++ b/lib/instrumentations/core/http/server.js @@ -55,6 +55,7 @@ function wrapListener (listener, agent, mustCollectStore) { url: util.formatDataUrl(requestUrl.pathname), time: serverRecieveTime, method: method, + protocol: consts.PROTOCOLS.HTTP, parentId: headers['x-parent'], originTime: headers['x-client-send'] } @@ -76,6 +77,7 @@ function wrapListener (listener, agent, mustCollectStore) { host: headers.host, url: util.formatDataUrl(requestUrl.pathname), time: serverSendTime, + protocol: consts.PROTOCOLS.HTTP, statusCode: response.statusCode, responseTime: responseTime } @@ -103,7 +105,8 @@ function wrapListener (listener, agent, mustCollectStore) { response.setHeader('x-parent', serviceKey) } - response.setHeader('x-client-send', serverSendTime) + response.setHeader('x-server-send', serverSendTime) + response.setHeader('x-server-receive', serverRecieveTime) if (spanId) { debug('trace event (ss); request: %s, x-span-id header has been set to: %s', requestId, spanId) diff --git a/lib/instrumentations/core/http/server.spec.js b/lib/instrumentations/core/http/server.spec.js index 71fe48a..fa6502e 100644 --- a/lib/instrumentations/core/http/server.spec.js +++ b/lib/instrumentations/core/http/server.spec.js @@ -138,7 +138,8 @@ describe('The http.Server.prototype wrapper module', function () { host: 'localhost', originTime: undefined, parentId: undefined, - spanId: undefined + spanId: undefined, + protocol: 'http' }) expect(agent.serverSend).to.be.calledWith({ @@ -149,10 +150,11 @@ describe('The http.Server.prototype wrapper module', function () { statusCode: statusCode, time: 12345678, url: '/', - responseTime: 0 + responseTime: 0, + protocol: 'http' }) - expect(setHeaderSpy).to.be.calledWith('x-client-send', 12345678) + expect(setHeaderSpy).to.be.calledWith('x-server-send', 12345678) expect(setHeaderSpy).to.be.calledWith('x-parent', 0) expect(writeHeadSpy).to.be.calledOnce }) @@ -200,7 +202,8 @@ describe('The http.Server.prototype wrapper module', function () { host: 'localhost', originTime: undefined, parentId: undefined, - spanId: spanId + spanId: spanId, + protocol: 'http' }) expect(agent.serverSend).to.be.calledWith({ @@ -211,11 +214,12 @@ describe('The http.Server.prototype wrapper module', function () { mustCollect: consts.MUST_COLLECT.ERROR, time: 12345678, url: '/', - responseTime: 0 + responseTime: 0, + protocol: 'http' }) expect(agent.setSpanId).to.be.calledWith(spanId) - expect(setHeaderSpy).to.be.calledWith('x-client-send', 12345678) + expect(setHeaderSpy).to.be.calledWith('x-server-send', 12345678) expect(setHeaderSpy).to.be.calledWith('x-parent', 0) expect(setHeaderSpy).to.be.calledWith('x-span-id', spanId) expect(setHeaderSpy).to.be.calledWith('x-must-collect', '1')