You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 14, 2024. It is now read-only.
Copy file name to clipboardExpand all lines: src/docs/sdk/sessions.mdx
+65-1Lines changed: 65 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -284,7 +284,9 @@ SDKs are encouraged to distinguish between different ways of ending a session:
284
284
A session is supposed to transition to `crashed` when it encountered an unhandled
285
285
error such as a full application crash. For applications that cannot fully
286
286
crash such as a website, it's acceptable to transition to the crashed state if
287
-
the user encountered an error dialog.
287
+
the user encountered an error dialog. For server environments where we create sessions
288
+
for every incoming request, `crashed` is basically like status code `500` internal server error.
289
+
So if there is an unhandled error happening during the request, the session should be `crashed`.
288
290
289
291
Abnormal are sessions of which their fate is unknown. For desktop applications, for instance, it makes sense to transition a session to abnormal if it was stored
290
292
but the exit of the application was not observed but also did not crash. These are situations where the user forced the app to close via the
@@ -427,3 +429,65 @@ The most basic API exposed is on the hub level and lets you start and stop sessi
427
429
`auto_session_tracking`
428
430
429
431
> This enables / disables automatic session tracking through integrations.
432
+
433
+
434
+
## SDK Implementation Guideline
435
+
436
+
We track the health of each release of projects in Sentry by sending session payloads from SDKs.
437
+
The session payload provide data such as session duration and the presence or absence of errors/crashes.
438
+
439
+
SDKs track sessions in one of two modes:
440
+
- Single Session
441
+
- Session Aggregates
442
+
443
+
Single session is the general case, and is a good fit for (relatively short-lived) applications that are typically involving only a single user. Examples:
444
+
- command-line utility like [`craft`](https://github.com/getsentry/craft); <dfntitle="Note: this is just an example, assuming craft was instrumented with a Sentry SDK supporting sessions">every execution of a `craft` subcommand</dfn> report a single session to Sentry
445
+
- user interacting with a mobile app
446
+
- user loading a web site with their favorite browser
447
+
448
+
Session aggregates are used when sending individual sessions would be undesirable or unpractical. To constrain resource usage (namely memory and network), SDKs keep track of summary information about a batch of sessions that occured in the recent past, never actually having to deal with session objects representing the individual sessions that make up the aggregate. This mode is the choice for applications that run for an arbitrarily long time and handle larger throughputs for potentially multiple users, such as web servers, background job workers, etc. Note that for those types of application, a better definition of session matches the execution of a single HTTP request or task, instead of a single execution of the whole application process.
449
+
450
+
In either case, SDKs should create and report sessions by default, choosing to report them individually or as aggregates depending on the type of application.
451
+
452
+
If an SDK can detect that an application is better served by session aggregates, then it must not report an application-wide session. The application-wide session may still be created during SDK initialization but must be aborted and never sent to Sentry. As an example, in the Node.js SDK, we can detect an application is probably a web server if it uses the `requestHandler` integration that is provided.
453
+
454
+
### Individual Session Functionality
455
+
456
+
#### Configuration
457
+
458
+
- On by default for global/static API;
459
+
User should be able to disable sessions if they don't want to track them.
460
+
461
+
Pre-requisites for reporting sessions and determining Release Health of projects in Sentry, such as release should be automatically detected by the SDK such as by looking up env vars.
462
+
463
+
(Maybe, needs discussion) if I pre-requisite cannot be detect (for example, no good way to determine release version), then we set some default value so that we can always report sessions by default (depending on discussion, this might not be a change in SDK code, but in Relay, basically removing hard-requirements in the session payload).
464
+
465
+
#### Lifetime of a Session
466
+
467
+
Sessions should be enabled by default only for the global hub/client that is initialized by Sentry.init, and disabled by default for any other manually created client.
468
+
A session is started when the SDK is initialized (ideally when the default client is bound to the global hub) and ended when one of these conditions happen:
469
+
The Hub.endSession() method is explicitly called; or
470
+
The program terminates without errors; or
471
+
The program terminates with an unhandled exception; or
472
+
The program terminates with an unhandled promise rejection.
473
+
474
+
Care must be taken to never attempt to send new session payloads to Sentry for a session that is already ended. For example, if the user manually ends the session with Hub.endSession(), there should not be any new updates to the session when the program terminates.
475
+
476
+
#### Session Atrributes and Mutability
477
+
478
+
#### Sending Session to Sentry
479
+
480
+
Session is sent initially after a certain (initially hard-coded, less config is better) delay (something between 1s to 30s TBD), and then updated with the duration and final status and error count when the program terminates. Note that, as an optimization, short lived programs will not send 2 session requests to Relay, but only the final one with status and duration.
481
+
482
+
### Session Aggregates Functionality
483
+
484
+
#### Configuration
485
+
486
+
Sessions should be enabled by default, a session is started as soon as a request is received by a web server and ends as soon as the response is fully sent back.
487
+
488
+
#### Lifetime of a Session
489
+
490
+
Sessions are never tracked nor sent individually, instead they are aggregated and the aggregates are sent every 30s and a final time when the web server is terminating.
491
+
As an implementation hint to the point above, when a "Client" is closed or flushed the associated "Session Flusher" shall also be flushed and submit the current aggregates the the transport, before the transport is flushed/closed.
492
+
Make sure this works reasonably for Serverless — there we shall not use "request mode" and SessionFlusher because we cannot have any work that happens outside of the request-response flow.
493
+
Provide an easy way to integrate with existing Node frameworks (Express, Next.js, Koa).
0 commit comments