-
Notifications
You must be signed in to change notification settings - Fork 395
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
insights: added request_uri attribute to transaction and error events
- Loading branch information
Martin Kuba
committed
May 25, 2016
1 parent
4f7f25a
commit a4fdafe
Showing
29 changed files
with
681 additions
and
1,719 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
'use strict' | ||
|
||
exports.shallow = shallowCopy | ||
|
||
/** | ||
* Performs a shallow copy of all properties on the source object. | ||
* | ||
* @param {object} source - The object to copy the properties from. | ||
* @param {object} [dest={}] - The object to copy the properties to. | ||
* | ||
* @return {object} The destination object. | ||
*/ | ||
function shallowCopy(source, dest) { | ||
dest = dest || {} | ||
for (var k in source) { | ||
if (source.hasOwnProperty(k)) { | ||
dest[k] = source[k] | ||
} | ||
} | ||
return dest | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,97 @@ | ||
'use strict' | ||
|
||
var helper = require('../../lib/agent_helper') | ||
var path = require('path') | ||
var test = require('tap').test | ||
var configurator = require('../../../lib/config') | ||
var Agent = require('../../../lib/agent') | ||
|
||
test("Agent should send errors to staging-collector.newrelic.com", function (t) { | ||
var config = configurator.initialize({ | ||
'app_name': 'node.js Tests', | ||
'license_key': 'd67afc830dab717fd163bfcb0b8b88423e9a1a3b', | ||
'host': 'staging-collector.newrelic.com', | ||
'port': 80, | ||
'ssl': false, | ||
'utilization': { | ||
'detect_aws': false, | ||
'detect_docker': false | ||
}, | ||
'logging': { | ||
'level': 'trace' | ||
test('Agent#_sendErrors', function(t) { | ||
var config = { | ||
'app_name': 'node.js Tests', | ||
'license_key': 'd67afc830dab717fd163bfcb0b8b88423e9a1a3b', | ||
'host': 'staging-collector.newrelic.com', | ||
'port': 80, | ||
'ssl': false, | ||
'utilization': { | ||
'detect_aws': false, | ||
'detect_docker': false | ||
}, | ||
'logging': { | ||
'level': 'trace' | ||
} | ||
} | ||
|
||
t.test('without ssl', function(t) { | ||
config.port = 80 | ||
config.ssl = false | ||
var agent = setupAgent(t, config) | ||
_testSendErrors(t, agent) | ||
}) | ||
|
||
t.test('with ssl', function(t) { | ||
config.port = 443 | ||
config.ssl = true | ||
var agent = setupAgent(t, config) | ||
_testSendErrors(t, agent) | ||
}) | ||
|
||
function _testSendErrors(t, agent) { | ||
t.plan(6) | ||
|
||
agent.start(function(err) { | ||
if (!t.notOk(err, 'should connect without error')) { | ||
console.log('Connection error:', err) | ||
return t.end() | ||
} | ||
|
||
agent.collector.errorData = function(payload, cb) { | ||
// console.log('errorData', payload) | ||
if (!t.ok(payload, 'should get the payload')) { | ||
return cb() | ||
} | ||
}) | ||
var agent = new Agent(config) | ||
|
||
agent.start(function cb_start(error) { | ||
t.notOk(error, "connected without error") | ||
var errData = payload[1][0][4] | ||
if (!t.ok(errData, 'should contain error information')) { | ||
return cb() | ||
} | ||
|
||
var transaction | ||
var proxy = agent.tracer.transactionProxy(function cb_transactionProxy() { | ||
transaction = agent.getTransaction() | ||
transaction.setName('/nonexistent', 501) | ||
}) | ||
proxy() | ||
t.ok(transaction, "got a transaction") | ||
agent.errors.add(transaction, new Error('test error')) | ||
t.equal(errData.request_uri, '/nonexistent', 'should have request_uri') | ||
|
||
var attrs = errData.agentAttributes | ||
t.deepEqual(attrs, {foo: 'bar'}, 'should have the correct attributes') | ||
|
||
cb() | ||
} | ||
|
||
agent.on('transactionFinished', function(transaction) { | ||
agent._sendErrors(function(error) { | ||
if (!t.notOk(error, "sent errors without error")) { | ||
console.log('Send error:', error) | ||
} | ||
|
||
agent._sendErrors(function cb__sendErrors(error) { | ||
t.notOk(error, "sent errors without error") | ||
agent.stop(function(error) { | ||
t.notOk(error, "stopped without error") | ||
|
||
agent.stop(function cb_stop(error) { | ||
t.notOk(error, "stopped without error") | ||
t.end() | ||
}) | ||
}) | ||
}) | ||
|
||
t.end() | ||
helper.runInTransaction(agent, function(tx) { | ||
tx.setName('/nonexistent', 501) | ||
tx.addAgentAttribute('foo', 'bar') | ||
tx.addAgentAttribute('request_uri', '/nonexistent') | ||
agent.errors.add(tx, new Error('test error')) | ||
tx.end() | ||
}) | ||
}) | ||
}) | ||
} | ||
|
||
function setupAgent(t, config) { | ||
var agent = helper.loadMockedAgent({'send_request_uri_attribute': true}, config) | ||
t.tearDown(function() { | ||
helper.unloadAgent(agent) | ||
}) | ||
return agent | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.