diff --git a/lib/constants.js b/lib/constants.js index 454adb2bf..9bebbf09e 100644 --- a/lib/constants.js +++ b/lib/constants.js @@ -18,8 +18,8 @@ module.exports = { /** @const {string} header that carries trace context across Google infrastructure. */ - TRACE_CONTEXT_HEADER_NAME: 'X-Cloud-Trace-Context', + TRACE_CONTEXT_HEADER_NAME: 'x-cloud-trace-context', /** @const {string} header that is used to identify outgoing http made by the agent. */ - TRACE_AGENT_REQUEST_HEADER: 'X-Cloud-Trace-Agent-Request' + TRACE_AGENT_REQUEST_HEADER: 'x-cloud-trace-agent-request' }; diff --git a/test/standalone/test-trace-header-context.js b/test/standalone/test-trace-header-context.js index 1dea935d5..6a93cd0dd 100644 --- a/test/standalone/test-trace-header-context.js +++ b/test/standalone/test-trace-header-context.js @@ -22,6 +22,14 @@ var express = require('../hooks/fixtures/express4'); var constants = require('../../lib/constants.js'); describe('test-trace-header-context', function() { + beforeEach(function() { + require('../..').start(); + }); + + afterEach(function() { + require('../..').stop(); + }); + it('should work with string url', function(done) { var app = express(); var server; @@ -30,7 +38,7 @@ describe('test-trace-header-context', function() { res.send(common.serverRes); }); app.get('/self', function(req, res) { - assert(req.headers[constants.TRACE_CONTEXT_HEADER_NAME.toLowerCase()]); + assert(req.headers[constants.TRACE_CONTEXT_HEADER_NAME]); res.send(common.serverRes); var traces = common.getTraces(); assert.equal(traces.length, 2); @@ -56,7 +64,7 @@ describe('test-trace-header-context', function() { res.send(common.serverRes); }); app.get('/self', function(req, res) { - assert(req.headers[constants.TRACE_CONTEXT_HEADER_NAME.toLowerCase()]); + assert(req.headers[constants.TRACE_CONTEXT_HEADER_NAME]); res.send(common.serverRes); var traces = common.getTraces(); assert.equal(traces.length, 2); @@ -73,4 +81,35 @@ describe('test-trace-header-context', function() { http.get({ port: common.serverPort }); }); }); + + it('should parse incoming header', function(done) { + var app = express(); + var server; + var context = '123456/2'; + app.get('/', function (req, res) { + http.get({ port: common.serverPort, path: '/self'}); + res.send(common.serverRes); + }); + app.get('/self', function(req, res) { + assert.equal( + req.headers[constants.TRACE_CONTEXT_HEADER_NAME].slice(0, 6), + context.slice(0, 6)); + res.send(common.serverRes); + var traces = common.getTraces(); + assert.equal(traces.length, 2); + assert.equal(traces[0].spans.length, 2); + assert.equal(traces[1].spans.length, 1); + assert.equal(traces[0].spans[0].name, '/'); + assert.equal(traces[0].spans[1].name, 'http://localhost:9042/self'); + assert.equal(traces[1].spans[0].name, '/self'); + common.cleanTraces(); + server.close(); + done(); + }); + server = app.listen(common.serverPort, function() { + var headers = {}; + headers[constants.TRACE_CONTEXT_HEADER_NAME] = context; + http.get({ port: common.serverPort, headers: headers }); + }); + }); }); diff --git a/test/test-constants.js b/test/test-constants.js index bd26daaa0..a33ca66af 100644 --- a/test/test-constants.js +++ b/test/test-constants.js @@ -21,7 +21,7 @@ var constants = require('../lib/constants.js'); describe('constants', function() { it('has correct values', function() { - assert.equal(constants.TRACE_CONTEXT_HEADER_NAME, 'X-Cloud-Trace-Context'); - assert.equal(constants.TRACE_AGENT_REQUEST_HEADER, 'X-Cloud-Trace-Agent-Request'); + assert.equal(constants.TRACE_CONTEXT_HEADER_NAME, 'x-cloud-trace-context'); + assert.equal(constants.TRACE_AGENT_REQUEST_HEADER, 'x-cloud-trace-agent-request'); }); });