Skip to content

Commit

Permalink
Allow ignoring the requests Context header (#295)
Browse files Browse the repository at this point in the history
* Allow ignoring the requests Context header

* added simple test for the header disabling config flag

* fixed test
  • Loading branch information
jerryjj authored and matthewloring committed Sep 7, 2016
1 parent aa274e7 commit f321ee9
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
7 changes: 5 additions & 2 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
};
3 changes: 3 additions & 0 deletions lib/trace-agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
10 changes: 10 additions & 0 deletions test/test-trace-agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
});
});

});

0 comments on commit f321ee9

Please sign in to comment.