Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added transaction ID to ErrorTrace event #1954

Merged
6 changes: 5 additions & 1 deletion lib/errors/index.js
Expand Up @@ -67,7 +67,8 @@ class Exception {
* [1] -> name extracted from error info,
* [2] -> extracted error message,
* [3] -> extracted error type,
* [4] -> attributes
* [4] -> attributes,
* [5] -> transaction id
*/
function createError(transaction, exception, config) {
const error = exception.error
Expand Down Expand Up @@ -111,6 +112,9 @@ function createError(transaction, exception, config) {

maybeAddAgentAttributes(params, exception)

if (transaction?.id) {
svetlanabrennan marked this conversation as resolved.
Show resolved Hide resolved
return [0, name, message, type, params, transaction.id]
}
return [0, name, message, type, params]
}

Expand Down
2 changes: 1 addition & 1 deletion test/unit/api/api-set-user-id.test.js
Expand Up @@ -63,7 +63,7 @@ tap.test('Agent API = set user id', (t) => {
api.setUserID(id)
const exception = new Exception(new Error('Test error.'))
const [...data] = createError(tx, exception, agent.config)
const params = data.pop()
const params = data[data.length - 2]
svetlanabrennan marked this conversation as resolved.
Show resolved Hide resolved
t.equal(params.agentAttributes['enduser.id'], id, 'should set enduser.id attribute on error')
t.end()
})
Expand Down
123 changes: 123 additions & 0 deletions test/unit/errors/error-collector.test.js
Expand Up @@ -199,6 +199,82 @@ tap.test('Errors', (t) => {
})
})

t.test('transaction id with distributed tracing enabled', (t) => {
t.autoend()
let errorJSON
let transaction
let error

t.beforeEach(() => {
agent.config.distributed_tracing.enabled = true
error = new Error('this is an error')
})

t.test('should have a transaction id when there is a transaction', (t) => {
transaction = new Transaction(agent)

agent.errors.add(transaction, error)
agent.errors.onTransactionFinished(transaction)

const errorTraces = getErrorTraces(agent.errors)
errorJSON = errorTraces[0]

const transactionId = errorJSON[5]
t.not(transactionId, undefined)
transaction.end()
t.end()
})

t.test('should not have a transaction id when there is no transaction', (t) => {
agent.errors.add(null, error)

const errorTraces = getErrorTraces(agent.errors)
errorJSON = errorTraces[0]

const transactionId = errorJSON[5]
t.notOk(transactionId)
t.end()
})
})

t.test('transaction id with distributed tracing disabled', (t) => {
t.autoend()
let errorJSON
let transaction
let error

t.beforeEach(() => {
agent.config.distributed_tracing.enabled = false
error = new Error('this is an error')
})

t.test('should have a transaction id when there is a transaction', (t) => {
transaction = new Transaction(agent)

agent.errors.add(transaction, error)
agent.errors.onTransactionFinished(transaction)

const errorTraces = getErrorTraces(agent.errors)
errorJSON = errorTraces[0]

const transactionId = errorJSON[5]
t.not(transactionId, undefined)
svetlanabrennan marked this conversation as resolved.
Show resolved Hide resolved
transaction.end()
t.end()
})

t.test('should not have a transaction id when there is no transaction', (t) => {
agent.errors.add(null, error)

const errorTraces = getErrorTraces(agent.errors)
errorJSON = errorTraces[0]

const transactionId = errorJSON[5]
t.notOk(transactionId)
t.end()
})
})

t.test('display name', (t) => {
t.autoend()
const PARAMS = 4
Expand Down Expand Up @@ -667,6 +743,17 @@ tap.test('Errors', (t) => {
t.notHas(params, 'stack_trace')
t.end()
})

t.test('should have a transaction id', (t) => {
const transactionId = errorJSON[5]
t.not(transactionId, undefined)
svetlanabrennan marked this conversation as resolved.
Show resolved Hide resolved
t.end()
})

t.test('should have 6 elements in errorJson', (t) => {
t.equal(errorJSON.length, 6)
t.end()
})
})

t.test('with transaction agent attrs, status code, and no error', (t) => {
Expand Down Expand Up @@ -721,6 +808,12 @@ tap.test('Errors', (t) => {
t.end()
})

t.test('should have a transaction id', (t) => {
const transactionId = errorJSON[5]
t.not(transactionId, undefined)
t.end()
})

t.test('should not have a request URL', (t) => {
t.notOk(params['request.uri'])
t.end()
Expand Down Expand Up @@ -826,6 +919,12 @@ tap.test('Errors', (t) => {
t.equal(params.stack_trace[0], 'Error: Dare to be the same!')
t.end()
})

t.test('should not have a transaction id', (t) => {
const transactionId = errorJSON[5]
t.notOk(transactionId)
t.end()
})
})

t.test('with a thrown TypeError and a transaction with no params', (t) => {
Expand Down Expand Up @@ -878,6 +977,12 @@ tap.test('Errors', (t) => {
t.equal(params.stack_trace[0], 'TypeError: Dare to be different!')
t.end()
})

t.test('should have a transaction id', (t) => {
const transactionId = errorJSON[5]
t.not(transactionId, undefined)
svetlanabrennan marked this conversation as resolved.
Show resolved Hide resolved
t.end()
})
})

t.test('with a thrown `TypeError` and a transaction with agent attrs', (t) => {
Expand Down Expand Up @@ -935,6 +1040,12 @@ tap.test('Errors', (t) => {
t.end()
})

t.test('should have a transaction id', (t) => {
const transactionId = errorJSON[5]
t.not(transactionId, undefined)
t.end()
})

t.test('should not have a request URL', (t) => {
t.notOk(params['request.uri'])
t.end()
Expand Down Expand Up @@ -999,6 +1110,12 @@ tap.test('Errors', (t) => {
t.notHas(errorJSON[4], 'stack_trace')
t.end()
})

t.test('should have a transaction id', (t) => {
const transactionId = errorJSON[5]
t.not(transactionId, undefined)
t.end()
})
})

t.test('with a thrown string and a transaction with agent parameters', (t) => {
Expand Down Expand Up @@ -1056,6 +1173,12 @@ tap.test('Errors', (t) => {
t.end()
})

t.test('should have a transaction id', (t) => {
const transactionId = errorJSON[5]
t.not(transactionId, undefined)
t.end()
})

t.test('should not have a request URL', (t) => {
t.notOk(params['request.uri'])
t.end()
Expand Down
2 changes: 1 addition & 1 deletion test/versioned/connect/error-intercept.tap.js
Expand Up @@ -74,7 +74,7 @@ test('intercepting errors with connect 2', function (t) {
t.equal(errors.length, 1, 'the error got traced')

const error = errors[0]
t.equal(error.length, 5, 'format for traced error is correct')
t.equal(error.length, 6, 'format for traced error is correct')
t.equal(error[3], 'TypeError', 'got the correct class for the error')

server.close()
Expand Down