-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Changes from 1 commit
10bc596
2c67d73
e7bc6a3
8f48f36
ab13a0b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -46,6 +46,20 @@ function finishRootSpan(vm: VueSentry, timestamp: number, timeout: number): void | |||||||||||||||
}, timeout); | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
// Find if the current component exists in the provided `TracingOptions.trackComponents` array option. | ||||||||||||||||
function findTrackComponent(trackComponents: string[], formattedName: string): boolean { | ||||||||||||||||
const isMatched = trackComponents.some(compo => { | ||||||||||||||||
let currentCompo = compo; | ||||||||||||||||
|
||||||||||||||||
if (!(currentCompo.startsWith('<') && currentCompo.endsWith('>'))) { | ||||||||||||||||
currentCompo = `<${currentCompo}>`; | ||||||||||||||||
} | ||||||||||||||||
return formattedName === currentCompo; | ||||||||||||||||
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. I think we can replace this with a more bundle size efficient version:
Suggested change
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. Ah in this case we don't even need the block anymore but could inline it to the 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. Noted 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. hey, I've taken your approach and found that function findTrackComponent(trackComponents: string[], formattedName: string): boolean {
function extractComponentName(name: string): string {
return name.replace(/^<(.*)>(?:.*)?$/, "$1");
}
const isMatched = trackComponents.some(compo => {
return extractComponentName(formattedName) === extractComponentName(compo)
}
);
return isMatched;
} The regex is needed for both the user provided component and the formatted component.
What do you think? 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. Good observation, you're right! Also, I didn't think about the There's one unfortunate side effect of this regex though: It can lead to polynomial build up when evaluating an input. Given that we run I played around with the regex to make it safer and keep it linear and arrived at this one: Also, since this logic is getting a little bit more involved now, could you add a couple of unit test for (I don't want to overburden you with tests btw, I just want to keep stuff like this covered and understandable for everyone. So if you don't have the time, just let me know. We appreciate your hard work either way!) 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. Noted, unit and e2e tests added. |
||||||||||||||||
}); | ||||||||||||||||
|
||||||||||||||||
return isMatched; | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
export const createTracingMixins = (options: TracingOptions): Mixins => { | ||||||||||||||||
const hooks = (options.hooks || []) | ||||||||||||||||
.concat(DEFAULT_HOOKS) | ||||||||||||||||
|
@@ -85,7 +99,7 @@ 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 | ||||||||||||||||
|
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.
formattedName
fromformatComponentName()
always return a name with< >
.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.
Oh, it can also be
<Component> at Component.vue
.