Skip to content

Commit c157b54

Browse files
buenaflorclaude
andcommitted
refactor(extend-app-start): Inline the logger lookup instead of injecting it
The extension logs only two warnings, both on rare guard paths in extendAppStart(). Inline Sentry.getCurrentScopes().getOptions().getLogger() at those sites instead of holding a logger field set at init, dropping the field, setLogger(), and the AndroidOptionsInitializer wiring. extendAppStart() runs post-init, so the lookup always yields the configured logger. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 9a9a0e3 commit c157b54

2 files changed

Lines changed: 12 additions & 17 deletions

File tree

sentry-android-core/src/main/java/io/sentry/android/core/AndroidOptionsInitializer.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,7 @@ static void initializeIntegrationsAndProcessors(
198198
}
199199

200200
final @NotNull AppStartMetrics appStartMetrics = AppStartMetrics.getInstance();
201-
final @NotNull AppStartExtension appStartExtension = appStartMetrics.getAppStartExtension();
202-
appStartExtension.setLogger(options.getLogger());
203-
options.setAppStartExtender(appStartExtension);
201+
options.setAppStartExtender(appStartMetrics.getAppStartExtension());
204202

205203
if (options.getModulesLoader() instanceof NoOpModulesLoader) {
206204
options.setModulesLoader(new AssetsModulesLoader(context, options));

sentry-android-core/src/main/java/io/sentry/android/core/AppStartExtension.java

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
package io.sentry.android.core;
22

33
import io.sentry.IAppStartExtender;
4-
import io.sentry.ILogger;
54
import io.sentry.ISentryLifecycleToken;
65
import io.sentry.ISpan;
76
import io.sentry.ITransaction;
8-
import io.sentry.NoOpLogger;
97
import io.sentry.NoOpSpan;
8+
import io.sentry.Sentry;
109
import io.sentry.SentryDate;
1110
import io.sentry.SentryLevel;
1211
import io.sentry.SpanStatus;
@@ -53,10 +52,6 @@ public interface ExtendAppStartListener {
5352
private final @NotNull AppStartMetrics metrics;
5453
private final @NotNull AutoClosableReentrantLock lock = new AutoClosableReentrantLock();
5554

56-
// Set once at SDK init via setLogger(), read later when an extension is requested. Defaults to a
57-
// no-op because this component is created before SentryOptions (and its logger) exist.
58-
private volatile @NotNull ILogger logger = NoOpLogger.getInstance();
59-
6055
private @Nullable ExtendAppStartListener extendAppStartListener;
6156
private @Nullable ISpan extendedSpan;
6257
private @Nullable ITransaction extendedTransaction;
@@ -69,25 +64,27 @@ public void setExtendAppStartListener(final @Nullable ExtendAppStartListener lis
6964
this.extendAppStartListener = listener;
7065
}
7166

72-
void setLogger(final @NotNull ILogger logger) {
73-
this.logger = logger;
74-
}
75-
7667
@Override
7768
public void extendAppStart() {
7869
try (final @NotNull ISentryLifecycleToken ignored = lock.acquire()) {
7970
if (extendedSpan != null) {
80-
logger.log(SentryLevel.WARNING, "App start is already being extended.");
71+
Sentry.getCurrentScopes()
72+
.getOptions()
73+
.getLogger()
74+
.log(SentryLevel.WARNING, "App start is already being extended.");
8175
return;
8276
}
8377
// Ignore the foreground check: headless app starts (broadcast/service) run in a
8478
// non-foreground process but can still be extended. The window gate still rejects an
8579
// extension once an activity was created, the first frame was drawn, or measurements were
8680
// already sent.
8781
if (!metrics.isAppStartWindowOpen()) {
88-
logger.log(
89-
SentryLevel.WARNING,
90-
"Cannot extend app start: the app start window has already passed.");
82+
Sentry.getCurrentScopes()
83+
.getOptions()
84+
.getLogger()
85+
.log(
86+
SentryLevel.WARNING,
87+
"Cannot extend app start: the app start window has already passed.");
9188
return;
9289
}
9390
final @Nullable ExtendAppStartListener listener = extendAppStartListener;

0 commit comments

Comments
 (0)