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
2 changes: 2 additions & 0 deletions docs/agent-api.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,8 @@ The optional `options` object can be used to log additional metadata with the er
For details see the <<metadata,metadata section>>.

The optional `callback` will be called after the error has been sent to the APM Server.
It will receive an `Error` instance if the agent failed to send the error,
and the id of the captured error.

[[message-strings]]
===== Message strings
Expand Down
4 changes: 3 additions & 1 deletion lib/agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,9 @@ Agent.prototype.captureError = function (err, opts, cb) {

function send (error) {
agent.logger.info('logging error %s with Elastic APM', id)
request.errors(agent, [error], cb)
request.errors(agent, [error], (err) => {
if (cb) cb(err, error.id)
})
}
}

Expand Down
6 changes: 4 additions & 2 deletions test/agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,12 @@ test('#flush()', function (t) {

test('#captureError()', function (t) {
t.test('with callback', function (t) {
t.plan(5)
t.plan(7)
APMServer()
.on('listening', function () {
this.agent.captureError(new Error('with callback'), function () {
this.agent.captureError(new Error('with callback'), function (err, id) {
t.error(err)
t.ok(/^[a-z0-9-]*$/i.test(id), 'has valid error.id')
t.ok(true, 'called callback')
t.end()
})
Expand Down