-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(nuxt): Add vue-router instrumentation #13054
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 4 commits
8bdd32b
c59f3b3
8eb2a57
37d0159
0641a01
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 |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| <template> | ||
| <p>{{ $route.params.param }} - {{ $route.params.param }}</p> | ||
| <ErrorButton errorText="Error thrown from Param Route Button" /> | ||
| </template> |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -5,93 +5,93 @@ export type SentryNuxtOptions = Omit<Parameters<typeof init>[0] & object, 'app'> | |||||
|
|
||||||
| type SourceMapsOptions = { | ||||||
| /** | ||||||
| * Options for the Sentry Vite plugin to customize the source maps upload process. | ||||||
| * If this flag is `true`, and an auth token is detected, the Sentry integration will | ||||||
|
||||||
| * If this flag is `true`, and an auth token is detected, the Sentry integration will | |
| * If this flag is `true`, and an auth token is detected, the Sentry integration will |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,41 @@ | ||
| import { getClient } from '@sentry/core'; | ||
| import { vueIntegration } from '@sentry/vue'; | ||
| import { browserTracingIntegration, vueIntegration } from '@sentry/vue'; | ||
| import { defineNuxtPlugin } from 'nuxt/app'; | ||
|
|
||
| // --- Types are copied from @sentry/vue (so it does not need to be exported) --- | ||
| // The following type is an intersection of the Route type from VueRouter v2, v3, and v4. | ||
| // This is not great, but kinda necessary to make it work with all versions at the same time. | ||
| type Route = { | ||
| /** Unparameterized URL */ | ||
| path: string; | ||
| /** | ||
| * Query params (keys map to null when there is no value associated, e.g. "?foo" and to an array when there are | ||
| * multiple query params that have the same key, e.g. "?foo&foo=bar") | ||
| */ | ||
| query: Record<string, string | null | (string | null)[]>; | ||
| /** Route name (VueRouter provides a way to give routes individual names) */ | ||
| name?: string | symbol | null | undefined; | ||
| /** Evaluated parameters */ | ||
| params: Record<string, string | string[]>; | ||
| /** All the matched route objects as defined in VueRouter constructor */ | ||
| matched: { path: string }[]; | ||
| }; | ||
|
|
||
| interface VueRouter { | ||
| onError: (fn: (err: Error) => void) => void; | ||
| beforeEach: (fn: (to: Route, from: Route, next?: () => void) => void) => void; | ||
| } | ||
|
|
||
| export default defineNuxtPlugin(nuxtApp => { | ||
| nuxtApp.hook('app:created', vueApp => { | ||
| const sentryClient = getClient(); | ||
| const sentryClient = getClient(); | ||
|
||
|
|
||
| if (sentryClient && '$router' in nuxtApp) { | ||
| sentryClient.addIntegration( | ||
| browserTracingIntegration({ router: nuxtApp.$router as VueRouter, routeLabel: 'path' }), | ||
| ); | ||
| } | ||
|
||
|
|
||
| nuxtApp.hook('app:created', vueApp => { | ||
| if (sentryClient) { | ||
| sentryClient.addIntegration(vueIntegration({ app: vueApp })); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| import * as SentryBrowser from '@sentry/browser'; | ||
| import { type BrowserClient, SDK_VERSION, getClient } from '@sentry/vue'; | ||
| import { SDK_VERSION } from '@sentry/vue'; | ||
| import { beforeEach, describe, expect, it, vi } from 'vitest'; | ||
| import { init } from '../../src/client'; | ||
|
|
||
|
|
@@ -35,23 +35,6 @@ describe('Nuxt Client SDK', () => { | |
| expect(browserInit).toHaveBeenLastCalledWith(expect.objectContaining(expectedMetadata)); | ||
| }); | ||
|
|
||
| describe('Automatically adds BrowserTracing integration', () => { | ||
| it.each([ | ||
| ['tracesSampleRate', { tracesSampleRate: 0 }], | ||
| ['tracesSampler', { tracesSampler: () => 1.0 }], | ||
| ['enableTracing', { enableTracing: true }], | ||
| ['no tracing option set', {}] /* enable "tracing without performance" by default */, | ||
| ])('adds a browserTracingIntegration if tracing is enabled via %s', (_, tracingOptions) => { | ||
| init({ | ||
| dsn: 'https://[email protected]/1337', | ||
| ...tracingOptions, | ||
| }); | ||
|
|
||
| const browserTracing = getClient<BrowserClient>()?.getIntegrationByName('BrowserTracing'); | ||
| expect(browserTracing).toBeDefined(); | ||
| }); | ||
| }); | ||
|
|
||
| it('returns client from init', () => { | ||
| expect(init({})).not.toBeUndefined(); | ||
| }); | ||
|
|
||
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.
This is not related - just a restructuring of the type