From 2a7adab6c3d82cf3fafbeba184014502c12e288d Mon Sep 17 00:00:00 2001 From: Wolfgang Therrien Date: Tue, 22 Oct 2024 11:10:39 -0400 Subject: [PATCH] fix(honeycomb-opentelemetry-web): Add check for lcpEntry.element (#342) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Which problem is this PR solving? Sometimes `lcpEntry.element` is null or undefined, this check prevents an `Cannot read properties of undefined (reading 'dataset')` error. ## How to verify that this has the expected result --- .../src/web-vitals-autoinstrumentation.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/honeycomb-opentelemetry-web/src/web-vitals-autoinstrumentation.ts b/packages/honeycomb-opentelemetry-web/src/web-vitals-autoinstrumentation.ts index 5efaba97..2fa84ec9 100644 --- a/packages/honeycomb-opentelemetry-web/src/web-vitals-autoinstrumentation.ts +++ b/packages/honeycomb-opentelemetry-web/src/web-vitals-autoinstrumentation.ts @@ -483,7 +483,7 @@ export class WebVitalsInstrumentation extends InstrumentationAbstract { }); const el: HTMLElement = lcpEntry?.element as HTMLElement; - if (el.dataset) { + if (el?.dataset) { for (const attrName in el.dataset) { const attrValue = el.dataset[attrName]; if (