-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat(vue,nuxt): Record default UI spans without Options API (mixins) #24174
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
Open
s1gr1d
wants to merge
2
commits into
develop
Choose a base branch
from
sig/add-alternative-mixin-implementation
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
dev-packages/e2e-tests/test-applications/vue-3/src/views/DelayedView.vue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| <script setup lang="ts"> | ||
| import type { Component } from 'vue'; | ||
| import { defineAsyncComponent, h } from 'vue'; | ||
|
|
||
| // Must stay in sync with `ASYNC_CHILD_DELAY_S` in `tests/performance.test.ts`. | ||
| const ASYNC_CHILD_DELAY_MS = 300; | ||
|
|
||
| // A child that mounts a fixed delay after the rest of the page, so tests can prove the | ||
| // `Application Render` span does not wait for late children on either instrumentation path. | ||
| const DelayedChild = defineAsyncComponent( | ||
| () => | ||
| new Promise<Component>(resolve => { | ||
| setTimeout( | ||
| () => resolve({ render: () => h('p', { id: 'delayed-child' }, 'Delayed child') }), | ||
| ASYNC_CHILD_DELAY_MS, | ||
| ); | ||
| }), | ||
| ); | ||
| </script> | ||
|
|
||
| <template> | ||
| <main> | ||
| <h1>Delayed</h1> | ||
| <DelayedChild /> | ||
| </main> | ||
| </template> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,6 @@ | ||
| import type { Operation } from './types'; | ||
|
|
||
| export const DEFAULT_HOOKS: Operation[] = ['activate', 'mount']; | ||
|
|
||
| /** How long the root render span waits for further render activity before it ends. */ | ||
| export const DEFAULT_ROOT_SPAN_TIMEOUT = 2000; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| import { timestampInSeconds } from '@sentry/core'; | ||
| import type { Mixins, VueSentry } from './tracing'; | ||
| import { maybeEndRootComponentSpan } from './tracing'; | ||
| import type { Vue } from './types'; | ||
|
|
||
| interface RootInstrumentation { | ||
| vm: VueSentry; | ||
| timeout: number; | ||
| } | ||
|
|
||
| const instrumentedApps = new WeakMap<Vue, RootInstrumentation>(); | ||
|
|
||
| /** | ||
| * The mixin hooks only check `$root === this` to detect the root component, so a self-referential | ||
| * stand-in works in place of the real instance, which does not exist yet at wrap time. | ||
| */ | ||
| function createRootViewModel(): VueSentry { | ||
| const vm: { $root?: unknown; $props: Record<string, unknown> } = { $props: {} }; | ||
| vm.$root = vm; | ||
| return vm as unknown as VueSentry; | ||
| } | ||
|
|
||
| /** | ||
| * Records the `Application Render` and root component mount spans by wrapping `app.mount()`, for | ||
| * builds where the Options API is compiled out and `app.mixin()` is a silent no-op (Nuxt 5 default). | ||
| * | ||
| * Vue runs all `mounted` hooks before `mount()` returns, so the wrap covers the same window as the | ||
| * mixin's root hooks. Late mounts extend neither path; the mixin's debounce timers are per component. | ||
| */ | ||
| export function instrumentAppMountWithoutMixin(app: Vue, mixins: Mixins, timeout: number): void { | ||
| // A second wrap would duplicate the root spans (e.g. user and Nuxt SDK both add the integration). | ||
| if (instrumentedApps.has(app)) { | ||
| return; | ||
| } | ||
|
|
||
| const appWithMount = app as Vue & { mount?: (...args: unknown[]) => unknown }; | ||
| const originalMount = appWithMount.mount; | ||
| // Guards odd app-like objects; Vue 2 constructors lack `mount` but never get here (their `app.mixin()` works). | ||
| if (typeof originalMount !== 'function') { | ||
| return; | ||
| } | ||
|
|
||
| const vm = createRootViewModel(); | ||
| instrumentedApps.set(app, { vm, timeout }); | ||
|
|
||
| // `createTracingMixins` always merges `DEFAULT_HOOKS`, so the `mount` pair exists. | ||
| const mountHooks = mixins as Partial<Record<'beforeMount' | 'mounted', (this: VueSentry) => void>>; | ||
|
|
||
| appWithMount.mount = function (...args: unknown[]): unknown { | ||
| mountHooks.beforeMount?.call(vm); | ||
| try { | ||
| return originalMount.apply(this, args); | ||
| } finally { | ||
| // Also runs when mounting throws, so the started root component span always ends. | ||
| mountHooks.mounted?.call(vm); | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
| * Extends the debounce that ends the `Application Render` span, so framework SDKs can report | ||
| * render activity the root cannot see (e.g. Nuxt's `<Suspense>` resolving). No-op on the mixin | ||
| * path and after the span has ended. | ||
| * | ||
| * @internal Exported for the Sentry Nuxt SDK, not part of the stable public API. | ||
| * @experimental May change or be removed in any release. | ||
| */ | ||
| export function INTERNAL_extendVueRootRenderSpan(app: Vue): void { | ||
| const instrumentation = instrumentedApps.get(app); | ||
| const span = instrumentation?.vm.$_sentryRootComponentSpan; | ||
| // No span: mixin path, or the debounce already ended it. | ||
| if (!instrumentation || !span) { | ||
| return; | ||
| } | ||
|
|
||
| if (span.isRecording()) { | ||
| maybeEndRootComponentSpan(instrumentation.vm, timestampInSeconds(), instrumentation.timeout); | ||
| } else { | ||
| // Ended externally, e.g. by a navigation cancelling the pageload. Drop the stale reference. | ||
| instrumentation.vm.$_sentryRootComponentSpan = undefined; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
page:finish reopens root render span
Medium Severity
page:finishruns on every client navigation, andINTERNAL_extendVueRootRenderSpanonly no-ops after$_sentryRootComponentSpanis cleared. A navigation inside the debounce window still sees that span, resets the timer, and movesApplication Render's end timestamp onto the next page. Fast clicks andnavigateToredirects inflate the pageload child and can end it after the pageload parent.Additional Locations (1)
packages/vue/src/rootInstrumentation.ts#L69-L73Reviewed by Cursor Bugbot for commit 7b3c0ee. Configure here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not reproducible, but hardened anyway (and added a test).
A navigation ends the pageload idle span before the next page's
page:finishfires.
What was true: the guard only checked that the span reference exists, so the first post-navigation
page:finisharmed one dead timer. It now checksspan.isRecording()and drops stale references, with a regression test.