From f65f2f1482f6f9ca80681f09249dc2b75ef7e3db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?San=20M=C3=B4nico?= Date: Thu, 18 Jan 2024 14:49:03 -0300 Subject: [PATCH] fix: span emit warnings on express instrumentation (#1891) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes Can not execute the operation on ended Span on express-instrumentation #1887 This checks if the span has ended before attemptuing to mutate it by calling span.recordException(...) and span.setStatus(...) Signed-off-by: San 'rdn' Mônico Co-authored-by: Jamie Danielson --- .../src/instrumentation.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/node/opentelemetry-instrumentation-express/src/instrumentation.ts b/plugins/node/opentelemetry-instrumentation-express/src/instrumentation.ts index 46fd4cc0ff..bb29f52cbf 100644 --- a/plugins/node/opentelemetry-instrumentation-express/src/instrumentation.ts +++ b/plugins/node/opentelemetry-instrumentation-express/src/instrumentation.ts @@ -280,7 +280,7 @@ export class ExpressInstrumentation extends InstrumentationBase< const isError = ![undefined, null, 'route', 'router'].includes( maybeError ); - if (isError) { + if (!spanHasEnded && isError) { const [error, message] = asErrorAndMessage(maybeError); span.recordException(error); span.setStatus({