Understanding the events sent by the JS SDK, `type: session`

I’m trying to understand why the JS SKD is constantly sending events to Sentry with the following payload (schema):

{"sent_at":"...","sdk":{"name":"sentry.javascript.browser","version":"6.2.3"}}
{"type":"session"}
{"sid":"....","init":false,"started":"..." ,"timestamp":"...","status":"exited","errors":0,"did":"...","duration":4127,"attrs":{"release":"app@dev"}}

In almost every click I get two of those events being sent. Once with init: false and the other with a different sid and init: true.

I would like to know how does the SDK get the sid, and why is it changing so often?


This is an PWA. Our integration with Sentry is quite simple (in coffescript):

if SENTRY_DSN?
  window.Sentry.init
    dsn: SENTRY_DSN
    release: SENTRY_RELEASE
    environment: SENTRY_ENVIRONMENT
    integrations: [new window.SentryIntegrations.BrowserTracing()]
    tracesSampleRate: 0.35

Hi @mvaled, sessions are used to report on Release Health.

Hi there @rhcarvalho . We are experiencing the same “problem” in our Angular application after updating Sentry (from “@sentry/browser”: “^5.29.2”, “@sentry/cli”: “^1.61.0”, to “@sentry/browser”: “^6.12.0”, “@sentry/cli”: “^1.68.0”).

I would like to know if the described behavior is “expected”. Is it really meant to send those requests with init true/false all the time? This somehow doesn’t seem right ^^

I am also wondering why this is happening after updating, did this feature get introduced some when after 5.29.2 oder did its behavior change (was the default for autoSessionTracking false before)? :thinking:

Edit:
I just found out that it was added in version 6.0.0:

Starting from the version 6.0.0 , all SDKs that support sending sessions data will do so by default. See our Release Health docs to learn more.

So the actual question that remains: is it really supposed to send those two requests all the time or do I still have to configure something here?

You are right. The behavior change was introduced in v6.x.

So the actual question that remains: is it really supposed to send those two requests all the time or do I still have to configure something here?

It should only send one request with a payload like

{"sent_at":"2021-10-06T10:02:47.359Z","sdk":{"name":"sentry.javascript.browser","version":"6.13.0"}}
{"type":"session"}
{"sid":"9bdc7011d74042acbd1b57b8806fe928","init":true, ...

And in case of an error there should be a second request with "init":false that updates the session marking it unhealthy.

This feature allows you to monitor the health of your releases, and for example identify that a newly deployed release is causing more errors or that, conversely, it reduced the number of errors after deploying a bugfix.

If you don’t want to use this feature, you can disable it:

Sentry.init({
  autoSessionTracking: false // default: true
});