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

feat(utils): Prioritize Component name attributes over HTML Tree String #9496

Closed
wants to merge 20 commits into from

Conversation

0Calories
Copy link
Member

@0Calories 0Calories commented Nov 8, 2023

As part of an experimental initiative, add a wrapper function that will check for the data-component attribute on DOM nodes. If the attribute does not exist, it will fallback to the htmlTreeAsString function. This PR replaces all usages of htmlTreeAsString with the new getElementIdentifier function.

In the future, we will have a system that will, during build time, automatically annotate elements in the output DOM of an application with the original name of the component that it belongs to. This PR sets up the SDK to access this property when it is available, so that element identifiers throughout Sentry are comprehensible. This will affect the names of elements seen in multiple places within Sentry; breadcrumbs, replays, and tracing.

@0Calories 0Calories requested review from AbhiPrasad and a team November 8, 2023 21:01
@0Calories 0Calories self-assigned this Nov 8, 2023
@0Calories 0Calories requested review from ale-cota and removed request for a team November 8, 2023 21:01
Copy link
Contributor

github-actions bot commented Nov 8, 2023

size-limit report 📦

Path Size
@sentry/browser (incl. Tracing, Replay) - Webpack (gzipped) 65.46 KB (+0.08% 🔺)
@sentry/browser (incl. Tracing, Replay) - Webpack with treeshaking flags (gzipped) 55.67 KB (+0.09% 🔺)
@sentry/browser (incl. Tracing) - Webpack (gzipped) 31.02 KB (+0.13% 🔺)
@sentry/browser - Webpack (gzipped) 21.34 KB (+0.17% 🔺)
@sentry/browser (incl. Tracing, Replay) - ES6 CDN Bundle (gzipped) 61.99 KB (+0.07% 🔺)
@sentry/browser (incl. Tracing) - ES6 CDN Bundle (gzipped) 29.14 KB (+0.14% 🔺)
@sentry/browser - ES6 CDN Bundle (gzipped) 21.28 KB (+0.2% 🔺)
@sentry/browser (incl. Tracing, Replay) - ES6 CDN Bundle (minified & uncompressed) 195.53 KB (+0.06% 🔺)
@sentry/browser (incl. Tracing) - ES6 CDN Bundle (minified & uncompressed) 88.43 KB (+0.13% 🔺)
@sentry/browser - ES6 CDN Bundle (minified & uncompressed) 63.4 KB (+0.17% 🔺)
@sentry/browser (incl. Tracing) - ES5 CDN Bundle (gzipped) 31.85 KB (+0.13% 🔺)
@sentry/react (incl. Tracing, Replay) - Webpack (gzipped) 65.78 KB (+0.03% 🔺)
@sentry/react - Webpack (gzipped) 21.38 KB (+0.17% 🔺)
@sentry/nextjs Client (incl. Tracing, Replay) - Webpack (gzipped) 82.52 KB (+0.05% 🔺)
@sentry/nextjs Client - Webpack (gzipped) 48.16 KB (+0.06% 🔺)
@sentry-internal/feedback - Webpack (gzipped) 16.04 KB (+0.24% 🔺)

@AbhiPrasad AbhiPrasad requested a review from a team November 8, 2023 21:45
Comment on lines +156 to +157
? getElementIdentifier(event.target, { keyAttrs, maxStringLength })
: getElementIdentifier(event, { keyAttrs, maxStringLength });
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now, getElementIdentifier isn't doing anything with the options passed to it, except passing it to htmlTreeAsString if there is no data-component annotation available. Would we want to make use of any of those options, like maxStringLength on the annotated component names as well?

@0Calories 0Calories marked this pull request as ready for review November 9, 2023 20:13
@0Calories
Copy link
Member Author

Added some integration tests

Copy link
Member

@AbhiPrasad AbhiPrasad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From doing a search on https://github.com/search?q=data-component&type=code, it seems that data-component is set and used by a lot of frontends/librarys.

Should we use a different attribute? perhaps namescape it with sentry so it's a little more obvious what happens? data-sentry-component?

@0Calories
Copy link
Member Author

Good point @AbhiPrasad, for the time being do you think we could just put this code behind an experimental flag? Changing this would require forking the annotation plugin and adjusting the attribute names, but I just want to quickly get this in to validate the data internally.

When we make our own plugin for this later on, I'll make sure we use a distinct name to avoid these issues

0Calories added a commit to getsentry/sentry that referenced this pull request Nov 15, 2023
Updates the frontend SDK version to 7.80.2-alpha.1, this version of the
SDK will pick off the values in the DOM labelled as `data-component` so
we can start seeing them internally and validate the product experience.
However, this change is avoided for the Replay SDKs, as it would cause
searching by CSS selector to no longer work.

SDK PR: getsentry/sentry-javascript#9496
@@ -4,6 +4,14 @@

- "You miss 100 percent of the chances you don't take. — Wayne Gretzky" — Michael Scott

## 7.80.2-alpha.1

No longer will prioritize the component names for replays, as this will break searching by CSS selector.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the long term plan for replays then? Don't we need this change for them also?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AbhiPrasad Had to put replays aside for the sake of the experiment, but there are a few things we will need to include in the backend and SDK to support it. I'll have a document ready with more details later

@0Calories
Copy link
Member Author

0Calories commented Dec 15, 2023

Closing this PR, I've experimented with this in an alpha release of the SDK and iterated on it by making a new PR with some improvements:

#9855

@0Calories 0Calories closed this Dec 15, 2023
@0Calories 0Calories deleted the feat/prioritize-component-name branch August 29, 2024 15:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants