Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
21 changes: 21 additions & 0 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -930,6 +950,7 @@ function getBaseClientConfig (conf, agent) {
// Exports.
module.exports = {
configLogger,
initialConfig,
createConfig,
INTAKE_STRING_MAX_SIZE,
CAPTURE_ERROR_LOG_STACK_TRACES_NEVER,
Expand Down
7 changes: 7 additions & 0 deletions test/agent.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down