Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -377,8 +377,8 @@ public void close(final boolean isTerminating) {
@SuppressWarnings("FutureReturnValueIgnored")
private void sendChunks(final @NotNull IScopes scopes, final @NotNull SentryOptions options) {
try {
options
.getExecutorService()
executorServiceSupplier
.evaluate()
.submit(() -> {
// SDK is closed, we don't send the chunks
if (isClosed.get()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import io.sentry.ISentryClient;
import io.sentry.SentryLevel;
import io.sentry.SentryOptions;
import io.sentry.internal.LegacyOptionsBridge;
import io.sentry.logger.LoggerBatchProcessor;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
Expand All @@ -29,8 +30,8 @@ public void onBackground() {
return;
}
try {
options
.getExecutorService()
// Created through the public batch processor factory, which only passes the options.
LegacyOptionsBridge.executorOf(options)
.submit(
new Runnable() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import io.sentry.ISentryClient;
import io.sentry.SentryLevel;
import io.sentry.SentryOptions;
import io.sentry.internal.LegacyOptionsBridge;
import io.sentry.metrics.MetricsBatchProcessor;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
Expand All @@ -29,8 +30,8 @@ public void onBackground() {
return;
}
try {
options
.getExecutorService()
// Created through the public batch processor factory, which only passes the options.
LegacyOptionsBridge.executorOf(options)
.submit(
new Runnable() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import io.sentry.DefaultVersionDetector;
import io.sentry.IContinuousProfiler;
import io.sentry.ILogger;
import io.sentry.ISentryExecutorService;
import io.sentry.ISentryLifecycleToken;
import io.sentry.ITransactionProfiler;
import io.sentry.NoOpCompositePerformanceCollector;
Expand Down Expand Up @@ -48,6 +49,7 @@
import io.sentry.cache.PersistingScopeObserver;
import io.sentry.compose.gestures.ComposeGestureTargetLocator;
import io.sentry.compose.viewhierarchy.ComposeViewHierarchyExporter;
import io.sentry.internal.LegacyOptionsBridge;
import io.sentry.internal.debugmeta.NoOpDebugMetaLoader;
import io.sentry.internal.gestures.GestureTargetLocator;
import io.sentry.internal.modules.NoOpModulesLoader;
Expand Down Expand Up @@ -155,6 +157,7 @@ static void initializeIntegrationsAndProcessors(
final boolean isReplayAvailable) {
initializeIntegrationsAndProcessors(
options,
LegacyOptionsBridge.executorOf(options),
context,
new BuildInfoProvider(new AndroidLogger()),
loadClass,
Expand All @@ -164,6 +167,7 @@ static void initializeIntegrationsAndProcessors(

static void initializeIntegrationsAndProcessors(
final @NotNull SentryAndroidOptions options,
final @NotNull ISentryExecutorService executorService,
final @NotNull Context context,
final @NotNull BuildInfoProvider buildInfoProvider,
final @NotNull io.sentry.util.LoadClass loadClass,
Expand All @@ -178,11 +182,16 @@ static void initializeIntegrationsAndProcessors(
if (options.getConnectionStatusProvider() instanceof NoOpConnectionStatusProvider) {
options.setConnectionStatusProvider(
new AndroidConnectionStatusProvider(
context, options, buildInfoProvider, options.getMonotonicTicker()));
context,
options,
buildInfoProvider,
options.getMonotonicTicker(),
null,
executorService));
}

if (options.getCacheDirPath() != null) {
options.addScopeObserver(new PersistingScopeObserver(options));
options.addScopeObserver(new PersistingScopeObserver(options, executorService));
options.addOptionsObserver(new PersistingOptionsObserver(options));
final PackageInfo packageInfo = ContextUtils.getPackageInfo(context, buildInfoProvider);
if (packageInfo != null && packageInfo.lastUpdateTime > 0) {
Expand Down Expand Up @@ -216,7 +225,8 @@ static void initializeIntegrationsAndProcessors(
options.setAppStartExtender(appStartMetrics.getAppStartExtension());

if (options.getModulesLoader() instanceof NoOpModulesLoader) {
options.setModulesLoader(new AssetsModulesLoader(context, options));
options.setModulesLoader(
new AssetsModulesLoader(context, options.getLogger(), executorService));
}
if (options.getDebugMetaLoader() instanceof NoOpDebugMetaLoader) {
options.setDebugMetaLoader(new AssetsDebugMetaLoader(context, options.getLogger()));
Expand Down Expand Up @@ -304,6 +314,7 @@ static void initializeIntegrationsAndProcessors(

setupProfiler(
options,
executorService,
context,
buildInfoProvider,
appStartTransactionProfiler,
Expand All @@ -315,6 +326,7 @@ static void initializeIntegrationsAndProcessors(
@SuppressLint("NewApi")
private static void setupProfiler(
final @NotNull SentryAndroidOptions options,
final @NotNull ISentryExecutorService executorService,
final @NotNull Context context,
final @NotNull BuildInfoProvider buildInfoProvider,
final @Nullable ITransactionProfiler appStartTransactionProfiler,
Expand Down Expand Up @@ -355,11 +367,15 @@ private static void setupProfiler(
options.setTransactionProfiler(
new AndroidTransactionProfiler(
context,
options,
buildInfoProvider,
Objects.requireNonNull(
options.getFrameMetricsCollector(),
"options.getFrameMetricsCollector is required")));
"options.getFrameMetricsCollector is required"),
options.getLogger(),
options.getProfilingTracesDirPath(),
options.isProfilingEnabled(),
options.getProfilingTracesHz(),
executorService));
}
} else {
options.setTransactionProfiler(NoOpTransactionProfiler.getInstance());
Expand All @@ -386,10 +402,8 @@ private static void setupProfiler(
new PerfettoContinuousProfiler(
options.getLogger(),
frameMetricsCollector,
() -> options.getExecutorService(),
() ->
new PerfettoProfiler(
appContext, options.getLogger(), options.getExecutorService())));
() -> executorService,
() -> new PerfettoProfiler(appContext, options.getLogger(), executorService)));
// Report adoption of the Perfetto continuous profiling backend (API 35+).
addIntegrationToSdkVersion("PerfettoContinuousProfiling");
} else if (options.isEnableLegacyProfiling()) {
Expand All @@ -400,7 +414,7 @@ private static void setupProfiler(
options.getLogger(),
options.getProfilingTracesDirPath(),
options.getProfilingTracesHz(),
() -> options.getExecutorService()));
() -> executorService));
} else {
options
.getLogger()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import io.sentry.SentryOptions;
import io.sentry.android.core.internal.util.CpuInfoUtils;
import io.sentry.android.core.internal.util.SentryFrameMetricsCollector;
import io.sentry.internal.LegacyOptionsBridge;
import io.sentry.util.AutoClosableReentrantLock;
import io.sentry.util.LazyEvaluator;
import io.sentry.util.Objects;
Expand Down Expand Up @@ -66,7 +67,7 @@ public AndroidTransactionProfiler(
sentryAndroidOptions.getProfilingTracesDirPath(),
sentryAndroidOptions.isProfilingEnabled(),
sentryAndroidOptions.getProfilingTracesHz(),
() -> sentryAndroidOptions.getExecutorService());
() -> LegacyOptionsBridge.executorOf(sentryAndroidOptions));
}

public AndroidTransactionProfiler(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import io.sentry.android.core.performance.AppStartMetrics;
import io.sentry.android.core.performance.TimeSpan;
import io.sentry.cache.EnvelopeCache;
import io.sentry.internal.LegacyOptionsBridge;
import io.sentry.internal.SentryRuntime;
import io.sentry.protocol.App;
import io.sentry.protocol.Device;
Expand Down Expand Up @@ -433,8 +434,7 @@ private static void deleteCurrentSessionFile(
final @NotNull SentryOptions options, boolean isSync) {
if (!isSync) {
try {
options
.getExecutorService()
LegacyOptionsBridge.executorOf(options)
.submit(() -> {
deleteCurrentSessionFile(options);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.os.Trace;
import io.sentry.ILogger;
import io.sentry.IScopes;
import io.sentry.ISentryExecutorService;
import io.sentry.ISentryLifecycleToken;
import io.sentry.Integration;
import io.sentry.Sentry;
Expand All @@ -20,6 +21,7 @@
import io.sentry.android.core.performance.TimeSpan;
import io.sentry.android.fragment.FragmentLifecycleIntegration;
import io.sentry.android.timber.SentryTimberIntegration;
import io.sentry.internal.LegacyOptionsBridge;
import io.sentry.internal.SentryRuntime;
import io.sentry.time.Stopwatch;
import io.sentry.util.AutoClosableReentrantLock;
Expand Down Expand Up @@ -201,8 +203,14 @@ static void init(
appStartMetrics.setSdkInitStopwatch(sdkInitStopwatch);
}

// Created before the integrations and processors, which start using it right away.
final @NotNull ISentryExecutorService executorService =
LegacyOptionsBridge.executorOrNew(options);
runtime.executorService(executorService);

AndroidOptionsInitializer.initializeIntegrationsAndProcessors(
options,
executorService,
context,
buildInfoProvider,
loadClass,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package io.sentry.android.core.internal.modules;

import android.content.Context;
import io.sentry.ILogger;
import io.sentry.ISentryExecutorService;
import io.sentry.SentryLevel;
import io.sentry.SentryOptions;
import io.sentry.android.core.ContextUtils;
import io.sentry.internal.LegacyOptionsBridge;
import io.sentry.internal.modules.ModulesLoader;
import java.io.FileNotFoundException;
import java.io.IOException;
Expand All @@ -18,20 +21,25 @@ public final class AssetsModulesLoader extends ModulesLoader {

private final @NotNull Context context;

@SuppressWarnings("FutureReturnValueIgnored")
public AssetsModulesLoader(final @NotNull Context context, final @NotNull SentryOptions options) {
super(options.getLogger());
this(context, options.getLogger(), LegacyOptionsBridge.executorOf(options));
}

@SuppressWarnings("FutureReturnValueIgnored")
public AssetsModulesLoader(
final @NotNull Context context,
final @NotNull ILogger logger,
final @NotNull ISentryExecutorService executorService) {
super(logger);
this.context = ContextUtils.getApplicationContext(context);

// pre-load modules on a bg thread to avoid doing so on the main thread in case of a crash/error
try {
options
.getExecutorService()
.submit(() -> {
getOrLoadModules();
});
executorService.submit(() -> {
getOrLoadModules();
});
} catch (Throwable e) {
options.getLogger().log(SentryLevel.ERROR, "AssetsModulesLoader submit failed", e);
logger.log(SentryLevel.ERROR, "AssetsModulesLoader submit failed", e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@
import androidx.annotation.RequiresApi;
import io.sentry.IConnectionStatusProvider;
import io.sentry.ILogger;
import io.sentry.ISentryExecutorService;
import io.sentry.ISentryLifecycleToken;
import io.sentry.SentryLevel;
import io.sentry.SentryOptions;
import io.sentry.android.core.AppState;
import io.sentry.android.core.BuildInfoProvider;
import io.sentry.android.core.ContextUtils;
import io.sentry.internal.LegacyOptionsBridge;
import io.sentry.time.Deadline;
import io.sentry.time.MonotonicTicker;
import io.sentry.util.AutoClosableReentrantLock;
Expand Down Expand Up @@ -86,6 +88,7 @@ public final class AndroidConnectionStatusProvider

private final @NotNull Context context;
private final @NotNull SentryOptions options;
private final @Nullable ISentryExecutorService executorService;
private final @NotNull BuildInfoProvider buildInfoProvider;
private final @NotNull MonotonicTicker ticker;

Expand Down Expand Up @@ -179,18 +182,33 @@ public AndroidConnectionStatusProvider(
@NotNull SentryOptions options,
@NotNull BuildInfoProvider buildInfoProvider,
@NotNull MonotonicTicker ticker) {
this(context, options, buildInfoProvider, ticker, null);
this(context, options, buildInfoProvider, ticker, null, null);
}

@SuppressLint("InlinedApi")
public AndroidConnectionStatusProvider(
@NotNull Context context,
@NotNull SentryOptions options,
@NotNull BuildInfoProvider buildInfoProvider,
@NotNull MonotonicTicker ticker,
@Nullable Handler handler) {
this(context, options, buildInfoProvider, ticker, handler, null);
}

/**
* @param executorService runs the provider's background work; {@code null} reads it from the
* options on each use, as the deprecated constructors do
*/
@SuppressLint("InlinedApi")
public AndroidConnectionStatusProvider(
@NotNull Context context,
@NotNull SentryOptions options,
@NotNull BuildInfoProvider buildInfoProvider,
@NotNull MonotonicTicker ticker,
@Nullable Handler handler,
@Nullable ISentryExecutorService executorService) {
this.context = ContextUtils.getApplicationContext(context);
this.options = options;
this.executorService = executorService;
this.buildInfoProvider = buildInfoProvider;
this.ticker = ticker;
this.snapshot = new AtomicReference<>(ConnectionSnapshot.unknown(ticker));
Expand Down Expand Up @@ -1098,7 +1116,8 @@ ConnectionSnapshot withCapabilities(
@SuppressWarnings("FutureReturnValueIgnored")
private void submitSafe(@NotNull Runnable r) {
try {
options.getExecutorService().submit(r);
(executorService != null ? executorService : LegacyOptionsBridge.executorOf(options))
.submit(r);
} catch (Throwable e) {
options
.getLogger()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ class AndroidContinuousProfilerTest {

AndroidOptionsInitializer.initializeIntegrationsAndProcessors(
fixture.options,
fixture.options.executorService,
context,
buildInfoProvider,
loadClass,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ class AndroidOptionsInitializerTest {
sentryOptions.configureOptions()
AndroidOptionsInitializer.initializeIntegrationsAndProcessors(
sentryOptions,
sentryOptions.executorService,
if (useRealContext) context else mockContext,
BuildInfoProvider(AndroidLogger()),
loadClass,
activityFramesTracker,
false,
Expand Down Expand Up @@ -166,6 +168,7 @@ class AndroidOptionsInitializerTest {

AndroidOptionsInitializer.initializeIntegrationsAndProcessors(
sentryOptions,
sentryOptions.executorService,
context,
buildInfo,
loadClass,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ class AndroidProfilerTest {

AndroidOptionsInitializer.initializeIntegrationsAndProcessors(
fixture.options,
fixture.options.executorService,
context,
buildInfoProvider,
loadClass,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ class AndroidTransactionProfilerTest {

AndroidOptionsInitializer.initializeIntegrationsAndProcessors(
fixture.options,
fixture.options.executorService,
context,
buildInfoProvider,
loadClass,
Expand Down
Loading
Loading