-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(vue): Rework tracing and add support for Vue 3 #3804
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
150d80c
feat(vue): Rework tracing and add support for Vue 3
kamilogorek d8ab3d6
feat: Allow initializing multiple Vue apps
kamilogorek 7286b49
Make linters happy again
kamilogorek c0d306d
s/vuerouter.ts/router.ts/g
kamilogorek bf6f1bd
Remove no-explicit-any by default
kamilogorek 8353a8b
Export attachErrorHandler so it can be used after Sentry was initialized
kamilogorek 8c77ca3
Export createTracingMixins
kamilogorek 36ed47f
Apply code review feedback
kamilogorek c7f9201
Merge branch 'master' into vue3
kamilogorek 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
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,83 @@ | ||
| import { ViewModel } from './types'; | ||
|
|
||
| // Vendored directly from https://github.com/vuejs/vue/blob/master/src/core/util/debug.js with types only changes. | ||
| const classifyRE = /(?:^|[-_])(\w)/g; | ||
| const classify = (str: string): string => str.replace(classifyRE, c => c.toUpperCase()).replace(/[-_]/g, ''); | ||
|
|
||
| const ROOT_COMPONENT_NAME = '<Root>'; | ||
| const ANONYMOUS_COMPONENT_NAME = '<Anonymous>'; | ||
|
|
||
| const repeat = (str: string, n: number): string => { | ||
| let res = ''; | ||
| while (n) { | ||
| if (n % 2 === 1) { | ||
| res += str; | ||
| } | ||
| if (n > 1) { | ||
| str += str; // eslint-disable-line no-param-reassign | ||
| } | ||
| n >>= 1; // eslint-disable-line no-bitwise, no-param-reassign | ||
| } | ||
| return res; | ||
| }; | ||
|
|
||
| export const formatComponentName = (vm?: ViewModel, includeFile?: boolean): string => { | ||
| if (!vm) { | ||
| return ANONYMOUS_COMPONENT_NAME; | ||
| } | ||
|
|
||
| if (vm.$root === vm) { | ||
| return ROOT_COMPONENT_NAME; | ||
| } | ||
|
|
||
| const options = vm.$options; | ||
|
|
||
| let name = options.name || options._componentTag; | ||
| const file = options.__file; | ||
| if (!name && file) { | ||
| const match = file.match(/([^/\\]+)\.vue$/); | ||
| if (match) { | ||
| name = match[1]; | ||
| } | ||
| } | ||
|
|
||
| return ( | ||
| (name ? `<${classify(name)}>` : ANONYMOUS_COMPONENT_NAME) + (file && includeFile !== false ? ` at ${file}` : ``) | ||
| ); | ||
| }; | ||
|
|
||
| export const generateComponentTrace = (vm?: ViewModel): string => { | ||
| if (vm?._isVue && vm?.$parent) { | ||
| const tree = []; | ||
| let currentRecursiveSequence = 0; | ||
| while (vm) { | ||
| if (tree.length > 0) { | ||
| const last = tree[tree.length - 1] as any; | ||
| if (last.constructor === vm.constructor) { | ||
| currentRecursiveSequence += 1; | ||
| vm = vm.$parent; // eslint-disable-line no-param-reassign | ||
| continue; | ||
| } else if (currentRecursiveSequence > 0) { | ||
| tree[tree.length - 1] = [last, currentRecursiveSequence]; | ||
| currentRecursiveSequence = 0; | ||
| } | ||
| } | ||
| tree.push(vm); | ||
| vm = vm.$parent; // eslint-disable-line no-param-reassign | ||
| } | ||
|
|
||
| const formattedTree = tree | ||
| .map( | ||
| (vm, i) => | ||
| `${(i === 0 ? '---> ' : repeat(' ', 5 + i * 2)) + | ||
| (Array.isArray(vm) | ||
| ? `${formatComponentName(vm[0])}... (${vm[1]} recursive calls)` | ||
| : formatComponentName(vm))}`, | ||
kamilogorek marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ) | ||
| .join('\n'); | ||
|
|
||
| return `\n\nfound in\n\n${formattedTree}`; | ||
| } | ||
|
|
||
| return `\n\n(found in ${formatComponentName(vm)})`; | ||
| }; | ||
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,48 @@ | ||
| import { getCurrentHub } from '@sentry/browser'; | ||
|
|
||
| import { formatComponentName, generateComponentTrace } from './components'; | ||
| import { Options, ViewModel, Vue } from './types'; | ||
|
|
||
| export const attachErrorHandler = (app: Vue, options: Options): void => { | ||
| const { errorHandler, warnHandler, silent } = app.config; | ||
|
|
||
| app.config.errorHandler = (error: Error, vm: ViewModel, lifecycleHook: string): void => { | ||
| const componentName = formatComponentName(vm, false); | ||
| const trace = vm ? generateComponentTrace(vm) : ''; | ||
| const metadata: Record<string, unknown> = { | ||
| componentName, | ||
| lifecycleHook, | ||
| trace, | ||
| }; | ||
|
|
||
| if (options.attachProps) { | ||
| // Vue2 - $options.propsData | ||
| // Vue3 - $props | ||
| metadata.propsData = vm.$options.propsData || vm.$props; | ||
| } | ||
|
|
||
| // Capture exception in the next event loop, to make sure that all breadcrumbs are recorded in time. | ||
| setTimeout(() => { | ||
| getCurrentHub().withScope(scope => { | ||
| scope.setContext('vue', metadata); | ||
| getCurrentHub().captureException(error); | ||
| }); | ||
| }); | ||
|
|
||
| if (typeof errorHandler === 'function') { | ||
| errorHandler.call(app, error, vm, lifecycleHook); | ||
| } | ||
|
|
||
| if (options.logErrors) { | ||
| const hasConsole = typeof console !== 'undefined'; | ||
| const message = `Error in ${lifecycleHook}: "${error && error.toString()}"`; | ||
|
|
||
| if (warnHandler) { | ||
| warnHandler.call(null, message, vm, trace); | ||
| } else if (hasConsole && !silent) { | ||
| // eslint-disable-next-line no-console | ||
| console.error(`[Vue warn]: ${message}${trace}`); | ||
| } | ||
| } | ||
| }; | ||
| }; |
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,4 +1,6 @@ | ||
| export * from '@sentry/browser'; | ||
|
|
||
| export { init } from './sdk'; | ||
| export { vueRouterInstrumentation } from './vuerouter'; | ||
| export { vueRouterInstrumentation } from './router'; | ||
| export { attachErrorHandler } from './errorhandler'; | ||
| export { createTracingMixins } from './tracing'; |
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.
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.
Uh oh!
There was an error while loading. Please reload this page.