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

feat: Add integration to track sessions as app in foreground #725

Merged
merged 16 commits into from
Sep 11, 2023

Conversation

timfish
Copy link
Collaborator

@timfish timfish commented Aug 30, 2023

Closes #712

This PR

  • Adds the BrowserWindowSession integration which tracks sessions as when the app has focus
  • There is a timout to ensure that sessions are not ended immediatly if a user briefly switches away from the app
    • The default timeout is 30 seconds but this is configurable via the backgroundTimeoutSeconds constructor option.
  • The session on exit handling was moved to src/main/sessions.ts since this is now use by both session integrations
  • Some changes to the default integration logic were required to ensure only one session integration is used
  • Errors or crashes while the app is in the background will not be attributed to any session
const { init, Integrations } = require('@sentry/electron');

init({
  dsn: '__DSN__',
  integrations: [new Integrations.BrowserWindowSession({ backgroundTimeoutSeconds: 10 })],
});

@timfish timfish changed the title feat: Add option to track sessions as app focus feat: Add integration to track sessions as app in foreground Aug 30, 2023
@timfish
Copy link
Collaborator Author

timfish commented Aug 30, 2023

I've limited this new feature to Electron >= v12 since older versions of Electron seem to unreliably report focus events which make this quite unreliable for sessions.

Electron v12 has been EOL for nearly 2 years now and nobody should be using it for new projects!

@timfish timfish marked this pull request as ready for review August 31, 2023 09:19
@AbhiPrasad
Copy link
Member

Errors or crashes while the app is in the background will not be attributed to any session

Let me clarify with the mobile SDKs about what they do here.

Copy link
Member

@AbhiPrasad AbhiPrasad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be nice to get a test for errored session as well.

src/main/integrations/browser-window-session.ts Outdated Show resolved Hide resolved
src/main/integrations/browser-window-session.ts Outdated Show resolved Hide resolved
@AbhiPrasad
Copy link
Member

Errors or crashes while the app is in the background will not be attributed to any session

The behaviour we kept here is good to go!

@timfish timfish merged commit b247856 into getsentry:master Sep 11, 2023
40 checks passed
@timfish timfish deleted the feat/window-sessions branch September 11, 2023 16:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Stop sessions if app goes into background
2 participants