From 5a07bd420787208f35af2d7202a543a8f83640b8 Mon Sep 17 00:00:00 2001 From: Wolfgang Therrien Date: Wed, 16 Oct 2024 11:58:44 -0400 Subject: [PATCH] Use include, remove undeeded code. --- .../src/web-vitals-autoinstrumentation.ts | 12 +----------- .../test/web-vitals-instrumentation.test.ts | 4 ++-- 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/packages/honeycomb-opentelemetry-web/src/web-vitals-autoinstrumentation.ts b/packages/honeycomb-opentelemetry-web/src/web-vitals-autoinstrumentation.ts index c2bec534..5efaba97 100644 --- a/packages/honeycomb-opentelemetry-web/src/web-vitals-autoinstrumentation.ts +++ b/packages/honeycomb-opentelemetry-web/src/web-vitals-autoinstrumentation.ts @@ -492,7 +492,7 @@ export class WebVitalsInstrumentation extends InstrumentationAbstract { // dataAttributes is undefined (i.e. send all values as span attributes) OR (dataAttributes === undefined || // dataAttributes is specified AND attrName is in dataAttributes (i.e attribute name is in the supplied allowList) - (dataAttributes && attrName in dataAttributes)) + dataAttributes.includes(attrName)) ) { span.setAttribute( `${attrPrefix}.element.data.${attrName}`, @@ -501,16 +501,6 @@ export class WebVitalsInstrumentation extends InstrumentationAbstract { } } } - if (dataAttributes) - dataAttributes?.forEach((attrName) => { - const attrValue = el.dataset[attrName]; - if (attrValue !== undefined) { - span.setAttribute( - `${attrPrefix}.element.data.${attrName}`, - attrValue, - ); - } - }); if (applyCustomAttributes) { applyCustomAttributes(lcp, span); diff --git a/packages/honeycomb-opentelemetry-web/test/web-vitals-instrumentation.test.ts b/packages/honeycomb-opentelemetry-web/test/web-vitals-instrumentation.test.ts index 932c9b00..130e2aca 100644 --- a/packages/honeycomb-opentelemetry-web/test/web-vitals-instrumentation.test.ts +++ b/packages/honeycomb-opentelemetry-web/test/web-vitals-instrumentation.test.ts @@ -434,8 +434,8 @@ describe('Web Vitals Instrumentation Tests', () => { expect(exporter.getFinishedSpans().length).toEqual(1); const span = exporter.getFinishedSpans()[0]; expect(span.attributes['lcp.element.data.answer']).toEqual('42'); - expect(span.attributes['lcp.element.famousCats']).toBeUndefined(); - expect(span.attributes['lcp.element.hasCats']).toBeUndefined(); + expect(span.attributes['lcp.element.data.famousCats']).toBeUndefined(); + expect(span.attributes['lcp.element.data.hasCats']).toBeUndefined(); expect(span.attributes).toMatchObject({ 'lcp.element.data.answer': '42', });