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

Sentry does not initialize in a backend-only Nuxt API #15617

Closed
3 tasks done
axel-trending-dev opened this issue Mar 7, 2025 · 2 comments
Closed
3 tasks done

Sentry does not initialize in a backend-only Nuxt API #15617

axel-trending-dev opened this issue Mar 7, 2025 · 2 comments
Labels
Package: nuxt Issues related to the Sentry Nuxt SDK

Comments

@axel-trending-dev
Copy link

axel-trending-dev commented Mar 7, 2025

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

v9

Framework Version

Nuxt 3.15.1 + Node v22 + pnpm@9.15.4

Link to Sentry event

No response

Reproduction Example/SDK Setup

import * as Sentry from '@sentry/nuxt';

Sentry.init({
  dsn: '***',

  // TODO: We recommend adjusting this value in production, or using tracesSampler
  // for finer control
  tracesSampleRate: 1.0,

  // Setting this option to true will print useful information to the console while you're setting up Sentry.
  debug: false
});

Steps to Reproduce

When using @sentry/nuxt in a backend-only Nuxt project (e.g., an API without a frontend), Sentry does not automatically capture errors, and even manual error capture (Sentry.captureException(error)) does not work.

It seems that Sentry only initializes when the frontend is engaged. The following logs appear when the frontend is accessed:
ℹ ✨ new dependencies optimized: @sentry/nuxt
ℹ ✨ optimized dependencies changed. reloading

However, if there is no frontend interaction, Sentry does not seem to start, and no errors are captured in the backend.

Steps to Reproduce

  1. Create a Nuxt project with a backend-only API (server/api/ handlers).
  2. Trigger an error in an API route.
  3. Observe that no errors are reported to Sentry.

Expected Result

Sentry should initialize and capture errors automatically, even in an API backend-only Nuxt setup.
Manual error capture (Sentry.captureException(error)) should work as expected.

Actual Result

Sentry is not capturing exceptions in an API backend-only Nuxt setup. Even manual error capture (Sentry.captureException(error)) is not working as expected.

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

Hi @axel-trending-dev, thanks for writing in.

I tried reproducing this locally by creating a new nuxt project via the nuxi wizard and setting up sentry using sentry-wizard. I removed the frontend routes and any .vue files, started the server using
node --import ./.output/server/sentry.server.config.mjs .output/server/index.mjs and sent a request to /api/sentry-example-api which is set up by the wizard and looks like this:

// This is just a very simple API route that throws an example error.
// Feel free to delete this file.
import { defineEventHandler } from '#imports';

export default defineEventHandler(() => {
  throw new Error("Sentry Example API Route Error");
});

And the error shows up:

Image

Could you please set debug: true in sentry.server.config.ts and paste some startup logs and logs after you fire off a request?

@axel-trending-dev
Copy link
Author

This bug can be closed I just saw now that in https://docs.sentry.io/platforms/javascript/guides/nuxt/manual-setup/ says the following:

`Sentry server-side monitoring doesn't work in development mode!

If you experience any issues with the server-side setup, check out Troubleshooting or read through the different installation methods.`

Thank you @andreiborza

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