sentry-javascript icon indicating copy to clipboard operation
sentry-javascript copied to clipboard

[Nuxt]: Wrong issue environment tag

Open priscilawebdev opened this issue 10 months ago • 4 comments

Is there an existing issue for this?

  • [x] I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues
  • [x] I have reviewed the documentation https://docs.sentry.io/
  • [x] I am using the latest SDK release https://github.com/getsentry/sentry-javascript/releases

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/nuxt

SDK Version

9.5.0

Framework Version

No response

Link to Sentry event

https://sentry-pri-nuxt.sentry.io/issues/32395492/events/8dfaac86dd084cc19ec6cea251cf4958/

Reproduction Example/SDK Setup

No response

Steps to Reproduce

  1. Create a new Nuxt project by following the official guide here: Nuxt Installation Guide.
  2. Set up a new organization in Sentry.
  3. Create a new Nuxt project in Sentry.
  4. Use the Sentry wizard to instrument the Nuxt project.
  5. Run yarn dev to start the development environment.
  6. Trigger an error in the application.
  7. Go to the issue details in Sentry.
  8. The 'environment' tag should be set to 'dev'/'development' instead of 'production'.

Expected Result

The 'environment' tag should be set to 'dev'/'development' instead of 'production'.

Actual Result

Currently I am seeing 'production'

Image

Image

  • Contributes to https://github.com/getsentry/sentry/issues/79408#issuecomment-2706156295

priscilawebdev avatar Mar 10 '25 06:03 priscilawebdev

I think this is a larger issue than Nuxt because at this point, our SDKs don't universally auto-detect environemnt.

Most importantly, it's almost impossible to auto-detect dev vs prod reliably, especially in browser-side SDKs.

I checked various SDKs for environment default values:

  • In some SDKs we check process.env.NODE_ENV (e.g. remix),
  • in the Node SDK we allow users to set the SENTRY_ENVIRONMENT env variable.
  • In NextJS (server-side) we check for the vercel env
  • by default afaict, we don't set any environment tag which makes Relay set production

I actually don't know what the expected behaviour is and how SDKs of other languages handle this. We should investigate this further and ideally settle on common behaviour. Thanks for raising!

Lms24 avatar Mar 10 '25 12:03 Lms24

This is more about the dev mode environment, right?

Someone created a PR for Nuxt but we closed it as it was not finished (https://github.com/getsentry/sentry-javascript/pull/15179). We can pick it up again but I think it would make sense to create a solution to detect the dev environment for all SDKs.

In the case of Nuxt, it's just looking for import.meta.dev as it is Vite-based. We could just check what's available during dev mode.

s1gr1d avatar Mar 10 '25 12:03 s1gr1d

heads-up: I took the liberty to re-classify this as an Improvement instead of a bug. So far this was somewhat "expected" SDK behaviour.

Lms24 avatar Mar 11 '25 16:03 Lms24

same as : #15147

maximepvrt avatar May 23 '25 07:05 maximepvrt