From 9e10b4ec00bac1553d478360e5107c7b44e61510 Mon Sep 17 00:00:00 2001 From: rochdev Date: Thu, 22 Jun 2023 16:13:02 -0400 Subject: [PATCH] fix error handling for synchronous exceptions --- packages/datadog-instrumentations/src/http2/client.js | 6 +++--- packages/dd-trace/src/plugins/tracing.js | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) 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) } }