Skip to content

fix(android): [Logs and Metrics Enable Flags 19] Read Timber option lazily - #5964

Open
adinauer wants to merge 2 commits into
docs/update-options-guidancefrom
fix/timber-lazy-logs-option
Open

fix(android): [Logs and Metrics Enable Flags 19] Read Timber option lazily#5964
adinauer wants to merge 2 commits into
docs/update-options-guidancefrom
fix/timber-lazy-logs-option

Conversation

@adinauer

@adinauer adinauer commented Aug 13, 2026

Copy link
Copy Markdown
Member

PR Stack (Logs and Metrics Enable Flags)


📜 Description

Makes the auto-installed Timber integration resolve enableTimberLogs lazily when the integration registers rather than snapshotting it while Android default integrations are constructed.

This honors the final option value after the Android configuration callback, including both programmatic opt-in and programmatic override of manifest configuration. Existing boolean constructors continue to behave as fixed values for manually installed integrations.

💡 Motivation and Context

Android installs default integrations before invoking the user's options callback so users can remove or replace them. Passing the current boolean value into Timber at that earlier point caused later programmatic configuration to be ignored.

💚 How did you test it?

  • ./gradlew :sentry-android-timber:testReleaseUnitTest :sentry-android-core:testReleaseUnitTest
  • ./gradlew spotlessApply apiDump
  • Added full Android initialization tests for callback false -> true and manifest true -> callback false
  • Added an integration-level test proving the supplier is evaluated at registration

📝 Checklist

  • I added GH Issue ID & Linear ID
  • 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.

#skip-changelog

⚠️ Merge this PR using a merge commit (not squash). Only the collection branch is squash-merged into main.

This was referenced Aug 13, 2026
Resolve the auto-installed Timber integration's Logs opt-in lazily when the integration registers. This honors programmatic configuration and manifest overrides applied after default integrations are constructed.

Co-Authored-By: Claude <noreply@anthropic.com>
@adinauer
adinauer force-pushed the fix/timber-lazy-logs-option branch from d7c56cc to 6e791e5 Compare August 13, 2026 11:46
@sentry

sentry Bot commented Aug 13, 2026

Copy link
Copy Markdown

📲 Install Builds

Android

🔗 App Name App ID Version Configuration
SDK Size io.sentry.tests.size 8.52.0 (1) release

⚙️ sentry-android Build Distribution Settings

@github-actions

Copy link
Copy Markdown
Contributor

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 377.30 ms 438.92 ms 61.62 ms
Size 0 B 0 B 0 B

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 4d120ff. Configure here.

}

public constructor(enableLogsProvider: Evaluator<Boolean>) : this() {
this.enableLogsProvider = enableLogsProvider

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Internal type in public constructor

Medium Severity

The new public SentryTimberIntegration constructor takes LazyEvaluator.Evaluator, which is @ApiStatus.Internal. That pulls an internal type into the published Timber API surface (also reflected in the .api dump) even though this path is only needed for auto-install. Similar SDK call sites that accept Evaluator live on @ApiStatus.Internal types.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 4d120ff. Configure here.


if (isTimberAvailable) {
options.addIntegration(new SentryTimberIntegration(options.isEnableTimberLogs()));
options.addIntegration(new SentryTimberIntegration(options::isEnableTimberLogs));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bug: A method reference options::isEnableTimberLogs was introduced, violating a class-level suppression intended to prevent them due to compatibility issues with older Android Gradle Plugin versions.
Severity: MEDIUM

Suggested Fix

To maintain compatibility with older Android Gradle Plugin versions, replace the method reference with an explicit lambda expression. Change new SentryTimberIntegration(options::isEnableTimberLogs) to new SentryTimberIntegration(() -> options.isEnableTimberLogs()), which aligns with the established pattern in the file.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location:
sentry-android-core/src/main/java/io/sentry/android/core/AndroidOptionsInitializer.java#L476

Potential issue: The file `AndroidOptionsInitializer.java` contains a class-level
`@SuppressWarnings("Convert2MethodRef")` annotation, explicitly added to prevent the use
of method references due to compatibility issues with older Android Gradle Plugin (AGP)
versions. The pull request introduces a method reference `options::isEnableTimberLogs`
at line 476, which violates this established project-wide convention. This change can
lead to build or runtime failures for developers using older, supported AGP versions,
which the project appears to support based on its conservative compatibility standards.

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

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.

1 participant