From f321ee9aa05bd4ccaf36fce96e0c36d9eeeaccb0 Mon Sep 17 00:00:00 2001 From: Jerry Jalava Date: Wed, 7 Sep 2016 21:14:12 +0300 Subject: [PATCH] Allow ignoring the requests Context header (#295) * Allow ignoring the requests Context header * added simple test for the header disabling config flag * fixed test --- config.js | 7 +++++-- lib/trace-agent.js | 3 +++ test/test-trace-agent.js | 10 ++++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/config.js b/config.js index aed70bcfa..e0463a0fc 100644 --- a/config.js +++ b/config.js @@ -64,7 +64,7 @@ module.exports = { // Specifies the behavior of the trace agent in the case of an uncaught exception. // Possible values are: - // `ignore`: Take no action. Note that the process may termiante before all the + // `ignore`: Take no action. Note that the process may termiante before all the // traces currently buffered have been flushed to the network. // `flush`: Handle the uncaught exception and attempt to publish the traces to // the API. Note that if you have other uncaught exception handlers in your @@ -79,6 +79,9 @@ module.exports = { // a delay. Note that presence of other uncaught exception handlers may // chose to terminate the application before the buffer has been flushed to // the network. - onUncaughtException: 'ignore' + onUncaughtException: 'ignore', + + // Allows to ignore the requests X-Cloud-Trace-Context -header if set + ignoreContextHeader: false } }; diff --git a/lib/trace-agent.js b/lib/trace-agent.js index 208dc9e1b..574303cad 100644 --- a/lib/trace-agent.js +++ b/lib/trace-agent.js @@ -231,6 +231,9 @@ TraceAgent.prototype.isTraceAgentRequest = function(options) { * object with keys. null if there is a problem. */ TraceAgent.prototype.parseContextFromHeader = function(str) { + if (this.config_.ignoreContextHeader) { + return null; + } if (!str) { return null; } diff --git a/test/test-trace-agent.js b/test/test-trace-agent.js index c69b6c7a6..8fd65e121 100644 --- a/test/test-trace-agent.js +++ b/test/test-trace-agent.js @@ -160,6 +160,16 @@ describe('Trace Agent', function() { }); }); }); + + describe('when configured to ignore header', function() { + it('should return expected value: null', function() { + agent.config_.ignoreContextHeader = true; + var result = agent.parseContextFromHeader( + '123456/667;o=1'); + assert(!result); + agent.config_.ignoreContextHeader = false; + }); + }); }); });