Skip to content

Conversation

@stefanosiano
Copy link
Contributor

@stefanosiano stefanosiano commented Jul 15, 2025

📜 Description

Adds autoTransactionDeadlineTimeoutMillis to SentryOptions to control the deadline for automatic transactions (Activity, Gesture, Navigation).
It defaults to 30 seconds, and a value <= 0 disables the deadline entirely.

💡 Motivation and Context

Fixes #4251

💚 How did you test it?

Unit tests

📝 Checklist

  • I added tests to verify the changes.
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled.
  • I updated the docs if needed.
  • I updated the wizard if needed.
  • Review from the native team if needed.
  • No breaking change or entry added to the changelog.
  • No breaking change for hybrid SDKs or communicated to hybrid SDKs.

🔮 Next steps

@stefanosiano stefanosiano changed the title [To check] Add auto transaction deadline timeout option Add autoTransactionDeadlineTimeoutMillis option Jul 16, 2025
@stefanosiano stefanosiano marked this pull request as ready for review July 16, 2025 15:18
@github-actions
Copy link
Contributor

github-actions bot commented Jul 16, 2025

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 442.38 ms 448.94 ms 6.56 ms
Size 1.58 MiB 2.09 MiB 519.43 KiB

Previous results on branch: cursor/add-auto-transaction-deadline-timeout-option-250f

Startup times

Revision Plain With Sentry Diff
1f38ee2 570.83 ms 655.98 ms 85.15 ms

App size

Revision Plain With Sentry Diff
1f38ee2 1.58 MiB 2.09 MiB 519.47 KiB

@romtsn
Copy link
Member

romtsn commented Jul 16, 2025

@sentry review

@seer-by-sentry
Copy link

PR Description

This pull request introduces a new configuration option, autoTransactionDeadlineTimeoutMillis, to control the deadline timeout for automatically created transactions in the Sentry Android SDK. This allows users to customize how long the SDK waits before automatically finishing a transaction, providing more flexibility in managing transaction lifecycles.

Click to see more

Key Technical Changes

  1. Added a new autoTransactionDeadlineTimeoutMillis property to the SentryOptions class, including getter and setter methods. This property allows users to specify the deadline timeout in milliseconds.
  2. Modified ActivityLifecycleIntegration, SentryGestureListener, and SentryNavigationListener to utilize the new autoTransactionDeadlineTimeoutMillis option when creating transactions. The deadline timeout is now configurable based on this option.
  3. Updated ManifestMetadataReader to read the autoTransactionDeadlineTimeoutMillis value from the AndroidManifest.xml metadata, allowing users to configure the timeout via the manifest.
  4. Added unit tests to verify the correct behavior of the new option in various scenarios, including positive, zero, and negative timeout values.

Architecture Decisions

The decision was made to add a new option to SentryOptions to provide a centralized configuration point for the deadline timeout. This approach aligns with the existing configuration strategy and simplifies the integration process for users. The use of null to represent 'no deadline' was chosen for consistency with existing timeout configurations.

Dependencies and Interactions

This change primarily affects the transaction creation process within the Android SDK. It interacts with ActivityLifecycleIntegration, SentryGestureListener, and SentryNavigationListener, which are responsible for automatically creating transactions based on activity lifecycle events, user gestures, and navigation events, respectively. It also depends on ManifestMetadataReader to read the configuration from the AndroidManifest.xml. No new external dependencies were introduced.

Risk Considerations

A potential risk is that setting a very long or infinite deadline timeout (by setting the option to 0 or a negative value) could lead to transactions remaining open indefinitely, potentially impacting performance and resource usage. Users should be aware of this when configuring the option. Another consideration is ensuring that the new option is properly documented and communicated to users to avoid confusion.

Notable Implementation Details

The implementation handles zero and negative values for autoTransactionDeadlineTimeoutMillis by treating them as 'no deadline,' effectively disabling the automatic deadline timeout. This behavior is consistent across all components that utilize the option. The unit tests cover various scenarios, including the default timeout value, custom positive timeouts, and disabled timeouts (zero and negative values), ensuring the option functions as expected.

Comment on lines 134 to 138

// Set deadline timeout based on configured option
val deadlineTimeoutMillis = scopes.options.autoTransactionDeadlineTimeoutMillis
// No deadline when zero or negative value is set
it.deadlineTimeout = if (deadlineTimeoutMillis <= 0) null else deadlineTimeoutMillis

Choose a reason for hiding this comment

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

The Kotlin implementation follows the same pattern as the Java implementations, which is good for consistency. However, consider extracting the deadline timeout logic into a utility method to reduce code duplication across ActivityLifecycleIntegration, SentryGestureListener, and SentryNavigationListener.

Suggested change
// Set deadline timeout based on configured option
val deadlineTimeoutMillis = scopes.options.autoTransactionDeadlineTimeoutMillis
// No deadline when zero or negative value is set
it.deadlineTimeout = if (deadlineTimeoutMillis <= 0) null else deadlineTimeoutMillis
// Consider creating a utility method like:
// private fun getDeadlineTimeoutFromOptions(options: SentryOptions): Long? {
// val deadlineTimeoutMillis = options.autoTransactionDeadlineTimeoutMillis
// return if (deadlineTimeoutMillis <= 0) null else deadlineTimeoutMillis
// }

Did we get this right? 👍 / 👎 to inform future reviews.

Copy link
Member

@romtsn romtsn left a comment

Choose a reason for hiding this comment

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

lgtm, besides the naming.

@stefanosiano stefanosiano enabled auto-merge (squash) July 17, 2025 10:25
@stefanosiano stefanosiano merged commit 0d667ec into main Jul 17, 2025
31 of 33 checks passed
@stefanosiano stefanosiano deleted the cursor/add-auto-transaction-deadline-timeout-option-250f branch July 17, 2025 10:39
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.

Android - Add possibility to remove deadline timeout for activity transactions

5 participants