Skip to content

Commit dd89b92

Browse files
Qardwatson
authored andcommitted
feat(agent): return uuid in captureError callback (#636)
Fixes #573
1 parent 008277d commit dd89b92

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

docs/agent-api.asciidoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -847,6 +847,8 @@ The optional `options` object can be used to log additional metadata with the er
847847
For details see the <<metadata,metadata section>>.
848848

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

851853
[[message-strings]]
852854
===== Message strings

lib/agent.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,9 @@ Agent.prototype.captureError = function (err, opts, cb) {
286286

287287
function send (error) {
288288
agent.logger.info('logging error %s with Elastic APM', id)
289-
request.errors(agent, [error], cb)
289+
request.errors(agent, [error], (err) => {
290+
if (cb) cb(err, error.id)
291+
})
290292
}
291293
}
292294

test/agent.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,10 +260,12 @@ test('#flush()', function (t) {
260260

261261
test('#captureError()', function (t) {
262262
t.test('with callback', function (t) {
263-
t.plan(5)
263+
t.plan(7)
264264
APMServer()
265265
.on('listening', function () {
266-
this.agent.captureError(new Error('with callback'), function () {
266+
this.agent.captureError(new Error('with callback'), function (err, id) {
267+
t.error(err)
268+
t.ok(/^[a-z0-9-]*$/i.test(id), 'has valid error.id')
267269
t.ok(true, 'called callback')
268270
t.end()
269271
})

0 commit comments

Comments
 (0)