diff --git a/sentry/api/sentry.api b/sentry/api/sentry.api index aca363c3ca..8ba2f393d8 100644 --- a/sentry/api/sentry.api +++ b/sentry/api/sentry.api @@ -580,59 +580,6 @@ public final class io/sentry/HubScopesWrapper : io/sentry/IHub { public fun withScope (Lio/sentry/ScopeCallback;)V } -public final class io/sentry/HubScopesWrapper : io/sentry/IHub { - public fun (Lio/sentry/IScopes;)V - public fun addBreadcrumb (Lio/sentry/Breadcrumb;)V - public fun addBreadcrumb (Lio/sentry/Breadcrumb;Lio/sentry/Hint;)V - public fun bindClient (Lio/sentry/ISentryClient;)V - public fun captureCheckIn (Lio/sentry/CheckIn;)Lio/sentry/protocol/SentryId; - public fun captureEnvelope (Lio/sentry/SentryEnvelope;Lio/sentry/Hint;)Lio/sentry/protocol/SentryId; - public fun captureEvent (Lio/sentry/SentryEvent;Lio/sentry/Hint;)Lio/sentry/protocol/SentryId; - public fun captureEvent (Lio/sentry/SentryEvent;Lio/sentry/Hint;Lio/sentry/ScopeCallback;)Lio/sentry/protocol/SentryId; - public fun captureException (Ljava/lang/Throwable;Lio/sentry/Hint;)Lio/sentry/protocol/SentryId; - public fun captureException (Ljava/lang/Throwable;Lio/sentry/Hint;Lio/sentry/ScopeCallback;)Lio/sentry/protocol/SentryId; - public fun captureMessage (Ljava/lang/String;Lio/sentry/SentryLevel;)Lio/sentry/protocol/SentryId; - public fun captureMessage (Ljava/lang/String;Lio/sentry/SentryLevel;Lio/sentry/ScopeCallback;)Lio/sentry/protocol/SentryId; - public fun captureTransaction (Lio/sentry/protocol/SentryTransaction;Lio/sentry/TraceContext;Lio/sentry/Hint;Lio/sentry/ProfilingTraceData;)Lio/sentry/protocol/SentryId; - public fun captureUserFeedback (Lio/sentry/UserFeedback;)V - public fun clearBreadcrumbs ()V - public fun clone ()Lio/sentry/IHub; - public synthetic fun clone ()Ljava/lang/Object; - public fun close ()V - public fun close (Z)V - public fun configureScope (Lio/sentry/ScopeCallback;)V - public fun continueTrace (Ljava/lang/String;Ljava/util/List;)Lio/sentry/TransactionContext; - public fun endSession ()V - public fun flush (J)V - public fun getBaggage ()Lio/sentry/BaggageHeader; - public fun getLastEventId ()Lio/sentry/protocol/SentryId; - public fun getOptions ()Lio/sentry/SentryOptions; - public fun getRateLimiter ()Lio/sentry/transport/RateLimiter; - public fun getSpan ()Lio/sentry/ISpan; - public fun getTraceparent ()Lio/sentry/SentryTraceHeader; - public fun getTransaction ()Lio/sentry/ITransaction; - public fun isCrashedLastRun ()Ljava/lang/Boolean; - public fun isEnabled ()Z - public fun isHealthy ()Z - public fun metrics ()Lio/sentry/metrics/MetricsApi; - public fun popScope ()V - public fun pushScope ()V - public fun removeExtra (Ljava/lang/String;)V - public fun removeTag (Ljava/lang/String;)V - public fun reportFullyDisplayed ()V - public fun setExtra (Ljava/lang/String;Ljava/lang/String;)V - public fun setFingerprint (Ljava/util/List;)V - public fun setLevel (Lio/sentry/SentryLevel;)V - public fun setSpanContext (Ljava/lang/Throwable;Lio/sentry/ISpan;Ljava/lang/String;)V - public fun setTag (Ljava/lang/String;Ljava/lang/String;)V - public fun setTransaction (Ljava/lang/String;)V - public fun setUser (Lio/sentry/protocol/User;)V - public fun startSession ()V - public fun startTransaction (Lio/sentry/TransactionContext;Lio/sentry/TransactionOptions;)Lio/sentry/ITransaction; - public fun traceHeaders ()Lio/sentry/SentryTraceHeader; - public fun withScope (Lio/sentry/ScopeCallback;)V -} - public abstract interface class io/sentry/IConnectionStatusProvider { public abstract fun addConnectionStatusObserver (Lio/sentry/IConnectionStatusProvider$IConnectionStatusObserver;)Z public abstract fun getConnectionStatus ()Lio/sentry/IConnectionStatusProvider$ConnectionStatus; diff --git a/sentry/src/main/java/io/sentry/Hub.java b/sentry/src/main/java/io/sentry/Hub.java index d56305be5d..dd468d1eca 100644 --- a/sentry/src/main/java/io/sentry/Hub.java +++ b/sentry/src/main/java/io/sentry/Hub.java @@ -539,6 +539,11 @@ public void removeExtra(final @NotNull String key) { return NoOpScopesStorage.NoOpScopesLifecycleToken.getInstance(); } + @Override + public @NotNull ISentryLifecycleToken pushIsolationScope() { + return NoOpScopesStorage.NoOpScopesLifecycleToken.getInstance(); + } + @Override public @NotNull SentryOptions getOptions() { return this.stack.peek().getOptions(); @@ -652,6 +657,31 @@ public void flush(long timeoutMillis) { return new Hub(this.options, new Stack(this.stack)); } + @Override + public @NotNull IScopes forkedScopes(@NotNull String creator) { + return Sentry.forkedScopes(creator); + } + + @Override + public @NotNull IScopes forkedCurrentScope(@NotNull String creator) { + return Sentry.forkedCurrentScope(creator); + } + + @Override + public @NotNull ISentryLifecycleToken makeCurrent() { + return NoOpScopesStorage.NoOpScopesLifecycleToken.getInstance(); + } + + @Override + public @NotNull IScope getScope() { + return Sentry.getCurrentScopes().getScope(); + } + + @Override + public @NotNull IScope getIsolationScope() { + return Sentry.getCurrentScopes().getIsolationScope(); + } + @ApiStatus.Internal @Override public @NotNull SentryId captureTransaction( diff --git a/sentry/src/main/java/io/sentry/HubAdapter.java b/sentry/src/main/java/io/sentry/HubAdapter.java index f7970200ce..d813a11391 100644 --- a/sentry/src/main/java/io/sentry/HubAdapter.java +++ b/sentry/src/main/java/io/sentry/HubAdapter.java @@ -158,6 +158,11 @@ public void removeExtra(@NotNull String key) { return Sentry.pushScope(); } + @Override + public @NotNull ISentryLifecycleToken pushIsolationScope() { + return Sentry.pushIsolationScope(); + } + @Override public void popScope() { Sentry.popScope(); @@ -193,6 +198,32 @@ public void flush(long timeoutMillis) { return Sentry.getCurrentScopes().clone(); } + @Override + public @NotNull IScopes forkedScopes(@NotNull String creator) { + return Sentry.forkedScopes(creator); + } + + @Override + public @NotNull IScopes forkedCurrentScope(@NotNull String creator) { + return Sentry.forkedCurrentScope(creator); + } + + @Override + public @NotNull ISentryLifecycleToken makeCurrent() { + // TODO this wouldn't do anything since it replaced the current with the same Scopes + return NoOpScopesStorage.NoOpScopesLifecycleToken.getInstance(); + } + + @Override + public @NotNull IScope getScope() { + return Sentry.getCurrentScopes().getScope(); + } + + @Override + public @NotNull IScope getIsolationScope() { + return Sentry.getCurrentScopes().getIsolationScope(); + } + @Override public @NotNull SentryId captureTransaction( @NotNull SentryTransaction transaction, diff --git a/sentry/src/main/java/io/sentry/HubScopesWrapper.java b/sentry/src/main/java/io/sentry/HubScopesWrapper.java index 90c485d7f4..c3b2b19d80 100644 --- a/sentry/src/main/java/io/sentry/HubScopesWrapper.java +++ b/sentry/src/main/java/io/sentry/HubScopesWrapper.java @@ -153,6 +153,11 @@ public void removeExtra(@NotNull String key) { return scopes.pushScope(); } + @Override + public @NotNull ISentryLifecycleToken pushIsolationScope() { + return scopes.pushIsolationScope(); + } + @Override public void popScope() { scopes.popScope(); @@ -188,6 +193,31 @@ public void flush(long timeoutMillis) { return scopes.clone(); } + @Override + public @NotNull IScopes forkedScopes(@NotNull String creator) { + return scopes.forkedScopes(creator); + } + + @Override + public @NotNull IScopes forkedCurrentScope(@NotNull String creator) { + return scopes.forkedCurrentScope(creator); + } + + @Override + public @NotNull ISentryLifecycleToken makeCurrent() { + return scopes.makeCurrent(); + } + + @Override + public @NotNull IScope getScope() { + return scopes.getScope(); + } + + @Override + public @NotNull IScope getIsolationScope() { + return scopes.getIsolationScope(); + } + @ApiStatus.Internal @Override public @NotNull SentryId captureTransaction( diff --git a/sentry/src/main/java/io/sentry/IScopes.java b/sentry/src/main/java/io/sentry/IScopes.java index 29edb6627d..1ad2d62887 100644 --- a/sentry/src/main/java/io/sentry/IScopes.java +++ b/sentry/src/main/java/io/sentry/IScopes.java @@ -309,6 +309,9 @@ default void addBreadcrumb(@NotNull String message, @NotNull String category) { @NotNull ISentryLifecycleToken pushScope(); + @NotNull + ISentryLifecycleToken pushIsolationScope(); + /** Removes the first scope */ void popScope(); @@ -354,12 +357,54 @@ default void addBreadcrumb(@NotNull String message, @NotNull String category) { /** * Clones the Hub * + * @deprecated please use {@link IScopes#forkedScopes(String)} or {@link + * IScopes#forkedCurrentScope(String)} instead. * @return the cloned Hub */ @NotNull @Deprecated IHub clone(); + /** + * Creates a fork of both current and isolation scope. + * + * @param creator debug information to see why scopes where forked + * @return forked Scopes + */ + @NotNull + IScopes forkedScopes(final @NotNull String creator); + + /** + * Creates a fork of current scope without forking isolation scope. + * + * @param creator debug information to see why scopes where forked + * @return forked Scopes + */ + @NotNull + IScopes forkedCurrentScope(final @NotNull String creator); + + /** + * Stores this Scopes in store, making it the current one that is used by static API. + * + * @return a token you should call .close() on when you're done. + */ + @NotNull + ISentryLifecycleToken makeCurrent(); + + /** + * Returns the current scope of this Scopes. + * + * @return scope + */ + public @NotNull IScope getScope(); + + /** + * Returns the isolation scope of this Scopes. + * + * @return isolation scope + */ + public @NotNull IScope getIsolationScope(); + /** * Captures the transaction and enqueues it for sending to Sentry server. * diff --git a/sentry/src/main/java/io/sentry/NoOpHub.java b/sentry/src/main/java/io/sentry/NoOpHub.java index 1d5134d865..890c41d43e 100644 --- a/sentry/src/main/java/io/sentry/NoOpHub.java +++ b/sentry/src/main/java/io/sentry/NoOpHub.java @@ -128,6 +128,11 @@ public void removeExtra(@NotNull String key) {} return NoOpScopesStorage.NoOpScopesLifecycleToken.getInstance(); } + @Override + public @NotNull ISentryLifecycleToken pushIsolationScope() { + return NoOpScopesStorage.NoOpScopesLifecycleToken.getInstance(); + } + @Override public void popScope() {} @@ -155,6 +160,31 @@ public void flush(long timeoutMillis) {} return instance; } + @Override + public @NotNull IScopes forkedScopes(@NotNull String creator) { + return NoOpScopes.getInstance(); + } + + @Override + public @NotNull IScopes forkedCurrentScope(@NotNull String creator) { + return NoOpScopes.getInstance(); + } + + @Override + public @NotNull ISentryLifecycleToken makeCurrent() { + return NoOpScopesStorage.NoOpScopesLifecycleToken.getInstance(); + } + + @Override + public @NotNull IScope getScope() { + return NoOpScope.getInstance(); + } + + @Override + public @NotNull IScope getIsolationScope() { + return NoOpScope.getInstance(); + } + @Override public @NotNull SentryId captureTransaction( final @NotNull SentryTransaction transaction, diff --git a/sentry/src/main/java/io/sentry/NoOpScopes.java b/sentry/src/main/java/io/sentry/NoOpScopes.java index edf7ce1ecb..aa2b0fd2f3 100644 --- a/sentry/src/main/java/io/sentry/NoOpScopes.java +++ b/sentry/src/main/java/io/sentry/NoOpScopes.java @@ -126,6 +126,11 @@ public void removeExtra(@NotNull String key) {} return NoOpScopesStorage.NoOpScopesLifecycleToken.getInstance(); } + @Override + public @NotNull ISentryLifecycleToken pushIsolationScope() { + return NoOpScopesStorage.NoOpScopesLifecycleToken.getInstance(); + } + @Override public void popScope() {} @@ -154,6 +159,31 @@ public void flush(long timeoutMillis) {} return NoOpHub.getInstance(); } + @Override + public @NotNull IScopes forkedScopes(@NotNull String creator) { + return NoOpScopes.getInstance(); + } + + @Override + public @NotNull IScopes forkedCurrentScope(@NotNull String creator) { + return NoOpScopes.getInstance(); + } + + @Override + public @NotNull ISentryLifecycleToken makeCurrent() { + return NoOpScopesStorage.NoOpScopesLifecycleToken.getInstance(); + } + + @Override + public @NotNull IScope getScope() { + return NoOpScope.getInstance(); + } + + @Override + public @NotNull IScope getIsolationScope() { + return NoOpScope.getInstance(); + } + @Override public @NotNull SentryId captureTransaction( final @NotNull SentryTransaction transaction, diff --git a/sentry/src/main/java/io/sentry/Scopes.java b/sentry/src/main/java/io/sentry/Scopes.java index 5e3de8a855..f844119be3 100644 --- a/sentry/src/main/java/io/sentry/Scopes.java +++ b/sentry/src/main/java/io/sentry/Scopes.java @@ -72,12 +72,12 @@ private Scopes( return creator; } - // TODO add to IScopes interface + @Override public @NotNull IScope getScope() { return scope; } - // TODO add to IScopes interface + @Override public @NotNull IScope getIsolationScope() { return isolationScope; } @@ -105,25 +105,16 @@ public boolean isAncestorOf(final @Nullable Scopes otherScopes) { return false; } - // TODO add to IScopes interface - public @NotNull Scopes forkedScopes(final @NotNull String creator) { + @Override + public @NotNull IScopes forkedScopes(final @NotNull String creator) { return new Scopes(scope.clone(), isolationScope.clone(), this, options, creator); } - // TODO add to IScopes interface - public @NotNull Scopes forkedCurrentScope(final @NotNull String creator) { - IScope clone = scope.clone(); - // TODO should use isolation scope - // return new Scopes(clone, isolationScope, this, options, creator); - return new Scopes(clone, clone, this, options, creator); + @Override + public @NotNull IScopes forkedCurrentScope(final @NotNull String creator) { + return new Scopes(scope.clone(), isolationScope, this, options, creator); } - // // TODO in Sentry.init? - // public static Scopes forkedRoots(final @NotNull SentryOptions options, final @NotNull String - // creator) { - // return new Scopes(ROOT_SCOPE.clone(), ROOT_ISOLATION_SCOPE.clone(), options, creator); - // } - // TODO always read from root scope? @Override public boolean isEnabled() { @@ -602,12 +593,28 @@ public ISentryLifecycleToken pushScope() { .log(SentryLevel.WARNING, "Instance is disabled and this 'pushScope' call is a no-op."); return NoOpScopesStorage.NoOpScopesLifecycleToken.getInstance(); } else { - Scopes scopes = this.forkedCurrentScope("pushScope"); + final @NotNull IScopes scopes = this.forkedCurrentScope("pushScope"); return scopes.makeCurrent(); } } - public ISentryLifecycleToken makeCurrent() { + @Override + public ISentryLifecycleToken pushIsolationScope() { + if (!isEnabled()) { + options + .getLogger() + .log( + SentryLevel.WARNING, + "Instance is disabled and this 'pushIsolationScope' call is a no-op."); + return NoOpScopesStorage.NoOpScopesLifecycleToken.getInstance(); + } else { + final @NotNull IScopes scopes = this.forkedScopes("pushIsolationScope"); + return scopes.makeCurrent(); + } + } + + @Override + public @NotNull ISentryLifecycleToken makeCurrent() { return Sentry.setCurrentScopes(this); } @@ -638,7 +645,7 @@ public void withScope(final @NotNull ScopeCallback callback) { } } else { - Scopes forkedScopes = forkedCurrentScope("withScope"); + final @NotNull IScopes forkedScopes = forkedCurrentScope("withScope"); // TODO should forkedScopes be made current inside callback? // TODO forkedScopes.makeCurrent()? try { diff --git a/sentry/src/main/java/io/sentry/ScopesAdapter.java b/sentry/src/main/java/io/sentry/ScopesAdapter.java index 3ffdc01186..fe79a42731 100644 --- a/sentry/src/main/java/io/sentry/ScopesAdapter.java +++ b/sentry/src/main/java/io/sentry/ScopesAdapter.java @@ -154,6 +154,11 @@ public void removeExtra(@NotNull String key) { return Sentry.pushScope(); } + @Override + public @NotNull ISentryLifecycleToken pushIsolationScope() { + return Sentry.pushIsolationScope(); + } + @Override public void popScope() { Sentry.popScope(); @@ -190,6 +195,32 @@ public void flush(long timeoutMillis) { return Sentry.getCurrentScopes().clone(); } + @Override + public @NotNull IScopes forkedScopes(@NotNull String creator) { + return Sentry.forkedScopes(creator); + } + + @Override + public @NotNull IScopes forkedCurrentScope(@NotNull String creator) { + return Sentry.forkedCurrentScope(creator); + } + + @Override + public @NotNull ISentryLifecycleToken makeCurrent() { + // TODO this wouldn't do anything since it replaced the current with the same Scopes + return NoOpScopesStorage.NoOpScopesLifecycleToken.getInstance(); + } + + @Override + public @NotNull IScope getScope() { + return Sentry.getCurrentScopes().getScope(); + } + + @Override + public @NotNull IScope getIsolationScope() { + return Sentry.getCurrentScopes().getIsolationScope(); + } + @ApiStatus.Internal @Override public @NotNull SentryId captureTransaction( diff --git a/sentry/src/main/java/io/sentry/Sentry.java b/sentry/src/main/java/io/sentry/Sentry.java index d9ebaa78be..aac1b9d66d 100644 --- a/sentry/src/main/java/io/sentry/Sentry.java +++ b/sentry/src/main/java/io/sentry/Sentry.java @@ -113,6 +113,14 @@ private Sentry() {} return mainScopes.clone(); } + public static @NotNull IScopes forkedScopes(final @NotNull String creator) { + return getCurrentScopes().forkedScopes(creator); + } + + public static @NotNull IScopes forkedCurrentScope(final @NotNull String creator) { + return getCurrentScopes().forkedCurrentScope(creator); + } + @ApiStatus.Internal // exposed for the coroutines integration in SentryContext @Deprecated @SuppressWarnings({"deprecation", "InlineMeSuggester"}) @@ -822,11 +830,19 @@ public static void removeExtra(final @NotNull String key) { return NoOpScopesStorage.NoOpScopesLifecycleToken.getInstance(); } + /** Pushes a new isolation and current scope while inheriting the current scope's data. */ + public static @NotNull ISentryLifecycleToken pushIsolationScope() { + // pushScope is no-op in global hub mode + if (!globalHubMode) { + return getCurrentScopes().pushIsolationScope(); + } + return NoOpScopesStorage.NoOpScopesLifecycleToken.getInstance(); + } + /** Removes the first scope */ public static void popScope() { // popScope is no-op in global hub mode if (!globalHubMode) { - // TODO this might have to behave differently from Scopes.popScope getCurrentScopes().popScope(); } } @@ -837,7 +853,6 @@ public static void popScope() { * @param callback the callback */ public static void withScope(final @NotNull ScopeCallback callback) { - // TODO this might have to behave differently from Scopes.withScope getCurrentScopes().withScope(callback); }