Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: This code duplicated not needed. #329

Merged
merged 1 commit into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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}`,
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
});
Expand Down
Loading