Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hubs/Scopes Merge 14 - Add Scopes to replace Hub #3311

Merged
merged 18 commits into from
Apr 19, 2024
Merged
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
76 changes: 76 additions & 0 deletions sentry/api/sentry.api
Original file line number Diff line number Diff line change
Expand Up @@ -661,10 +661,12 @@ public abstract interface class io/sentry/IScope {
public abstract fun endSession ()Lio/sentry/Session;
public abstract fun getAttachments ()Ljava/util/List;
public abstract fun getBreadcrumbs ()Ljava/util/Queue;
public abstract fun getClient ()Lio/sentry/ISentryClient;
Copy link
Member Author

Choose a reason for hiding this comment

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

Client now lives on IScope and we'll set the default one on global scope in the future (follow up PR).

Copy link
Member Author

Choose a reason for hiding this comment

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

Client is now bound to global scope, as of #3344 but the code region is changed in later PRs a couple times.

Copy link
Member

@markushi markushi Apr 17, 2024

Choose a reason for hiding this comment

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

Sounds good! For metrics it would be important to have only one shared SentryClient instance by default, as metrics aggregation/sending is bound to that right now. If that's not the case anymore just let me know, I can take a look.

Copy link
Member Author

Choose a reason for hiding this comment

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

Should still be true. The SentryClient is set on global scope on Sentry.init. Before that there's a NoOpSentryClient on global scope. By default there should also only ever be NoOpSentryClient on isolation and current scope. A user can however bind any client on any of the scopes.

public abstract fun getContexts ()Lio/sentry/protocol/Contexts;
public abstract fun getEventProcessors ()Ljava/util/List;
public abstract fun getExtras ()Ljava/util/Map;
public abstract fun getFingerprint ()Ljava/util/List;
public abstract fun getLastEventId ()Lio/sentry/protocol/SentryId;
Copy link
Member Author

Choose a reason for hiding this comment

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

I was thinking that we could track last event ID per scope. By default it should probably just return the value from global scope in the future.

Copy link
Member Author

Choose a reason for hiding this comment

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

Changed in #3346

public abstract fun getLevel ()Lio/sentry/SentryLevel;
public abstract fun getOptions ()Lio/sentry/SentryOptions;
public abstract fun getPropagationContext ()Lio/sentry/PropagationContext;
Expand All @@ -679,6 +681,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 setClient (Lio/sentry/ISentryClient;)V
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 All @@ -688,6 +691,7 @@ public abstract interface class io/sentry/IScope {
public abstract fun setContexts (Ljava/lang/String;[Ljava/lang/Object;)V
public abstract fun setExtra (Ljava/lang/String;Ljava/lang/String;)V
public abstract fun setFingerprint (Ljava/util/List;)V
public abstract fun setLastEventId (Lio/sentry/protocol/SentryId;)V
public abstract fun setLevel (Lio/sentry/SentryLevel;)V
public abstract fun setPropagationContext (Lio/sentry/PropagationContext;)V
public abstract fun setRequest (Lio/sentry/protocol/Request;)V
Expand Down Expand Up @@ -1286,11 +1290,13 @@ public final class io/sentry/NoOpScope : io/sentry/IScope {
public fun endSession ()Lio/sentry/Session;
public fun getAttachments ()Ljava/util/List;
public fun getBreadcrumbs ()Ljava/util/Queue;
public fun getClient ()Lio/sentry/ISentryClient;
public fun getContexts ()Lio/sentry/protocol/Contexts;
public fun getEventProcessors ()Ljava/util/List;
public fun getExtras ()Ljava/util/Map;
public fun getFingerprint ()Ljava/util/List;
public static fun getInstance ()Lio/sentry/NoOpScope;
public fun getLastEventId ()Lio/sentry/protocol/SentryId;
public fun getLevel ()Lio/sentry/SentryLevel;
public fun getOptions ()Lio/sentry/SentryOptions;
public fun getPropagationContext ()Lio/sentry/PropagationContext;
Expand All @@ -1305,6 +1311,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 setClient (Lio/sentry/ISentryClient;)V
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 All @@ -1314,6 +1321,7 @@ public final class io/sentry/NoOpScope : io/sentry/IScope {
public fun setContexts (Ljava/lang/String;[Ljava/lang/Object;)V
public fun setExtra (Ljava/lang/String;Ljava/lang/String;)V
public fun setFingerprint (Ljava/util/List;)V
public fun setLastEventId (Lio/sentry/protocol/SentryId;)V
public fun setLevel (Lio/sentry/SentryLevel;)V
public fun setPropagationContext (Lio/sentry/PropagationContext;)V
public fun setRequest (Lio/sentry/protocol/Request;)V
Expand Down Expand Up @@ -1708,10 +1716,12 @@ public final class io/sentry/Scope : io/sentry/IScope {
public fun endSession ()Lio/sentry/Session;
public fun getAttachments ()Ljava/util/List;
public fun getBreadcrumbs ()Ljava/util/Queue;
public fun getClient ()Lio/sentry/ISentryClient;
public fun getContexts ()Lio/sentry/protocol/Contexts;
public fun getEventProcessors ()Ljava/util/List;
public fun getExtras ()Ljava/util/Map;
public fun getFingerprint ()Ljava/util/List;
public fun getLastEventId ()Lio/sentry/protocol/SentryId;
public fun getLevel ()Lio/sentry/SentryLevel;
public fun getOptions ()Lio/sentry/SentryOptions;
public fun getPropagationContext ()Lio/sentry/PropagationContext;
Expand All @@ -1726,6 +1736,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 setClient (Lio/sentry/ISentryClient;)V
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 All @@ -1735,6 +1746,7 @@ public final class io/sentry/Scope : io/sentry/IScope {
public fun setContexts (Ljava/lang/String;[Ljava/lang/Object;)V
public fun setExtra (Ljava/lang/String;Ljava/lang/String;)V
public fun setFingerprint (Ljava/util/List;)V
public fun setLastEventId (Lio/sentry/protocol/SentryId;)V
public fun setLevel (Lio/sentry/SentryLevel;)V
public fun setPropagationContext (Lio/sentry/PropagationContext;)V
public fun setRequest (Lio/sentry/protocol/Request;)V
Expand Down Expand Up @@ -1780,6 +1792,70 @@ public abstract class io/sentry/ScopeObserverAdapter : io/sentry/IScopeObserver
public fun setUser (Lio/sentry/protocol/User;)V
}

public final class io/sentry/Scopes : io/sentry/IScopes, io/sentry/metrics/MetricsApi$IMetricsInterface {
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 forkedCurrentScope (Ljava/lang/String;)Lio/sentry/Scopes;
public fun forkedScopes (Ljava/lang/String;)Lio/sentry/Scopes;
public fun getBaggage ()Lio/sentry/BaggageHeader;
public fun getCreator ()Ljava/lang/String;
public fun getDefaultTagsForMetrics ()Ljava/util/Map;
public fun getGlobalScope ()Lio/sentry/IScope;
public fun getIsolationScope ()Lio/sentry/IScope;
public fun getLastEventId ()Lio/sentry/protocol/SentryId;
public fun getLocalMetricsAggregator ()Lio/sentry/metrics/LocalMetricsAggregator;
public fun getMetricsAggregator ()Lio/sentry/IMetricsAggregator;
public fun getOptions ()Lio/sentry/SentryOptions;
public fun getParent ()Lio/sentry/Scopes;
public fun getRateLimiter ()Lio/sentry/transport/RateLimiter;
public fun getScope ()Lio/sentry/IScope;
public fun getSpan ()Lio/sentry/ISpan;
public fun getTraceparent ()Lio/sentry/SentryTraceHeader;
public fun getTransaction ()Lio/sentry/ITransaction;
public fun isAncestorOf (Lio/sentry/Scopes;)Z
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 startSpanForMetric (Ljava/lang/String;Ljava/lang/String;)Lio/sentry/ISpan;
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 final class io/sentry/ScopesAdapter : io/sentry/IScopes {
public fun addBreadcrumb (Lio/sentry/Breadcrumb;)V
public fun addBreadcrumb (Lio/sentry/Breadcrumb;Lio/sentry/Hint;)V
Expand Down
11 changes: 11 additions & 0 deletions sentry/src/main/java/io/sentry/IScope.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import io.sentry.protocol.Contexts;
import io.sentry.protocol.Request;
import io.sentry.protocol.SentryId;
import io.sentry.protocol.User;
import java.util.Collection;
import java.util.List;
Expand Down Expand Up @@ -370,4 +371,14 @@ public interface IScope {
*/
@NotNull
IScope clone();

void setLastEventId(final @NotNull SentryId lastEventId);

@NotNull
SentryId getLastEventId();

void setClient(final @NotNull ISentryClient client);

@NotNull
ISentryClient getClient();
}
17 changes: 17 additions & 0 deletions sentry/src/main/java/io/sentry/NoOpScope.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import io.sentry.protocol.Contexts;
import io.sentry.protocol.Request;
import io.sentry.protocol.SentryId;
import io.sentry.protocol.User;
import java.util.ArrayDeque;
import java.util.ArrayList;
Expand Down Expand Up @@ -236,6 +237,9 @@ public void setPropagationContext(@NotNull PropagationContext propagationContext
return new PropagationContext();
}

@Override
public void setLastEventId(@NotNull SentryId lastEventId) {}

/**
* Clones the Scope
*
Expand All @@ -245,4 +249,17 @@ public void setPropagationContext(@NotNull PropagationContext propagationContext
public @NotNull IScope clone() {
return NoOpScope.getInstance();
}

@Override
public @NotNull SentryId getLastEventId() {
return SentryId.EMPTY_ID;
}

@Override
public void setClient(@NotNull ISentryClient client) {}

@Override
public @NotNull ISentryClient getClient() {
return NoOpSentryClient.getInstance();
}
}
28 changes: 28 additions & 0 deletions sentry/src/main/java/io/sentry/Scope.java
Copy link
Member

Choose a reason for hiding this comment

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

nit: a few final keywords are missing, e.g. in the setters.

Copy link
Member Author

Choose a reason for hiding this comment

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

Will address in a follow up PR.

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import io.sentry.protocol.App;
import io.sentry.protocol.Contexts;
import io.sentry.protocol.Request;
import io.sentry.protocol.SentryId;
import io.sentry.protocol.TransactionNameSource;
import io.sentry.protocol.User;
import io.sentry.util.CollectionUtils;
Expand All @@ -22,6 +23,8 @@
/** Scope data to be sent with the event */
public final class Scope implements IScope {

private volatile @NotNull SentryId lastEventId;

/** Scope's SentryLevel */
private @Nullable SentryLevel level;

Expand Down Expand Up @@ -80,6 +83,8 @@ public final class Scope implements IScope {

private @NotNull PropagationContext propagationContext;

private @NotNull ISentryClient client = NoOpSentryClient.getInstance();

/**
* Scope's ctor
*
Expand All @@ -89,6 +94,7 @@ public Scope(final @NotNull SentryOptions options) {
this.options = Objects.requireNonNull(options, "SentryOptions is required.");
this.breadcrumbs = createBreadcrumbsList(this.options.getMaxBreadcrumbs());
this.propagationContext = new PropagationContext();
this.lastEventId = SentryId.EMPTY_ID;
}

private Scope(final @NotNull Scope scope) {
Expand All @@ -97,6 +103,8 @@ private Scope(final @NotNull Scope scope) {
this.session = scope.session;
this.options = scope.options;
this.level = scope.level;
// TODO should we do this? didn't do it for Hub
this.lastEventId = scope.getLastEventId();

final User userRef = scope.user;
this.user = userRef != null ? new User(userRef) : null;
Expand Down Expand Up @@ -945,6 +953,26 @@ public void setPropagationContext(final @NotNull PropagationContext propagationC
return new Scope(this);
}

@Override
public void setLastEventId(@NotNull SentryId lastEventId) {
this.lastEventId = lastEventId;
}

@Override
public @NotNull SentryId getLastEventId() {
Copy link
Member

Choose a reason for hiding this comment

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

It's a bit weird but JS removed this feature altogether:

REMOVED - Use event processors or beforeSend instead

But to be honest I still think we need it though 😅

Copy link
Member Author

Choose a reason for hiding this comment

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

If we intend to remove it, we should deprecate it for a while and only remove this in a later major, not in 8.x.

return lastEventId;
}

@Override
public void setClient(@NotNull ISentryClient client) {
this.client = client;
}

@Override
public @NotNull ISentryClient getClient() {
return client;
}

/** The IWithTransaction callback */
@ApiStatus.Internal
public interface IWithTransaction {
Expand Down
Loading
Loading