Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ window.Sentry = Sentry;
Sentry.init({
dsn: 'https://public@dsn.ingest.sentry.io/1337',
release: '0.1',
integrations: [Sentry.browserSessionIntegration({ lifecycle: 'route' })],
initialScope: {
user: {
id: '1337',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ window.Sentry = Sentry;
Sentry.init({
dsn: 'https://public@dsn.ingest.sentry.io/1337',
release: '0.1',
integrations: [Sentry.browserSessionIntegration({ lifecycle: 'page' })],
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
waitForSession,
} from '../../../utils/helpers';

sentryTest('starts a session on pageload with page lifecycle.', async ({ getLocalTestUrl, page }) => {
sentryTest('starts a session on pageload with page lifecycle (default).', async ({ getLocalTestUrl, page }) => {
const url = await getLocalTestUrl({ testDir: __dirname });

const sessionPromise = waitForSession(page, s => !!s.init && s.status === 'ok');
Expand All @@ -32,7 +32,7 @@ sentryTest('starts a session on pageload with page lifecycle.', async ({ getLoca
});

sentryTest(
"doesn't start a new session on pushState navigation with page lifecycle.",
"doesn't start a new session on pushState navigation with page lifecycle (default).",
async ({ getLocalTestUrl, page }) => {
const url = await getLocalTestUrl({ testDir: __dirname });

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ window.Sentry = Sentry;
Sentry.init({
dsn: 'https://public@dsn.ingest.sentry.io/1337',
release: '0.1',
integrations: [Sentry.browserSessionIntegration({ lifecycle: 'route' })],
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { sentryTest } from '../../../utils/fixtures';
import { waitForSession } from '../../../utils/helpers';

sentryTest(
'should start new sessions on pushState navigation with route lifecycle (default).',
'should start new sessions on pushState navigation with route lifecycle.',
async ({ getLocalTestUrl, page }) => {
const url = await getLocalTestUrl({ testDir: __dirname });

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import * as Sentry from '@sentry/browser';

window.Sentry = Sentry;

Sentry.init({
dsn: 'https://public@dsn.ingest.sentry.io/1337',
release: '0.1',
integrations: [Sentry.browserSessionIntegration({ lifecycle: 'route' })],
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import * as Sentry from '@sentry/browser';

window.Sentry = Sentry;

Sentry.init({
dsn: 'https://public@dsn.ingest.sentry.io/1337',
release: '0.1',
integrations: [Sentry.browserSessionIntegration({ lifecycle: 'route' })],
});
10 changes: 4 additions & 6 deletions packages/browser/src/integrations/browsersession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@ interface BrowserSessionOptions {
/**
* Controls the session lifecycle - when new sessions are created.
*
* - `'route'`: A session is created on page load and on every navigation.
* This is the default behavior.
* - `'page'`: A session is created once when the page is loaded. Session is not
* updated on navigation. This is useful for webviews or single-page apps where
* URL changes should not trigger new sessions.
* updated on navigation. This is the default behavior.
* - `'route'`: A session is created on page load and on every navigation.
*
* @default 'route'
* @default 'page'
*/
lifecycle?: 'route' | 'page';
}
Expand All @@ -25,7 +23,7 @@ interface BrowserSessionOptions {
* Note: In order for session tracking to work, you need to set up Releases: https://docs.sentry.io/product/releases/
*/
export const browserSessionIntegration = defineIntegration((options: BrowserSessionOptions = {}) => {
const lifecycle = options.lifecycle ?? 'route';
const lifecycle = options.lifecycle ?? 'page';

return {
name: 'BrowserSession',
Expand Down
Loading