Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Supportability of the Lit framework #11445

Discussion options

Problem Statement

Some customers have been using the https://lit.dev/ framework and are forced to use the Javascript SDK as we don't have a SDK for this.

This can also create some gaps as there is no Automatic instrumentation for Performance for Lit in specific.

Solution Brainstorm

https://lit.dev/

┆Issue is synchronized with this Jira Improvement by Unito

You must be logged in to vote

Replies: 2 comments 8 replies

Comment options

Hey @Angelodaniel I'm gonna convert this to a discussion for the moment because that's how we track currently unsupported frameworks.

That being said, it'd be great to find out more where our @sentry/browser SDK currently has shortcomings for Lit. For instance: Do we need a custom routing instrumentation for a client-side router? Are errors not getting caught correctly?
Appreciate feedback from anyone following this issue/discussion.

You must be logged in to vote
5 replies
Comment options

Angelodaniel Apr 5, 2024
Collaborator Author

I'll come back on the gaps or feature requests in specific

Comment options

Looking at the other sentry libs for JS frontend frameworks it looks like they are all hooking into their frameworks respective routers. The "react" lib is in fact the "react router" library, if I'm. reading the docs correctly. Conversely lit doesn't have a de facto router, there's one under the "lit-labs" scope but that means that it's not ready for production yet.

Comment options

Angelodaniel Apr 15, 2024
Collaborator Author

They currently have browserTracingIntegration set in the Sentry initialisation. That's been working great but they aren't sending any SPA navigations from the app. Since they are using Lit and their own custom router (lit doesn't have a production ready canonical router) they tried previously setting up custom routing via: https://docs.sentry.io/platforms/javascript/performance/instrumentation/automatic-instrumentation/#custom-routing. This ended up dropping all the performance instrumentation, possibly because we couldn't get the startBrowserTracingPageLoadSpan function called early enough in the apps lifecycle.

So might be worth looking into to see what we can already do

Comment options

Is there any example code available of how other routers are integrated with sentry?

Comment options

Here's react router!

export function reactRouterV3BrowserTracingIntegration(

Here is vue:

export function browserTracingIntegration(options: VueBrowserTracingIntegrationOptions = {}): Integration {
// If router is not passed, we just use the normal implementation
if (!options.router) {
return originalBrowserTracingIntegration(options);
}
const integration = originalBrowserTracingIntegration({
...options,
instrumentNavigation: false,
});
const { router, instrumentNavigation = true, instrumentPageLoad = true, routeLabel = 'name' } = options;
return {
...integration,
afterAllSetup(client) {
integration.afterAllSetup(client);
const startNavigationSpan = (options: StartSpanOptions): void => {
startBrowserTracingNavigationSpan(client, options);
};
instrumentVueRouter(router, { routeLabel, instrumentNavigation, instrumentPageLoad }, startNavigationSpan);
},
};
}
Comment options

Angelodaniel
Apr 24, 2025
Collaborator Author

Hey Team, I'm working on a Single page app where there are multiple Lit framework components which show up "nameless". We have some long ui tasks that we want to try and correlate to these components so it's more obvious that Component A is responsible for the Long UI task.
What would be the best way to instrument those?
See Notion case for Customer specific context - Here

@timfish mentioned: I was going to suggest how to instrument the callbacks but it sounds like you're already doing that!
It does sound like the issues they’re having are due to the lack of async context in the browser. We can’t link up spans across async await

You must be logged in to vote
3 replies
Comment options

To add onto this discussion a little bit: creating the spans isn't necessarily a problem, since we can manually create inactiveSpans and start/close them in different Lit callbacks. The problem is the async loading of (sub-)components and actually knowing when all sub-components of one parent are fully loaded. We have tried looking into waiting for all child components' updateComplete callback as follows:

async getUpdateComplete() {
 // Wait for updateComplete from this component first
 await super.getUpdateComplete();
 // Find all Lit children in the shadow DOM
 const childComponents = Array.from(this.shadowRoot.querySelectorAll('*'))
 .filter(el => el instanceof LitElement); // Alleen LitElement instances
 // Wait for updateComplete from all children
 await Promise.all(childComponents.map(child => child.updateComplete));
 // Return true to indicate updateComplete
 return true;
}

Unfortunately this didn't work since in our specific case the sub-components are rendered conditionally, they do not exist in the shadow DOM for a while when loading the component / when checking in the parent's lifecycle callbacks. This again leads us to unusable Sentry spans (i.e. the manually created span is already closed before the Long UI Task in the trace). The only way I found to (semi-)reliably check if all sub-components are loaded is with a MutationObserver:

// Set up the MutationObserver
this.observer = new MutationObserver((mutations) => {
 mutations.forEach(() => {
 this._lastObservation = performance.now();
 this._observerIdle = false;
 });
});
// Start observing the component's shadow DOM
this.observer.observe(this.shadowRoot, { childList: true, subtree: true });
this.checkObserverIdle = setInterval(() => {
 if (this._observerIdle) {
 clearInterval(this.checkObserverIdle);
 } else {
 this._observerIdle = true;
 }
}, this._idleInterval);

However, I can imagine this is not the most appropriate approach when you have tons of separate components on a Single Page App.

Comment options

I wonder if https://developer.mozilla.org/en-US/docs/Web/API/Element/elementTiming can be leveraged here. It does have a restriction in the kind of elements it supports though unfortunately.

Comment options

Angelodaniel Jun 3, 2025
Collaborator Author

Hey @AbhiPrasad -> I managed to setup a test app https://github.com/Angelodaniel/lit-components-custom-instrumentation
"The InstrumentedLitElement uses both a MutationObserver and recursive updateComplete checks to ensure spans only end when the entire subtree is rendered." is this something that we can review? I didn't see any other options for now.
Seems this is what we need: lit/lit#3538

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Improvement Sync: Jira apply to auto-create a Jira shadow ticket
Converted from issue

This discussion was converted from issue #11444 on April 05, 2024 09:34.

AltStyle によって変換されたページ (->オリジナル) /