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

Using Sentry Electron with Sentry React will cause the environment tag to be missing #1030

Open
3 tasks done
Claudia-teng opened this issue Dec 6, 2024 · 2 comments
Open
3 tasks done
Assignees

Comments

@Claudia-teng
Copy link

Claudia-teng commented Dec 6, 2024

Is there an existing issue for this?

How do you use Sentry?

Self-hosted/on-premise

Electron SDK Version

5.7.0

Electron Version

28.3.3

What platform are you using?

MacOS

Link to Sentry event

No response

Steps to Reproduce

  1. Add sentry electron & sentry react to renderer process as the document recommended
    https://docs.sentry.io/platforms/javascript/guides/electron/#framework-specific-sdks
import * as Sentry from '@sentry/electron/renderer'
import { init as ReactInit } from '@sentry/react'

Sentry.init(
  {
    dsn: import.meta.env.VITE_SENTRY_DSN,
    environment: process.env.NODE_ENV
  },
  ReactInit
)
  1. Throw an error in the renderer process function

  2. Build the electron app

  3. Occur the function that makes error

  4. Check Sentry error with json format, and there's no environment attribute under "tags".

"tags": [
    [
      "browser.name",
      "Chrome"
    ],
    [
      "chrome",
      "Chrome 120.0.6099.291"
    ],
    [
      "chrome.name",
      "Chrome"
    ],
    [
      "device.family",
      "Desktop"
    ],
    [
      "event.environment",
      "javascript"
    ],
    [
      "event.origin",
      "electron"
    ],
    [
      "event.process",
      "renderer"
    ],
    [
      "handled",
      "yes"
    ],
    [
      "level",
      "error"
    ],
    [
      "mechanism",
      "generic"
    ],
    [
      "node",
      "Node 18.18.2"
    ],
    [
      "node.name",
      "Node"
    ],
    [
      "os",
      "macOS 13.3.1"
    ],
    [
      "os.name",
      "macOS"
    ],
    [
      "runtime",
      "Electron 28.3.3"
    ],
    [
      "runtime.name",
      "Electron"
    ],
    [
      "release",
      "xxx"
    ],
    [
      "user",
      "xxx"
    ],
    [
      "url",
      "xxx"
    ]
  ],

This will make environment field to be "--" on Sentry ui.
Image

This only happens in production mode. In development mode, there is an "environment" tag,

 "tags": [
    [
      "browser.name",
      "Chrome"
    ],
    [
      "chrome",
      "Chrome 120.0.6099.291"
    ],
    [
      "chrome.name",
      "Chrome"
    ],
    [
      "device.family",
      "Desktop"
    ],
    [
      "environment",
      "development"
    ],
    [
      "event.environment",
      "javascript"
    ],
    [
      "event.origin",
      "electron"
    ],
    [
      "event.process",
      "renderer"
    ],
    [
      "handled",
      "yes"
    ],
    [
      "level",
      "error"
    ],
    [
      "mechanism",
      "generic"
    ],
    [
      "node",
      "Node 18.18.2"
    ],
    [
      "node.name",
      "Node"
    ],
    [
      "os",
      "macOS 13.3.1"
    ],
    [
      "os.name",
      "macOS"
    ],
    [
      "runtime",
      "Electron 28.3.3"
    ],
    [
      "runtime.name",
      "Electron"
    ],
    [
      "release",
      "xxx"
    ],
    [
      "user",
      "xxx"
    ],
    [
      "url",
      "xxx"
    ]
  ],

Expected Result

Can see which environment the error occurs

Actual Result

Missing the environment field

--

But If I only import sentry react, the environment tag appears.
It seems that using only sentry react works for catching correct errors and environment.

import * as Sentry from '@sentry/react'

Sentry.init({
  dsn: import.meta.env.VITE_SENTRY_DSN,
  environment: process.env.NODE_ENV
})

error json

"tags": [
    [
      "browser",
      "Electron 28.3.3"
    ],
    [
      "browser.name",
      "Electron"
    ],
    [
      "device",
      "Mac"
    ],
    [
      "device.family",
      "Mac"
    ],
    [
      "environment",
      "production"
    ],
    [
      "handled",
      "yes"
    ],
    [
      "level",
      "error"
    ],
    [
      "mechanism",
      "generic"
    ],
    [
      "os",
      "Mac OS X \u003E=10.15.7"
    ],
    [
      "os.name",
      "Mac OS X"
    ],
    [
      "release",
      "xxx"
    ],
    [
      "user",
      "xxx"
    ],
    [
      "url",
      "xxx"
    ]
  ],

The fields received are different.

Please advise, thanks!

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Dec 6, 2024
@timfish timfish self-assigned this Dec 6, 2024
@timfish
Copy link
Collaborator

timfish commented Dec 7, 2024

Thanks for reporting this. It's on my list of things to take a look at!

@timfish
Copy link
Collaborator

timfish commented Dec 16, 2024

With the Electron SDK, all events from renderers are sent through the Electron main process so that all events include the full app and machine context. The environment in the main process therefore takes precedence so you should set your desired environment there.

Maybe we should add some warnings if an environment is passed in the renderer so this is more obvious 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Development

No branches or pull requests

2 participants