diff --git a/lib/agent.js b/lib/agent.js index bfde1b219a..71fb2c5df0 100644 --- a/lib/agent.js +++ b/lib/agent.js @@ -29,7 +29,10 @@ function Agent () { // Early configuration to ensure `agent.logger` works before `agent.start()`. this.logger = config.configLogger() - this._conf = null + // Get an initial pre-.start() configuration of agent defaults. This is a + // crutch for Agent APIs that depend on `agent._conf`. + this._conf = config.initialConfig(this.logger) + this._httpClient = null this._uncaughtExceptionListener = null this._inflightEvents = new InflightEventSet() diff --git a/lib/config.js b/lib/config.js index 8e40515684..1d75ac5710 100644 --- a/lib/config.js +++ b/lib/config.js @@ -246,6 +246,26 @@ function configLogger (opts) { return logging.createLogger(logLevel, customLogger) } +// Create an initial configuration from DEFAULTS. This is used as a stand-in +// for Agent configuration until `agent.start(...)` is called. +function initialConfig () { + const cfg = Object.assign({}, DEFAULTS) + + // Reproduce the generated properties for `Config`. + cfg.ignoreUrlStr = [] + cfg.ignoreUrlRegExp = [] + cfg.ignoreUserAgentStr = [] + cfg.ignoreUserAgentRegExp = [] + cfg.transactionIgnoreUrlRegExp = [] + cfg.sanitizeFieldNamesRegExp = [] + cfg.ignoreMessageQueuesRegExp = [] + normalize(cfg) + + cfg.transport = new NoopTransport() + + return cfg +} + function createConfig (opts, logger) { return new Config(opts, logger) } @@ -930,6 +950,7 @@ function getBaseClientConfig (conf, agent) { // Exports. module.exports = { configLogger, + initialConfig, createConfig, INTAKE_STRING_MAX_SIZE, CAPTURE_ERROR_LOG_STACK_TRACES_NEVER, diff --git a/test/agent.test.js b/test/agent.test.js index 12b0e1ff6f..dc1ea2a1ca 100644 --- a/test/agent.test.js +++ b/test/agent.test.js @@ -146,6 +146,13 @@ test('#setFramework()', function (t) { }) test('#startTransaction()', function (t) { + t.test('agent not yet started: startTransaction() should not crash', function (t) { + const agent = new Agent() // do not start the agent + agent.startTransaction('foo') + agent.destroy() + t.end() + }) + t.test('name, type, subtype and action', function (t) { const agent = new Agent().start(agentOptsNoopTransport) var trans = agent.startTransaction('foo', 'type', 'subtype', 'action')