diff --git a/packages/datadog-instrumentations/src/http2/client.js b/packages/datadog-instrumentations/src/http2/client.js index d91cea4e1d5..e5a3cd9f4ad 100644 --- a/packages/datadog-instrumentations/src/http2/client.js +++ b/packages/datadog-instrumentations/src/http2/client.js @@ -33,11 +33,11 @@ function createWrapRequest (authority, options) { const ctx = { headers, authority, options } return startChannel.runStores(ctx, () => { - const req = request.apply(this, arguments) + try { + const req = request.apply(this, arguments) - shimmer.wrap(req, 'emit', createWrapEmit(ctx)) + shimmer.wrap(req, 'emit', createWrapEmit(ctx)) - try { return req } catch (e) { ctx.error = e diff --git a/packages/dd-trace/src/plugins/tracing.js b/packages/dd-trace/src/plugins/tracing.js index e585b1290d0..5ccdedb1e4f 100644 --- a/packages/dd-trace/src/plugins/tracing.js +++ b/packages/dd-trace/src/plugins/tracing.js @@ -84,6 +84,8 @@ class TracingPlugin extends Plugin { const span = this.activeSpan if (!span._spanContext._tags['error']) { + // Errors may be wrapped in a context. + error = (error && error.error) || error span.setTag('error', error || 1) } }