Decide session staleness on a monotonic clock in LifecycleWatcher

Aperta
#6,663 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
56/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
android, java, kotlin
Ambito
backend, mobile

Direzione di ricerca

Start with LifecycleWatcher.isSessionOnScopeStale() in sentry-android-core/src/main/java/io/sentry/android/core/LifecycleWatcher.java, then inspect Session and the existing background-path Deadline usage. Check how session start time is stored and serialized; the change is done when the in-memory monotonic start tick supports the staleness decision and is not serialized. The issue points to no specific test, so locate relevant lifecycle and session tests before making the change.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Platform: Android Platform: Java

When the app comes to the foreground with no background window pending, LifecycleWatcher.isSessionOnScopeStale() decides whether to start a new session. This happens when SDK init started the session, rather than the user leaving and coming back. The check compares Session.getStarted() with the wall clock.

A clock step between SDK init and the first foreground gets this wrong:

  • A forward step can start a second session when it shouldn't.
  • A backward step can keep a stale session.

Release health counts session starts, so either case can move session counts.

Fix

Let a Session remember the monotonic tick it started on. Keep it in memory only and don't serialize it. Then decide staleness with a Deadline, as the background path already does.

Context

getsentry/sentry-java#5580 and getsentry/sentry-java#6585 were closed on 2026-11-18 because Relay ignores the session seq and duration fields. This is the one session clock issue left that affects counts.

Agent notes
  • sentry-android-core/src/main/java/io/sentry/android/core/LifecycleWatcher.java: see isSessionOnScopeStale() and its TODO [MAJOR] on 9.x.x (checked 2026-11-18).
  • Relay at f218978dbb: relay-server/src/metrics_extraction/sessions/mod.rs buckets session metrics by started and emits only counts.
Lingua principale
Kotlin
Stelle
1.4k
Fork
483
Merge medio
2g 54m
PR unite (30g)
207

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di getsentry/sentry-java

Tutte le issue di getsentry/sentry-java

Issue simili

Altre issue su Kotlin

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.