-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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(vue): Update Vue trackComponents
list to match components with or without <>
#13543
Merged
Lms24
merged 5 commits into
getsentry:develop
from
Zen-cronic:fix/trackComponents-allowList
Sep 9, 2024
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
10bc596
fix(vue): Update Vue `trackComponents` list to match components with …
Zen-cronic 2c67d73
test(vue): Add unit test for `findTrackComponent` function
Zen-cronic e7bc6a3
test(vue): Add e2e test cases for trackComponents span
Zen-cronic 8f48f36
fix(vue): Remove extra angle bracket in component span description
Zen-cronic ab13a0b
test(vue): Add new route for trackComponent tests
Zen-cronic 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 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 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
10 changes: 10 additions & 0 deletions
10
dev-packages/e2e-tests/test-applications/vue-3/src/views/ComponentMainView.vue
This file contains 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,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> | ||
10 changes: 10 additions & 0 deletions
10
dev-packages/e2e-tests/test-applications/vue-3/src/views/ComponentOneView.vue
This file contains 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,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> |
10 changes: 10 additions & 0 deletions
10
dev-packages/e2e-tests/test-applications/vue-3/src/views/ComponentTwoView.vue
This file contains 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,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> |
This file contains 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 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 |
---|---|---|
|
@@ -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'); | ||
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. 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', | ||
|
This file contains 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,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); | ||
}); | ||
}); | ||
}); |
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.
Inspired by the sveltekit-2-svelte-5 test setup.