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

c is not a function when defining custom beforeSend function #349

Closed
jonalxh opened this issue Sep 17, 2021 · 11 comments
Closed

c is not a function when defining custom beforeSend function #349

jonalxh opened this issue Sep 17, 2021 · 11 comments
Labels

Comments

@jonalxh
Copy link

jonalxh commented Sep 17, 2021

Hi, I'm currently trying to customize sentry to prevent the report of several messages that are very noisy in my dashboard. First I tried writing all the errors I want to disable to be tracked inside the ignoreErrors section of config, but it did nothing, after that I tried to make a custom beforeSend function inside the sentry.config attribute, but when building the app it throwed me the same error reported here although I have the latests version. Finally i ended up writing my custom beforeSend function inside the publicRuntimeConfig as one of the comments in this repo issues section said, but now i'm getting this error:

image

The build finishes well, but this error appears each 5 seconds in my sentry console. How to solve it?

Version

@nuxtjs/sentry: 5.1.3
nuxt: 2.15.4

Sentry configuration

sentry: {
    dsn: credentials.SentryConf.dsn,
    lazy: true,
    disabled: !isProd,
    disableServerSide: true,
    tracing: true,
    clientIntegrations: {
      ExtraErrorData
    },
    ignoreErrors: [
      'unhandledRejection',
      'UnhandledRejection',
      'unhandledPromiseRejection',
      'ReportingObserver',
      'Cannot set headers after they are sent to the client',
      'ResizeObserver loop limit exceeded'
    ]
  },
  publicRuntimeConfig: {
    sentry: { // It is necessary to set this config here, because in the common sentry settings it thrown the following error: https://github.com/nuxt-community/sentry-module/issues/266, tested with version 5.1.3
      config: {
        beforeSend(event, hint){
          if (hint.originalException.stack) {
            // eslint-disable-next-line dot-notation
            const errorStack = JSON.stringify(hint.originalException.stack)
  
            const errorsToIgnore = [
              'unhandledRejection',
              'UnhandledRejection',
              'unhandledPromiseRejection',
              'ReportingObserver',
              'Cannot set headers after they are sent to the client',
              'ResizeObserver loop limit exceeded',
              'postMessage',
              'createError',
              'Non-Error promise rejection captured with keys: details, error',
              'Request failed with status code 403',
              'Network Error',
              'disconnected'
            ]
  
            const shouldIgnoreError = errorsToIgnore.some(elem => errorStack.toLowerCase().includes(elem.toLowerCase()))
  
            return shouldIgnoreError ? null : event;
  
         }
  
          return event;
        }
      }
    }
  },

Steps to reproduce

Just create a nuxt project with the versions and settings mentioned above.

What is Expected?

The expected behavior is that sentry ignored the array of errors I've manually set and not show the c is not a function error,

What is actually happening?

I'm receiving hundreds of times the c is not a function error.

I'm new to Sentry, so if I'm doing it bad, please explain me how to avoid Sentry reports of the array of error I have set.
Thanks a lot.

@jonalxh jonalxh added the bug label Sep 17, 2021
@rchl
Copy link
Member

rchl commented Sep 17, 2021

  1. What is the ExtraErrorData object referenced in the clientIntegrations object? It must be just a plain object. Depending on what you are doing here, that could cause issue like you are seeing.
  2. The ignoreErrors belongs in the sentry.config object - sentry: { config: { ignoreErrors: [...] } }
  3. As for beforeSend used within the publicRuntimeConfig, I'd have to check it out but I don't see why it wouldn't work.

@jonalxh
Copy link
Author

jonalxh commented Sep 17, 2021

  1. Is just an integration imported: import { ExtraErrorData } from '@sentry/integrations';.
  2. I'm going to put it there to check if it works, but I have a question. Sentry will check the error as case sensitive if I put it inside sentry.config.ignoreErrors?
  3. It doesn't work inside the original config, it throws beforeSend: beforeSend(...), duplicating the beforeSend function.

@rchl
Copy link
Member

rchl commented Sep 17, 2021

1. Is just an integration imported: `import { ExtraErrorData } from '@sentry/integrations';`.

This sounds wrong. That option takes a plain object with integration configuration, not the integration class, which is what you are getting by importing it.

2\. I'm going to put it there to check if it works, but I have a question. Sentry will check the error as case sensitive if I put it inside sentry.config.ignoreErrors?

See https://docs.sentry.io/clients/javascript/config/ . It seems like strings are case-sensitive but you can use regexp to make things case-insensitive.

3\. It doesn't work inside the original config, it throws `beforeSend: beforeSend(...)`, duplicating the beforeSend function.

You could try declaring that function using: beforeSend: function(event, hint) { syntax instead. Although with #266 fixed I thought your case should have worked if you are running recent enough Nuxt version...

@jonalxh
Copy link
Author

jonalxh commented Sep 17, 2021

  1. How do I enable that integration if I don't provide the imported class?

  2. Documentation says "When using strings, they’ll partially match the messages, so if you need to achieve an exact match, use RegExp patterns instead." So I think that they are initially case insensitive, no?

  3. By setting the beforeSend function inside sentry.config as you recommended me seems to solve the build problem, but I'm still receiving the c is not a function message several times.

@rchl
Copy link
Member

rchl commented Sep 18, 2021

1. How do I enable that integration if I don't provide the imported class?

Just do ExtraErrorData: {},. As long as it's one of the official integrations this will enable it.

@LegendSebastianoL
Copy link

same here, I've tried the previous code without the ignoreErrors array but yes with the runtime bit and this is my config:

    clientIntegrations: {
      CaptureConsole: {
        levels: ['error']
      },
      ReportingObserver: {
        types: ['crash']
      }
    },

full config it's in #350
and this is the error.

Sentry Logger [Error]: e: Event processing pipeline threw an error, original event will not be sent. Details have been sent as a new event.
Reason: TypeError: c is not a function

@rchl
Copy link
Member

rchl commented Sep 21, 2021

Post your actual configuration. The client integrations config doesn't seem relevant to your issue.

And your issue is likely just that your beforeSend handler is crashing somewhere because of missing null check.

@LegendSebastianoL
Copy link

LegendSebastianoL commented Sep 21, 2021

I've tried both:

    config: {
      debug: true,
      release: process.env.SENTRY_RELEASE ? process.env.SENTRY_RELEASE : 'test',
      environment: process.env.SENTRY_ENVIRONMENT ? process.env.SENTRY_ENVIRONMENT : 'local'
    },

       ignoreErrors: [
         /.*seba*/,
         /.*Non-Error promise rejection captured with*/,
         /.*[object Event]*/,
         /.*<unknown>*/,
         /.*Missing external script*/,
         /.*ECONNRESET*/,
         /.*TypeError: document.head.append is not a function*/
      ],

    clientIntegrations: {
      CaptureConsole: {
        levels: ['error']
      },
      ReportingObserver: {
        types: ['crash']
      }
    },

and

  sentry: {
    lazy: false,
    dsn: process.env.NODE_ENV === 'development' ? null : process.env.SENTRY_NUXT_DSN,

    config: {
      debug: true,
      release: process.env.SENTRY_RELEASE ? process.env.SENTRY_RELEASE : 'test',
      environment: process.env.SENTRY_ENVIRONMENT ? process.env.SENTRY_ENVIRONMENT : 'local'
    },

    clientIntegrations: {
      CaptureConsole: {
        levels: ['error']
      },
      InboundFilters: {
        ignoreErrors: [
          /.*Non-Error promise rejection captured with*/,
          /.*[object Event]*/,
          /.*<unknown>*/,
          /.*Missing external script*/,
          /.*ECONNRESET*/,
          /.*TypeError: document.head.append is not a function*/
        ]
      },
      ReportingObserver: {
        types: ['crash']
      }
    },

the beforeSend it's the same as the one above, I wanted to try that piece of code for me as well

@rchl
Copy link
Member

rchl commented Sep 22, 2021

I'm asking about how you defined the beforeSend exactly and you keep omitting it from your configuration...

I guess beforeSend() {} might create an issue but beforeSend: function () {} shouldn't. But it all depends on your version of Nuxt also since it was fixed at some point (even if some cases can still fail).

@jonalxh
Copy link
Author

jonalxh commented Sep 24, 2021

I've solved the issue by just using the ignoreErrors inside sentry.config, but if I set a beforeSend: function {...} the c is not a function error appears again.

@rchl
Copy link
Member

rchl commented Sep 24, 2021

Closing then. I think it would work better with later versions of Nuxt. There were some fixes around serializing functions in the config.

In Nuxt 2.15.8 all cases worked correctly when I've tested.

@rchl rchl closed this as completed Sep 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants