sentry-javascript
sentry-javascript copied to clipboard
User sessions are not being tracked properly
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 package are you using?
@sentry/nextjs
SDK Version
7.13.0
Framework Version
12.2.5
Link to Sentry event
No response
SDK Setup
import * as Sentry from '@sentry/nextjs';
import {
BrowserClient,
Breadcrumbs,
Dedupe,
defaultStackParser,
getCurrentHub,
GlobalHandlers,
makeFetchTransport,
LinkedErrors,
HttpContext,
FunctionToString,
InboundFilters
} from '@sentry/browser';
const isProd = process.env.NODE_ENV === 'production';
const config = {
dsn: typeof SENTRY_DSN !== 'undefined' ? SENTRY_DSN : '',
environment: typeof ENV !== 'undefined' ? ENV : 'unknown',
sampleRate: isProd ? 0.7 : 0,
tracesSampleRate: 0
};
const client = new BrowserClient({
// all options you normally pass to Sentry.init
...config,
// ...
transport: makeFetchTransport,
stackParser: defaultStackParser,
// Only the integrations listed here will be used
integrations: [
new Breadcrumbs(),
new GlobalHandlers(),
new LinkedErrors(),
new Dedupe(),
new HttpContext(),
new InboundFilters(),
new FunctionToString()
]
});
getCurrentHub().bindClient(client);
Sentry.setTag('platform', 'unknown');
Steps to Reproduce
- The above SDK setup taken from https://docs.sentry.io/platforms/javascript/configuration/tree-shaking/
- See user sessions are not being tracked.
Expected Result
User sessions should be tracked right
Actual Result
// This file configures the initialization of Sentry on the server.
// The config you add here will be used whenever the server handles a request.
// https://docs.sentry.io/platforms/javascript/guides/nextjs/
import * as Sentry from '@sentry/nextjs';
const isProd = process.env.NODE_ENV === 'production';
Sentry.init({
dsn: process.env.SENTRY_DSN || '',
authToken: process.env.SENTRY_AUTH_TOKEN,
environment: process.env.ENV || 'unknown',
sampleRate: isProd ? 0.7 : 0,
tracesSampleRate: 0
});
This works and tracks the user session
Sentry config given here https://docs.sentry.io/platforms/javascript/configuration/tree-shaking , does not track user sessions somehow and the crash reporting dashboard shows incorrect values as user sessions are ideally 0, errors are being tracked correctly though
Oh yeah, when creating a custom client you currently have to manually start sessions as they are normally created and in the Sentry.init().
We should probably make this part of the individual clients instead.
This issue has gone three weeks without activity. In another week, I will close it.
But! If you comment or otherwise update it, I will reset the clock, and if you remove the label Waiting for: Community, I will leave it alone ... forever!
"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀