diff --git a/lib/config.js b/lib/config.js index 031cd7281c..317fcbec39 100644 --- a/lib/config.js +++ b/lib/config.js @@ -198,7 +198,10 @@ function Config(config) { // 4. override config with environment variables this._fromEnvironment(); - // 5. put the version in the config + // 5. clean up anything that requires postprocessing + this._canonicalize(); + + // 6. put the version in the config this.version = require(path.join(__dirname, '..', 'package.json')).version; } util.inherits(Config, EventEmitter); @@ -564,6 +567,21 @@ Config.prototype._fromEnvironment = function (metadata, data) { }, this); }; +/** + * Depending on how the status codes are set, they could be strings, which + * makes strict equality testing / indexOf fail. To keep things cheap, parse + * them once, after configuration has finished loading. Other one-off shims + * based on special properties of configuration values should go here as well. + */ +Config.prototype._canonicalize = function () { + var codes = this.error_collector && this.error_collector.ignore_status_codes; + if (codes) { + this.error_collector.ignore_status_codes = codes.map(function (code) { + return parseInt(code, 10); + }); + } +}; + /** * The agent will use the supportability metrics object if it's * available. diff --git a/test/config.test.js b/test/config.test.js index ee9c9b04a9..d9e817bfef 100644 --- a/test/config.test.js +++ b/test/config.test.js @@ -155,7 +155,7 @@ describe("the agent configuration", function () { idempotentEnv('NEW_RELIC_ERROR_COLLECTOR_IGNORE_ERROR_CODES', '401,404,502', function (tc) { should.exist(tc.error_collector.ignore_status_codes); - expect(tc.error_collector.ignore_status_codes).eql(['401', '404', '502']); + expect(tc.error_collector.ignore_status_codes).eql([401, 404, 502]); }); });