Skip to content
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

Using vue-router 4.2.2 with Sentry.vueRouterInstrumentation result in TypeError next is not a function #8349

Closed
3 tasks done
egistli-geezerbuild opened this issue Jun 17, 2023 · 1 comment · Fixed by #8351
Assignees
Labels
Package: vue Issues related to the Sentry Vue SDK

Comments

@egistli-geezerbuild
Copy link

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/vue

SDK Version

7.55.2

Framework Version

Vue 3.3.4, Nuxt 3.5.3

Link to Sentry event

https://ebtex.sentry.io/issues/4252605919/?query=is%3Aignored&referrer=issue-stream&stream_index=3

SDK Setup

It's a nuxt plugin.

import * as Sentry from '@sentry/vue';
import { BrowserTracing } from '@sentry/browser';
import type { Router } from 'vue-router'

export default defineNuxtPlugin((nuxtApp) => {
    console.log('init nuxt sentry', [nuxtApp.$router]);
    const { vueApp } = nuxtApp;
    const vueRouter = nuxtApp.$router as Router

    Sentry.init({
        app: [vueApp],
        dsn: process.env.SENTRY_DSN,
        environment: process.dev ? 'development' : 'production',
        integrations: [
            new BrowserTracing({
                routingInstrumentation: Sentry.vueRouterInstrumentation(vueRouter)
            })
        ],
        // Set tracesSampleRate to 1.0 to capture 100%
        // of transactions for performance monitoring.
        // We recommend adjusting this value in production
        tracesSampleRate: 1.0,
        beforeSend(event, hint) {
            // Check if it is an exception, and if so, log it.
            if (event.exception) {
                // eslint-disable-next-line no-console
                console.error(`[Exeption handled by Sentry]: (${hint.originalException})`, { event, hint });
            }
            // Continue sending to Sentry
            return event;
        }
    });

    vueApp.mixin(Sentry.createTracingMixins({ trackComponents: true, timeout: 2000, hooks: ['activate', 'mount', 'update'] }));
    Sentry.attachErrorHandler(vueApp, { logErrors: false, attachProps: true, trackComponents: true, timeout: 2000, hooks: ['activate', 'mount', 'update'] });

    return {
        provide: {
            sentrySetContext: Sentry.setContext,
            sentrySetUser: Sentry.setUser,
            sentrySetTag: Sentry.setTag,
            sentryAddBreadcrumb: Sentry.addBreadcrumb,
            sentryCaptureException: Sentry.captureException
        }
    };
});

Steps to Reproduce

  1. Set up a Nuxt3 project
  2. Add above sentry plugin into plugins folder
  3. run npx nuxt generate

Expected Result

Nuxt cli can successfully generate SPA content.

Actual Result

However I see error as the following

 ERROR  [Exeption handled by Sentry]: (TypeError: next is not a function) { event: 
   { exception: { values: [Array] },
     level: 'error',
     event_id: 'a1a34826c2b043a4b182d554decb251d',
     platform: 'javascript',
     timestamp: 1686988594.694,
     environment: 'production',
     sdk: { integrations: [Array] },
     breadcrumbs: [ [Object] ],
     sdkProcessingMetadata: {} },
  hint:
   { originalException:
      TypeError: next is not a function
...

Commenting out the line routingInstrumentation: Sentry.vueRouterInstrumentation(vueRouter) resolves this issue.
I also check the source, the issue is in the node_modules/@sentry/vue/cjs/router.js there's a callback on beforeEach. In the last line of the callback, next is called.

However in vue-router 4, the next parameter has been removed from beforeEach callback hence the error thrown.
Is it because vue-router4 not supported yet by @sentry/vue?

@Lms24
Copy link
Member

Lms24 commented Jun 19, 2023

Hi @egistli-geezerbuild thanks for reporting!

Is it because vue-router4 not supported yet by @sentry/vue?

Vue Router 4 is supported according to our docs but you're right that the next call seems to be problematic. I wonder why this didn't come up before. I opened #8351 to fix this.

@Lms24 Lms24 added Status: In Progress Package: vue Issues related to the Sentry Vue SDK and removed Type: Bug labels Jun 19, 2023
@Lms24 Lms24 self-assigned this Jun 19, 2023
Lms24 added a commit that referenced this issue Jun 19, 2023
Vue Router 4 no longer exposes a `next` resolver function to call inside a `beforeEach` [router guard callback](https://router.vuejs.org/guide/advanced/navigation-guards.html#global-before-guards).
Instead it will resolve the hook when the callback function returns.

This PR checks if `next` is available and only calls it then. Also it
adjusts the types accordingly and adds a test that previously failed.

fixes #8349
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Package: vue Issues related to the Sentry Vue SDK
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants