From e5e89f2727e531ea753696bcb6307d421c652606 Mon Sep 17 00:00:00 2001 From: Grunet Date: Thu, 9 Jan 2025 21:04:25 -0600 Subject: [PATCH] Fix TS example for recording exceptions --- content/en/docs/languages/js/instrumentation.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/content/en/docs/languages/js/instrumentation.md b/content/en/docs/languages/js/instrumentation.md index ff6514fc1f20..a3f1b70ed0ca 100644 --- a/content/en/docs/languages/js/instrumentation.md +++ b/content/en/docs/languages/js/instrumentation.md @@ -1085,7 +1085,9 @@ import opentelemetry, { SpanStatusCode } from '@opentelemetry/api'; try { doWork(); } catch (ex) { - span.recordException(ex); + if (ex instanceof Error) { + span.recordException(ex); + } span.setStatus({ code: SpanStatusCode.ERROR }); } ``` @@ -1100,7 +1102,9 @@ const opentelemetry = require('@opentelemetry/api'); try { doWork(); } catch (ex) { - span.recordException(ex); + if (ex instanceof Error) { + span.recordException(ex); + } span.setStatus({ code: opentelemetry.SpanStatusCode.ERROR }); } ```