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

Incorrect serialize sentry config (beforeSend) #266

Closed
charlie0228 opened this issue Jan 19, 2021 · 1 comment · Fixed by #267
Closed

Incorrect serialize sentry config (beforeSend) #266

charlie0228 opened this issue Jan 19, 2021 · 1 comment · Fixed by #267
Labels

Comments

@charlie0228
Copy link
Contributor

Version

@nuxtjs/sentry: 4.5.0
nuxt: 2.14.12

Sentry configuration

  sentry: {
    dsn: 'https://examplePublicKey@o0.ingest.sentry.io/0', // Enter your project's DSN here
    config: {
      beforeSend(event, hint) {
        const ignoreErrorInBeforeSend = [
          {
            check: (event, hint) => {
              // Ignore fbevent.js postMessage error in iOS device
              if (hint?.originalException?.stack) {
                // eslint-disable-next-line dot-notation
                const errorStack = JSON.stringify(hint.originalException.stack)
                return /postMessage/.test(errorStack)
              }

              return false
            },
          },
        ]

        const shouldIgnoreError = ignoreErrorInBeforeSend.some((rule) =>
          rule.check(event, hint)
        )
        return shouldIgnoreError ? null : event
      },
    }, // Additional config
  },

Reproduction Link

https://github.com/charlie0228/nuxt-sentry-issue

Steps to reproduce

  1. run yarn build
  2. check .nuxt\sentry.client.js

What is Expected?

Correct syntax in .nuxt\sentry.client.js
This issue is similar to #226

What is actually happening?

Incorrect config syntax like below, the const config is all wrong!

.nuxt\sentry.client.js

import VueLib from 'vue'
import * as Sentry from '@sentry/browser'

import { Dedupe, ExtraErrorData, ReportingObserver, RewriteFrames, Vue } from '@sentry/integrations'

export default function (ctx, inject) {
  /* eslint-disable object-curly-spacing, quote-props, quotes, key-spacing, comma-spacing */
  const config = {"dsn":"https:\u002F\u002FexamplePublicKey@o0.ingest.sentry.io\u002F0","environment":"production","beforeSend":beforeSend(event, hint) {
                const ignoreErrorInBeforeSend = [
                    {
                        check: (event, hint) => {
                            var _a;
                            // Ignore fbevent.js postMessage error in iOS device
                            if ((_a = hint === null || hint === void 0 ? void 0 : hint.originalException) === null || _a === void 0 ? void 0 : _a.stack) {
                                // eslint-disable-next-line dot-notation
                                const errorStack = JSON.stringify(hint.originalException.stack);
                                return /postMessage/.test(errorStack);
                            }
                            return false;
                        },
                    },
                ];
                const shouldIgnoreError = ignoreErrorInBeforeSend.some((rule) => rule.check(event, hint));
                return shouldIgnoreError ? null : event;
            }}
  config.integrations = [
    new Dedupe({}),
    new ExtraErrorData({}),
    new ReportingObserver({}),
    new RewriteFrames({}),
    new Vue({ Vue: VueLib, ...{"attachProps":true,"logErrors":false}})
  ]

  /* eslint-enable object-curly-spacing, quote-props, quotes, key-spacing, comma-spacing */
  Sentry.init(config)

  inject('sentry', Sentry)
  ctx.$sentry = Sentry
}
@rchl
Copy link
Member

rchl commented Feb 8, 2021

Fix released in https://github.com/nuxt-community/sentry-module/releases/tag/v5.0.1

Some cases will still fail until a Nuxt fix is released.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants