Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1.8k
fix(vue): Update Vue trackComponents list to match components with or without <>#13543
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
10bc5962c67d73e7bc6a38f48f36ab13a0bFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| <script setup lang="ts"> | ||
| import ComponentOneView from './ComponentOneView.vue'; | ||
| import ComponentTwoView from './ComponentTwoView.vue'; | ||
| </script> | ||
| <template> | ||
| <h1>Demonstrating Component Tracking</h1> | ||
| <ComponentOneView /> | ||
| <ComponentTwoView /> | ||
| </template> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| <script setup lang="ts"> | ||
| function log() { | ||
| console.log('Component One!'); | ||
| } | ||
| </script> | ||
| <template> | ||
| <h1>Component One</h1> | ||
| <button id="componentOneBtn" @click="log">Click to Log</button> | ||
| </template> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| <script setup lang="ts"> | ||
| function log() { | ||
| console.log('Component Two!'); | ||
| } | ||
| </script> | ||
| <template> | ||
| <h1>Component One</h1> | ||
| <button id="componentTwoBtn" @click="log">Click to Log</button> | ||
| </template> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -46,6 +46,19 @@ function finishRootSpan(vm: VueSentry, timestamp: number, timeout: number): void | ||
| }, timeout); | ||
| } | ||
| /** Find if the current component exists in the provided `TracingOptions.trackComponents` array option. */ | ||
| export function findTrackComponent(trackComponents: string[], formattedName: string): boolean { | ||
| function extractComponentName(name: string): string { | ||
| return name.replace(/^<([^\s]*)>(?: at [^\s]*)?$/, '$1'); | ||
ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Based on what you suggested @Lms24, just an added non-capture group. The ReDoS Checker passes. Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds good to me, thanks! | ||
| } | ||
| const isMatched = trackComponents.some(compo => { | ||
| return extractComponentName(formattedName) === extractComponentName(compo); | ||
| }); | ||
| return isMatched; | ||
| } | ||
| export const createTracingMixins = (options: TracingOptions): Mixins => { | ||
| const hooks = (options.hooks || []) | ||
| .concat(DEFAULT_HOOKS) | ||
| @@ -84,8 +97,9 @@ export const createTracingMixins = (options: TracingOptions): Mixins => { | ||
| // Skip components that we don't want to track to minimize the noise and give a more granular control to the user | ||
| const name = formatComponentName(this, false); | ||
| const shouldTrack = Array.isArray(options.trackComponents) | ||
| ? options.trackComponents.indexOf(name) > -1 | ||
| ? findTrackComponent(options.trackComponents, name) | ||
| : options.trackComponents; | ||
| // We always want to track root component | ||
| @@ -109,7 +123,7 @@ export const createTracingMixins = (options: TracingOptions): Mixins => { | ||
| } | ||
| this.$_sentrySpans[operation] = startInactiveSpan({ | ||
| name: `Vue <${name}>`, | ||
| name: `Vue ${name}`, | ||
| op: `${VUE_OP}.${operation}`, | ||
| attributes: { | ||
| [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.ui.vue', | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| import { describe, expect, it } from 'vitest'; | ||
| import { findTrackComponent } from '../../src/tracing'; | ||
| describe('findTrackComponent', () => { | ||
| describe('when user-defined array contains `<Component>`', () => { | ||
| it('returns true if a match is found', () => { | ||
| // arrange | ||
| const trackComponents = ['<ABC>', '<XYZ>']; | ||
| const formattedComponentName = '<XYZ>'; | ||
| // act | ||
| const shouldTrack = findTrackComponent(trackComponents, formattedComponentName); | ||
| // assert | ||
| expect(shouldTrack).toBe(true); | ||
| }); | ||
| }); | ||
| describe('when user-defined array contains `Component` without the `<>`', () => { | ||
| it('returns true if a match is found', () => { | ||
| // arrange | ||
| const trackComponents = ['ABC', 'XYZ']; | ||
| const formattedComponentName = '<XYZ>'; | ||
| // act | ||
| const shouldTrack = findTrackComponent(trackComponents, formattedComponentName); | ||
| // assert | ||
| expect(shouldTrack).toBe(true); | ||
| }); | ||
| }); | ||
| describe('when the vue file name is include in the formatted component name', () => { | ||
| it('returns true if a match is found', () => { | ||
| // arrange | ||
| const trackComponents = ['ABC', 'XYZ']; | ||
| const formattedComponentName = '<XYZ> at XYZ.vue'; | ||
| // act | ||
| const shouldTrack = findTrackComponent(trackComponents, formattedComponentName); | ||
| // assert | ||
| expect(shouldTrack).toBe(true); | ||
| }); | ||
| }); | ||
| }); |
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.
Inspired by the sveltekit-2-svelte-5 test setup.