feat(android): [Session based Traces for Mobile 1B] Add session trace lifecycle#5398
feat(android): [Session based Traces for Mobile 1B] Add session trace lifecycle#5398adinauer wants to merge 6 commits into
Conversation
Reuse the active session propagation context for eligible mobile root transactions while preserving explicit continuations and force-new trace escapes. Add Android integration guards, configuration, and tests for the opt-in lifecycle behavior. Co-Authored-By: Claude <noreply@anthropic.com>
Treat session trace lifecycle as an option-level behavior instead of storing lifecycle state on each propagation context. This keeps the current propagation context as the ambient trace source whenever session trace lifecycle is enabled. Co-Authored-By: Claude <noreply@anthropic.com>
Reuse SpanContext copy logic when remapping root transactions onto the session propagation context. Preserve transaction identity while replacing the trace id and clearing the parent span id. Co-Authored-By: Claude <noreply@anthropic.com>
Use parent span presence as the session trace lifecycle opt-out instead of a separate TransactionContext flag. Co-Authored-By: Claude <noreply@anthropic.com>
|
📲 Install BuildsAndroid
|
Performance metrics 🚀
|
Co-Authored-By: Claude <noreply@anthropic.com>
| /** Whether to enable or disable automatic session tracking. */ | ||
| private boolean enableAutoSessionTracking = true; | ||
|
|
||
| /** Whether root transactions should reuse the current session trace lifecycle. */ |
There was a problem hiding this comment.
imo this should be more generic since trace re-use is not only specific to spans/transactions, wdyt?
| /** Whether root transactions should reuse the current session trace lifecycle. */ | |
| /** Whether telemetry should reuse the current session trace lifecycle. */ |
There was a problem hiding this comment.
It does only affect head of trace transactions (no parentSpanID) so the current version sounds more correct to me.
There was a problem hiding this comment.
which traceId do errors, metrics, logs inherit then?
There was a problem hiding this comment.
Those should take traceId from the active transaction if there is any on scope. But since that should be identical to the scopes traceId the distinction would only matter for non head of trace transactions where the new behaviour doesn't kick in.
Probably simplest to change the wording to what you suggested rather than explain SDK internals here.
There was a problem hiding this comment.
ah okay, btw should we scope this option to the android sdk? (not sure about the protocol here when we add new options)
There was a problem hiding this comment.
Since this is used in core SDK, we can't move it to AndroidOptions. We can add a comment to the JavaDoc to explain this is only intended for Android. In docs we can simply not mention it for JVM.
There was a problem hiding this comment.
In the future (new major) we'll likely make this default enabled in AndroidOptionsInitializer.
PR Stack (Session based Traces for Mobile)
📜 Description
Adds opt-in Android session trace lifecycle support and simplifies the trace model by keeping session lifecycle behavior at the option/transaction level instead of storing lifecycle state on
PropagationContext.This PR:
enableSessionTraceLifecycleconfiguration and Android wiringforceNewTracetransaction flag💡 Motivation and Context
Session-based traces on mobile need independently started root transactions to join the ambient app-session trace. Keeping this behavior behind an SDK option and deriving the opt-out from
parentSpanIdavoids per-context lifecycle state while preserving bounded/continued distributed traces.This is the new first PR in the Session based Traces for Mobile stack:
1B.💚 How did you test it?
./gradlew :sentry:compileJava :sentry:compileTestKotlin :sentry-opentelemetry:sentry-opentelemetry-core:compileJava./gradlew :sentry:test --tests 'io.sentry.ScopesTest' --tests 'io.sentry.ScopeTest' --tests 'io.sentry.util.TracingUtilsTest' :sentry-opentelemetry:sentry-opentelemetry-core:test./gradlew :sentry:test --tests 'io.sentry.ScopesTest.when session trace lifecycle is enabled, root transaction uses current propagation context' --tests 'io.sentry.ScopesTest.forceNewTrace does not override continued trace with parent span' spotlessApply apiDump./gradlew :sentry:compileJava :sentry:compileTestKotlin./gradlew :sentry:test --tests 'io.sentry.TransactionContextTest'./gradlew :sentry:compileJava :sentry:compileTestKotlin :sentry:test --tests 'io.sentry.ScopesTest.continued trace with parent span is not remapped to session trace' --tests 'io.sentry.TransactionContextTest'./gradlew spotlessApply apiDump📝 Checklist
sendDefaultPIIis enabled.🔮 Next steps
Continue the Session based Traces for Mobile stack.