Skip to content
Merged
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
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@

### Fixes

- Nav3: `sentry-android-navigation3` no longer declares a dependency on `androidx.lifecycle:lifecycle-runtime-compose`. Nav3 apps already depend on it via `navigation3-ui`, so no app changes are necessary ([#6699](https://github.com/getsentry/sentry-java/pull/6699))
- Profiling: No longer crash on API 35+ devices whose framework can't load `ProfilingManager`. Perfetto profiling is turned off on those devices instead ([#6742](https://github.com/getsentry/sentry-java/pull/6742))

### Dependencies

- Nav3: `sentry-android-navigation3` no longer declares a dependency on `androidx.lifecycle:lifecycle-runtime-compose`. Nav3 apps already depend on it via `navigation3-ui`, so no app changes are necessary ([#6699](https://github.com/getsentry/sentry-java/pull/6699))

## 8.65.1

### Fixes
Expand Down
1 change: 1 addition & 0 deletions sentry-android-navigation3/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ dependencies {
testImplementation(libs.androidx.test.ext.junit)
testImplementation(libs.androidx.viewpager2)
testImplementation(libs.google.truth)
testImplementation(libs.kotlin.test.junit)
testImplementation(libs.mockito.core)
testImplementation(libs.mockito.kotlin)
testImplementation(libs.roboelectric)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ public class SentryBackStackEntry(
* - [CharSequence]
* - [Char]
* - [Boolean]
* - any [Number] (`NaN` and infinite values are sent as strings)
* - any [Number] (`NaN` and infinite values are sent as the strings `"NaN"`, `"Infinity"`, and
* `"-Infinity"`, which JSON can represent)
* - enums (via [Enum.name])
* - `null`
*
Expand All @@ -109,9 +110,9 @@ public class SentryBackStackEntry(
* All non-supported argument types are stringified via `toString()`, as are map keys.
*
* No arguments will be recorded for a back stack entry if [map] throws or returns `null`, or if its
* arguments are cyclic, too deeply nested, too large, or contain map keys that stringify to the
* same string. If the SDK drops an entry's arguments, it adds a `dropped_by_sentry` field and
* corresponding reason (e.g., `duplicate_key`) in the Sentry UI.
* arguments are cyclic, too deeply nested, or too large, or contain a map with two keys that are
* stringified the same way (e.g., `1` and `"1"`). If the SDK drops an entry's arguments, it adds a
* `dropped_by_sentry` field and corresponding reason (e.g., `duplicate_key`) in the Sentry UI.
*
* **Using kotlinx.serialization**
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.sentry.compose.navigation3.internal.backstack

import androidx.compose.runtime.snapshots.Snapshot
import io.sentry.ILogger
import io.sentry.SentryLevel.WARNING
import io.sentry.compose.navigation3.BackStackEntryMapper
Expand All @@ -26,7 +27,7 @@ import java.util.IdentityHashMap
* **Threading policy**
*
* This class performs work synchronously on the calling thread. The host app's
* [BackStackEntryMapper] is invoked on that same thread and should remain small, non-blocking, and
* `BackStackEntryMapper` is invoked on that same thread and should remain small, non-blocking, and
* safe for the caller's threading context.
*/
internal class BackStackConverter<T : Any>(
Expand Down Expand Up @@ -86,7 +87,12 @@ internal class BackStackConverter<T : Any>(
}

val sanitizedArguments =
info.arguments?.let(sanitizer::sanitizeEntry) ?: SanitizedArguments(emptyMap())
info.arguments?.let { arguments ->
// Argument conversion may read Compose state through host app code. Suppress read
// observation so changes to that state don't trigger recomposition solely b/c our
// telemetry code read it.
Snapshot.withoutReadObservation { sanitizer.sanitizeEntry(arguments) }
Comment thread
0xadam-brown marked this conversation as resolved.
Resolved
} ?: SanitizedArguments(emptyMap())
val formattedName = NormalizedSentryBackStackEntry.formatName(info.name)

return if (formattedName.isBlank()) {
Expand Down Expand Up @@ -303,18 +309,19 @@ internal class BackStackConverter<T : Any>(
override fun fillInStackTrace(): Throwable = this
}

private companion object {
companion object {

private const val MAX_CHARACTER_WARNING =
"Nav3 arguments exceeded the maximum total character count for one backstack update. Skipping " +
"arguments for this and older captured entries."
const val MAX_CHARACTER_WARNING =
"Nav3 back stack update exceeded the argument character limit. Dropping arguments for " +
"this and older entries."

private const val MAX_COUNT_WARNING =
"Nav3 arguments exceeded the maximum total count for one backstack update. Skipping arguments for " +
"this and older captured entries."
const val MAX_COUNT_WARNING =
"Nav3 back stack update exceeded the argument value limit. Dropping arguments for this " +
"and older entries."

private const val STRUCTURE_WARNING =
"Nav3 argument sanitization failed (possibly a cyclic or deeply nested structure). Skipping arguments."
const val STRUCTURE_WARNING =
"Nav3 argument sanitization failed (possibly cyclic or too deeply nested). Dropping this " +
"entry's arguments."
}
}

Expand All @@ -332,8 +339,7 @@ internal class BackStackConverter<T : Any>(

logger.log(
WARNING,
"Nav3 backStackEntryMapper returned a blank name while processing this back stack update. " +
"Using $UNKNOWN_ENTRY_NAME instead.",
"Nav3 backStackEntryMapper returned a blank name. Using $UNKNOWN_ENTRY_NAME.",
)
hasLoggedInvalidNameWarning = true
}
Expand All @@ -345,8 +351,7 @@ internal class BackStackConverter<T : Any>(

logger.log(
WARNING,
"Nav3 backStackEntryMapper threw while resolving an entry. " +
"Using $UNKNOWN_ENTRY_NAME without arguments instead.",
"Nav3 backStackEntryMapper threw. Using $UNKNOWN_ENTRY_NAME without arguments.",
throwable,
)
hasLoggedMapperFailureWarning = true
Expand All @@ -359,10 +364,8 @@ internal class BackStackConverter<T : Any>(

logger.log(
WARNING,
"Nav3 backStackEntryMapper returned unsupported argument value of type %s while processing this back " +
"stack update. Falling back to toString(). Use String, CharSequence, Char, Number, " +
"Boolean, Enum, Map, Collection, object Array, and primitive array values for reliable " +
"results.",
"Nav3 argument type %s is unsupported. Using toString(). Return scalars, enums, maps, " +
"collections, or arrays from BackStackEntryMapper.",
typeName,
)
hasLoggedUnsupportedValueWarning = true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package io.sentry.compose.navigation3.internal.backstack

import androidx.lifecycle.LifecycleEventObserver
import io.sentry.Breadcrumb
import io.sentry.Hint
import io.sentry.IScope
import io.sentry.IScopes
import io.sentry.SentryIntegrationPackageStorage
import io.sentry.SentryLevel.INFO
import io.sentry.SentryOptions
Expand All @@ -16,6 +19,9 @@ import io.sentry.compose.navigation3.internal.lifecycle.INavScope
import io.sentry.compose.navigation3.internal.lifecycle.INavScopes
import io.sentry.compose.navigation3.internal.lifecycle.NAVIGATION_CONTEXT_KEY
import io.sentry.compose.navigation3.internal.lifecycle.NAVIGATION_OP
import io.sentry.compose.navigation3.internal.lifecycle.NavLeaseCoordinator
import io.sentry.compose.navigation3.internal.lifecycle.NavRootInfo
import io.sentry.compose.navigation3.internal.lifecycle.NavScopes
import io.sentry.compose.navigation3.internal.lifecycle.NavTransactionRequest
import io.sentry.util.IntegrationUtils.addIntegrationToSdkVersion
import java.lang.ref.WeakReference
Expand Down Expand Up @@ -379,3 +385,70 @@ private class NavBreadcrumbs(private val scopes: INavScopes) {
scopes.addBreadcrumb(breadcrumb, hint)
}
}

/**
* A [BackStackObserver] whose updates to a shared mutable [IScope] are coordinated with those of
* other `BackStackObserver`s.
*
* Coordination is achieved via [NavScopes].
*
* **Usage**
*
* Call [attach] before the first [onBackStackChanged], and call [dispose] when observation ends.
*
* Instances targeting the same [IScope] must be created with the same [NavLeaseCoordinator].
*
* **Thread safety**
*
* This class is ***not*** thread-safe. Invocations should be confined to the same thread as the
* [LifecycleEventObserver] callbacks through which the [NavLeaseCoordinator] observes the attached
* lifecycle.
*/
internal class CoordinatedBackStackObserver<T : Any>(
scopes: IScopes,
options: SentryNavOptions,
entryMapper: ForwardingBackStackEntryMapper<T>,
coordinator: NavLeaseCoordinator,
) {

private val navScopes = NavScopes(scopes, coordinator)
private val observer = BackStackObserver(navScopes, options, entryMapper)

fun attach(rootInfo: NavRootInfo) {
navScopes.attach(rootInfo)
}

fun onBackStackChanged(backStack: List<T>) {
navScopes.onBackStackUpdate()
observer.onBackStackChanged(backStack)
}

fun dispose() {
// Call disposal on both the observer and navScopes in case their (currently overlapping)
// implementations drift over time.
observer.dispose()
navScopes.dispose()
}
}

/**
* The [NavLeaseCoordinator] shared by default by all [CoordinatedBackStackObserver]s.
*
* **Lifetime**
*
* The default coordinator lives as long as the process, since lease state follows nav root
* lifecycles rather than the SDK's. Closing and re-initializing the SDK doesn't require a reset
* because:
*
* - `SentryNavEffect` resolves the current scopes on every call;
*
* - while the SDK is closed, bookkeeping continues without a scope; and
*
* - unpublishing compares by reference, so values published to an earlier scope don't affect the
* current one.
*
* Limitation: A nav transaction that's still running when the SDK is closed and re-initialized can
* be bound to the new scope the next time it's published, although its client has been closed.
* Spans then attach to it, and are lost, until it times out or the next navigation finishes it.
*/
internal val defaultNavLeaseCoordinator: NavLeaseCoordinator = NavLeaseCoordinator()

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# `io.sentry.compose.navigation3.internal.backstack`

This package converts a host app's back stack into Sentry navigation data: screen names, navigation
breadcrumbs, transactions, and the captured back stack.

## Mapping and sanitization

The host app's `BackStackEntryMapper` supplies each entry's name and optional arguments in a
`SentryBackStackEntry`. Properties are the fields and values on the host's back stack entry;
arguments are the values the mapper chooses to expose as `SentryBackStackEntry.arguments`.

Arguments are the mapper's output before sanitization. `BackStackConverter` normalizes entry names
and sanitizes arguments before they are recorded. Sanitization can stringify values or drop an
entry's arguments when they are invalid or exceed the limits in `ArgumentConstraints`.
The value and character budgets are shared across the entries captured in one back stack update.

## Observation and coordination

`BackStackObserver` detects changes and records navigation data for one back stack.
`CoordinatedBackStackObserver` connects that observer to `NavScopes`, which coordinates access to
shared scope state with other navigation roots. The lifecycle and ownership rules live in the
[sibling lifecycle package](../lifecycle/README.md).
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ This package is meant to encapsulate knowledge about the possibility of multiple
raises. Addressing those concerns is complicated. Confining them here makes them easier to reason about and easier to swap for alternative
logic should we someday need to.

## Dependencies

This package may ***not*** depend on any other `io.sentry.compose.navigation3` package, Compose, or
`androidx.navigation3`. It may use Android framework and AndroidX Lifecycle APIs directly.

## Limitations

Support for multiple `SentryNavEffect`s is restricted to the scenarios documented in the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ internal class StagedNavData {
* Clears the screen and nav context this instance published, unless something else has replaced
* them in [realScope] since.
*/
@Suppress("AvoidReferentialEquality")
fun clearPublishedStateFrom(realScope: IScope) {
// Identity tracks the screen we published; equal but distinct host replacements must survive.
if (publishedScreen != null && realScope.screen === publishedScreen) {
realScope.screen = null
}
Expand Down
Loading
Loading