Skip to content
Closed
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
8 changes: 4 additions & 4 deletions sentry/api/sentry.api
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ public final class io/sentry/CombinedScopeView : io/sentry/IScope {
public fun removeContexts (Ljava/lang/String;)V
public fun removeExtra (Ljava/lang/String;)V
public fun removeTag (Ljava/lang/String;)V
public fun replaceOptions (Lio/sentry/SentryOptions;)V
public fun replaceOptions (Lio/sentry/SentryOptions;)Z
public fun setContexts (Ljava/lang/String;Ljava/lang/Boolean;)V
public fun setContexts (Ljava/lang/String;Ljava/lang/Character;)V
public fun setContexts (Ljava/lang/String;Ljava/lang/Number;)V
Expand Down Expand Up @@ -769,7 +769,7 @@ public abstract interface class io/sentry/IScope {
public abstract fun removeContexts (Ljava/lang/String;)V
public abstract fun removeExtra (Ljava/lang/String;)V
public abstract fun removeTag (Ljava/lang/String;)V
public abstract fun replaceOptions (Lio/sentry/SentryOptions;)V
public abstract fun replaceOptions (Lio/sentry/SentryOptions;)Z
public abstract fun setContexts (Ljava/lang/String;Ljava/lang/Boolean;)V
public abstract fun setContexts (Ljava/lang/String;Ljava/lang/Character;)V
public abstract fun setContexts (Ljava/lang/String;Ljava/lang/Number;)V
Expand Down Expand Up @@ -1446,7 +1446,7 @@ public final class io/sentry/NoOpScope : io/sentry/IScope {
public fun removeContexts (Ljava/lang/String;)V
public fun removeExtra (Ljava/lang/String;)V
public fun removeTag (Ljava/lang/String;)V
public fun replaceOptions (Lio/sentry/SentryOptions;)V
public fun replaceOptions (Lio/sentry/SentryOptions;)Z
public fun setContexts (Ljava/lang/String;Ljava/lang/Boolean;)V
public fun setContexts (Ljava/lang/String;Ljava/lang/Character;)V
public fun setContexts (Ljava/lang/String;Ljava/lang/Number;)V
Expand Down Expand Up @@ -1918,7 +1918,7 @@ public final class io/sentry/Scope : io/sentry/IScope {
public fun removeContexts (Ljava/lang/String;)V
public fun removeExtra (Ljava/lang/String;)V
public fun removeTag (Ljava/lang/String;)V
public fun replaceOptions (Lio/sentry/SentryOptions;)V
public fun replaceOptions (Lio/sentry/SentryOptions;)Z
public fun setContexts (Ljava/lang/String;Ljava/lang/Boolean;)V
public fun setContexts (Ljava/lang/String;Ljava/lang/Character;)V
public fun setContexts (Ljava/lang/String;Ljava/lang/Number;)V
Expand Down
4 changes: 2 additions & 2 deletions sentry/src/main/java/io/sentry/CombinedScopeView.java
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ public void setSpanContext(

@ApiStatus.Internal
@Override
public void replaceOptions(@NotNull SentryOptions options) {
globalScope.replaceOptions(options);
public boolean replaceOptions(@NotNull SentryOptions options) {
return globalScope.replaceOptions(options);
}
}
2 changes: 1 addition & 1 deletion sentry/src/main/java/io/sentry/IScope.java
Original file line number Diff line number Diff line change
Expand Up @@ -401,5 +401,5 @@ void setSpanContext(
final @NotNull String transactionName);

@ApiStatus.Internal
void replaceOptions(final @NotNull SentryOptions options);
boolean replaceOptions(final @NotNull SentryOptions options);
}
4 changes: 3 additions & 1 deletion sentry/src/main/java/io/sentry/NoOpScope.java
Original file line number Diff line number Diff line change
Expand Up @@ -282,5 +282,7 @@ public void setSpanContext(
@NotNull Throwable throwable, @NotNull ISpan span, @NotNull String transactionName) {}

@Override
public void replaceOptions(@NotNull SentryOptions options) {}
public boolean replaceOptions(@NotNull SentryOptions options) {
return false;
}
}
5 changes: 4 additions & 1 deletion sentry/src/main/java/io/sentry/Scope.java
Original file line number Diff line number Diff line change
Expand Up @@ -1042,7 +1042,8 @@ public void setSpanContext(

@ApiStatus.Internal
@Override
public void replaceOptions(final @NotNull SentryOptions options) {
public boolean replaceOptions(final @NotNull SentryOptions options) {
// TODO [POTEL] implement some override mechanism
if (!getClient().isEnabled()) {
this.options = options;
final Queue<Breadcrumb> oldBreadcrumbs = breadcrumbs;
Expand All @@ -1054,7 +1055,9 @@ public void replaceOptions(final @NotNull SentryOptions options) {
*/
addBreadcrumb(breadcrumb);
}
return true;
}
return false;
}

/** The IWithTransaction callback */
Expand Down
60 changes: 35 additions & 25 deletions sentry/src/main/java/io/sentry/Sentry.java
Original file line number Diff line number Diff line change
Expand Up @@ -272,43 +272,51 @@ private static synchronized void init(
"Sentry has been already initialized. Previous configuration will be overwritten.");
}

if (!initConfigurations(options)) {
if (!preInitConfigurations(options)) {
return;
}

options.getLogger().log(SentryLevel.INFO, "GlobalHubMode: '%s'", String.valueOf(globalHubMode));
Sentry.globalHubMode = globalHubMode;
globalScope.replaceOptions(options);
final boolean didReplaceOptions = globalScope.replaceOptions(options);

// since replaceOptions can noop, we retrieve the options to use from global scope
final @NotNull SentryOptions optionsToUse = globalScope.getOptions();

final IScopes scopes = getCurrentScopes();
final IScope rootScope = new Scope(options);
final IScope rootIsolationScope = new Scope(options);
final IScope rootScope = new Scope(optionsToUse);
final IScope rootIsolationScope = new Scope(optionsToUse);
rootScopes = new Scopes(rootScope, rootIsolationScope, globalScope, "Sentry.init");

getScopesStorage().set(rootScopes);

scopes.close(true);
globalScope.bindClient(new SentryClient(rootScopes.getOptions()));
if (didReplaceOptions) {
scopes.close(true);

// If the executorService passed in the init is the same that was previously closed, we have to
// set a new one
if (options.getExecutorService().isClosed()) {
options.setExecutorService(new SentryExecutorService());
}
initConfigurations(optionsToUse);

// when integrations are registered on Scopes ctor and async integrations are fired,
// it might and actually happened that integrations called captureSomething
// and Scopes was still NoOp.
// Registering integrations here make sure that Scopes is already created.
for (final Integration integration : options.getIntegrations()) {
integration.register(ScopesAdapter.getInstance(), options);
}
globalScope.bindClient(new SentryClient(optionsToUse));

notifyOptionsObservers(options);
// If the executorService passed in the init is the same that was previously closed, we have
// to
// set a new one
if (options.getExecutorService().isClosed()) {
options.setExecutorService(new SentryExecutorService());
}
// when integrations are registered on Scopes ctor and async integrations are fired,
// it might and actually happened that integrations called captureSomething
// and Scopes was still NoOp.
// Registering integrations here make sure that Scopes is already created.
for (final Integration integration : options.getIntegrations()) {
integration.register(ScopesAdapter.getInstance(), options);
}

notifyOptionsObservers(options);

finalizePreviousSession(options, ScopesAdapter.getInstance());
finalizePreviousSession(options, ScopesAdapter.getInstance());

handleAppStartProfilingConfig(options, options.getExecutorService());
handleAppStartProfilingConfig(options, options.getExecutorService());
}
}

@SuppressWarnings("FutureReturnValueIgnored")
Expand Down Expand Up @@ -412,8 +420,7 @@ private static void notifyOptionsObservers(final @NotNull SentryOptions options)
}
}

@SuppressWarnings("FutureReturnValueIgnored")
private static boolean initConfigurations(final @NotNull SentryOptions options) {
private static boolean preInitConfigurations(final @NotNull SentryOptions options) {
if (options.isEnableExternalConfiguration()) {
options.merge(ExternalOptions.from(PropertiesProviderFactory.create(), options.getLogger()));
}
Expand All @@ -431,6 +438,11 @@ private static boolean initConfigurations(final @NotNull SentryOptions options)
@SuppressWarnings("unused")
final Dsn parsedDsn = new Dsn(dsn);

return true;
}

@SuppressWarnings("FutureReturnValueIgnored")
private static void initConfigurations(final @NotNull SentryOptions options) {
ILogger logger = options.getLogger();

if (options.isDebug() && logger instanceof NoOpLogger) {
Expand Down Expand Up @@ -527,8 +539,6 @@ private static boolean initConfigurations(final @NotNull SentryOptions options)
options.setBackpressureMonitor(new BackpressureMonitor(options, ScopesAdapter.getInstance()));
options.getBackpressureMonitor().start();
}

return true;
}

/** Close the SDK */
Expand Down