Skip to content

[Nuxt] Server-side not reporting any errors (aws-lambda) #15391

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

Closed
3 tasks done
brtinney opened this issue Feb 12, 2025 · 3 comments
Closed
3 tasks done

[Nuxt] Server-side not reporting any errors (aws-lambda) #15391

brtinney opened this issue Feb 12, 2025 · 3 comments
Labels
Package: nuxt Issues related to the Sentry Nuxt SDK

Comments

@brtinney
Copy link

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/nuxt

SDK Version

9.0.1

Framework Version

Nuxt 3.15.1, aws-lambda

Link to Sentry event

No response

Reproduction Example/SDK Setup

Sentry.init({
    dsn: process.env.SENTRY_DSN,
    environment: process.env.APP_ENV || 'development',
    normalizeDepth: 10,
    beforeSend: async (event, hint) => {
      console.log("before send", event, hint)
      const error = hint.originalException
      if (!event.contexts) {
        event.contexts = {}
      }
      if (error && (error instanceof H3Error || isFetchError(error))) {
        if (error instanceof FetchError) {
          if (
            /^https:\/\/api\.cloudflare\.com/.test(
              error.request?.toString() || ''
            ) ||
            [402, 403, 404, 422].includes(error.statusCode || 0)
          ) {
            return null
          } else if (
            [401].includes(error.statusCode || 0) &&
            error.statusMessage ===
              'The user does not have an active session or is not authenticated'
          ) {
            return null
          }
        }

        if (
          ['This URL can be used only once', 'Access expired.'].includes(
            error.data.error_description
          )
        ) {
          return null
        }
        event.contexts.error_data = { error_data: error.data }
      }

      return event
    }
  })
})

Steps to Reproduce

I switched from something based on this manual integration to the provided Nuxt module, and suddenly I was not getting any errors being reported.

At first, I thought this was just a result of this block dropping all 3xx and 4xx errors.

While that is a separate issue (that should either pass everything through to be filtered by beforeSend() or able to be customized through options on the module), I found that it wasn't the (only) cause of my issue, as triggering a 503 error still didn't send anything.

Expected Result

I expected that I would get errors reported in Sentry as I had before.

Actual Result

Still no errors being logged in Sentry from the server.

While debugging, I basically just copied the hook code from the official module into my own nitro hook and made that one ignore anything not 3xx or 4xx errors as the original Sentry plugin will handle those, and my code won't cause duplicates.

However, while I can confirm the init() is run (using NODE_OPTIONS to --import .output/server/sentry.server.config.mjs as per the AWS Lambda ESM docs), and there is a client, Sentry.captureException(error) does not appear to actually ever report anything in Sentry. It seems that I am seeing some "Too Large" errors according to my stats page, but I don't think they correspond to the tests I've been doing (hard to prove definitively without a filter for environment).

Maybe related: is there a reason why every chunk now has tons of extra code in it? This ballooned my deployed code from ~19MB to ~46MB. I did add ignoreInternal: false to attempt to confirm if it was triggering the "Too Large" error, but I'm not sure that would actually log the internal Sentry error given how nitro hooks work. Either way, I don't know how an endpoint that just does throw createError({ statusCode: 503, statusMessage: "Fake Error" }) would be hitting those limits.

For now, I'm going to revert things. While this issue doesn't have aws-lambda on it, I assumed it would be fine since it is just Node (and there is a separate AWS Lambda integration). But maybe not.

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Feb 12, 2025
@github-actions github-actions bot added the Package: nuxt Issues related to the Sentry Nuxt SDK label Feb 12, 2025
@andreiborza
Copy link
Member

Hi @brtinney, thanks for writing in.

Could you set debug: true and paste some startup and running logs? I'll have a look at reproducing this in the meantime.

As for the increased size, I'm guessing this is from sourcemaps (cc @s1gr1d).

@andreiborza
Copy link
Member

@brtinney I tried to reproduce this setting up a fresh nuxt project and using our nuxt wizard to set up sentry. I used the aws-lambda preset for nitro:

// nuxt.config.ts
nitro: {
    preset: 'aws-lambda',
    serveStatic: true,
    output: {
      publicDir: '.output/server',
    }
  }

Zipped the .output/server folder and created a lambda function from that zip file. I set up the NODE_OPTIONS as you mentioned and navigated to /sentry-example-page to trigger an error and I got them:

Image

What happens if you remove your beforeSend?

@brtinney
Copy link
Author

Thanks @andreiborza -- I had been having so many different issues (sometimes the client would fail, too, but mostly in development). I forgot that the debug flag would help me a lot more than my own debug statements.

I had put one inside beforeSend but never saw it logged, so I assumed that it was never getting there. However, I basically re-installed everything from scratch and slowly added my customizations back in piece-by-piece and was able to get things working -- eventually finding that I got tripped up by nitro global exports (isFetchError) that are not available in sentry.sever.config.mjs, even though it will work in dev.

Things that I found:

  1. The ThirdPartyErrorsFilter didn't seem work quite right (using unstable_sentryBundlerPluginOptions: { applicationKey: 'key' } and then putting that key in the config for the integration for the client) -- it was filtering errors I threw in my code. That isn't a big deal, but was certainly causing me some confusion without the debug flag.
  2. The total size of the bundle seems fixed now. Maybe something I was doing was causing the weird extra imports in every file. It should not have been source maps since those are generated by Nuxt either way (on the server).
  3. There were some errors logged along the way, which I'm not sure affect anything (these lines do exist, and don't really seem related):
Sentry Logger [error]: Could not find line 16034 in file /var/task/.output/server/chunks/runtime.mjs
Sentry Logger [error]: Could not find line 13283 in file /var/task/.output/server/chunks/runtime.mjs
Sentry Logger [error]: Could not find line 13158 in file /var/task/.output/server/chunks/runtime.mjs

The lines, respectively:

event.path || event.rawPath,
const isolationScope = getIsolationScope();
const onLeave = () => currentInstance === instance ? onRestore : void 0;
  1. I had some issues with trying to detect the type of error in my beforeSend -- instanceof didn't seem to work as it had before, so I had to use isError exported from h3 in addition to re-defining my isFetchError which tests for x.name === 'FetchError'. I assume this behavior has something to do with the file being imported via the command line argument, but it is a bit of a gotcha.
  2. As expected, I still had to use my separate nitro hook to send 4xx errors, which is fine, just a little annoying.

Anyway, everything is working at this point. Hopefully if anyone else runs into similar issues, some of this might set them on the right track.

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

No branches or pull requests

2 participants