Skip to content

Commit

Permalink
Introduce IScopes interface.
Browse files Browse the repository at this point in the history
  • Loading branch information
adinauer committed Apr 2, 2024
1 parent fde534e commit 27f2398
Show file tree
Hide file tree
Showing 10 changed files with 1,778 additions and 758 deletions.
333 changes: 250 additions & 83 deletions sentry/api/sentry.api

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions sentry/src/main/java/io/sentry/Hub.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

@Deprecated
public final class Hub implements IHub, MetricsApi.IMetricsInterface {

private volatile @NotNull SentryId lastEventId;
Expand Down
22 changes: 13 additions & 9 deletions sentry/src/main/java/io/sentry/HubAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/**
* @deprecated use {@link ScopesAdapter} instead
*/
@Deprecated
public final class HubAdapter implements IHub {

private static final HubAdapter INSTANCE = new HubAdapter();
Expand Down Expand Up @@ -50,7 +54,7 @@ public boolean isEnabled() {
@ApiStatus.Internal
@Override
public @NotNull SentryId captureEnvelope(@NotNull SentryEnvelope envelope, @Nullable Hint hint) {
return Sentry.getCurrentHub().captureEnvelope(envelope, hint);
return Sentry.getCurrentScopes().captureEnvelope(envelope, hint);
}

@Override
Expand Down Expand Up @@ -186,7 +190,7 @@ public void flush(long timeoutMillis) {

@Override
public @NotNull IHub clone() {
return Sentry.getCurrentHub().clone();
return Sentry.getCurrentScopes().clone();
}

@Override
Expand All @@ -195,7 +199,7 @@ public void flush(long timeoutMillis) {
@Nullable TraceContext traceContext,
@Nullable Hint hint,
@Nullable ProfilingTraceData profilingTraceData) {
return Sentry.getCurrentHub()
return Sentry.getCurrentScopes()
.captureTransaction(transaction, traceContext, hint, profilingTraceData);
}

Expand All @@ -217,23 +221,23 @@ public void setSpanContext(
final @NotNull Throwable throwable,
final @NotNull ISpan span,
final @NotNull String transactionName) {
Sentry.getCurrentHub().setSpanContext(throwable, span, transactionName);
Sentry.getCurrentScopes().setSpanContext(throwable, span, transactionName);
}

@Override
public @Nullable ISpan getSpan() {
return Sentry.getCurrentHub().getSpan();
return Sentry.getCurrentScopes().getSpan();
}

@Override
@ApiStatus.Internal
public @Nullable ITransaction getTransaction() {
return Sentry.getCurrentHub().getTransaction();
return Sentry.getCurrentScopes().getTransaction();
}

@Override
public @NotNull SentryOptions getOptions() {
return Sentry.getCurrentHub().getOptions();
return Sentry.getCurrentScopes().getOptions();
}

@Override
Expand Down Expand Up @@ -271,11 +275,11 @@ public void reportFullyDisplayed() {
@ApiStatus.Internal
@Override
public @Nullable RateLimiter getRateLimiter() {
return Sentry.getCurrentHub().getRateLimiter();
return Sentry.getCurrentScopes().getRateLimiter();
}

@Override
public @NotNull MetricsApi metrics() {
return Sentry.getCurrentHub().metrics();
return Sentry.getCurrentScopes().metrics();
}
}
279 changes: 279 additions & 0 deletions sentry/src/main/java/io/sentry/HubScopesWrapper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,279 @@
package io.sentry;

import io.sentry.metrics.MetricsApi;
import io.sentry.protocol.SentryId;
import io.sentry.protocol.SentryTransaction;
import io.sentry.protocol.User;
import io.sentry.transport.RateLimiter;
import java.util.List;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

@SuppressWarnings("deprecation")
@Deprecated
public final class HubScopesWrapper implements IHub {

private final IScopes scopes;

public HubScopesWrapper(final @NotNull IScopes scopes) {
this.scopes = scopes;
}

@Override
public boolean isEnabled() {
return scopes.isEnabled();
}

@Override
public @NotNull SentryId captureEvent(@NotNull SentryEvent event, @Nullable Hint hint) {
return scopes.captureEvent(event, hint);
}

@Override
public @NotNull SentryId captureEvent(
@NotNull SentryEvent event, @Nullable Hint hint, @NotNull ScopeCallback callback) {
return scopes.captureEvent(event, hint, callback);
}

@Override
public @NotNull SentryId captureMessage(@NotNull String message, @NotNull SentryLevel level) {
return scopes.captureMessage(message, level);
}

@Override
public @NotNull SentryId captureMessage(
@NotNull String message, @NotNull SentryLevel level, @NotNull ScopeCallback callback) {
return scopes.captureMessage(message, level, callback);
}

@Override
public @NotNull SentryId captureEnvelope(@NotNull SentryEnvelope envelope, @Nullable Hint hint) {
return scopes.captureEnvelope(envelope, hint);
}

@Override
public @NotNull SentryId captureException(@NotNull Throwable throwable, @Nullable Hint hint) {
return scopes.captureException(throwable, hint);
}

@Override
public @NotNull SentryId captureException(
@NotNull Throwable throwable, @Nullable Hint hint, @NotNull ScopeCallback callback) {
return scopes.captureException(throwable, hint, callback);
}

@Override
public void captureUserFeedback(@NotNull UserFeedback userFeedback) {
scopes.captureUserFeedback(userFeedback);
}

@Override
public void startSession() {
scopes.startSession();
}

@Override
public void endSession() {
scopes.endSession();
}

@Override
public void close() {
scopes.close();
}

@Override
public void close(boolean isRestarting) {
scopes.close(isRestarting);
}

@Override
public void addBreadcrumb(@NotNull Breadcrumb breadcrumb, @Nullable Hint hint) {
scopes.addBreadcrumb(breadcrumb, hint);
}

@Override
public void addBreadcrumb(@NotNull Breadcrumb breadcrumb) {
scopes.addBreadcrumb(breadcrumb);
}

@Override
public void setLevel(@Nullable SentryLevel level) {
scopes.setLevel(level);
}

@Override
public void setTransaction(@Nullable String transaction) {
scopes.setTransaction(transaction);
}

@Override
public void setUser(@Nullable User user) {
scopes.setUser(user);
}

@Override
public void setFingerprint(@NotNull List<String> fingerprint) {
scopes.setFingerprint(fingerprint);
}

@Override
public void clearBreadcrumbs() {
scopes.clearBreadcrumbs();
}

@Override
public void setTag(@NotNull String key, @NotNull String value) {
scopes.setTag(key, value);
}

@Override
public void removeTag(@NotNull String key) {
scopes.removeTag(key);
}

@Override
public void setExtra(@NotNull String key, @NotNull String value) {
scopes.setExtra(key, value);
}

@Override
public void removeExtra(@NotNull String key) {
scopes.removeExtra(key);
}

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

@Override
public void pushScope() {
scopes.pushScope();
}

@Override
public void popScope() {
scopes.popScope();
}

@Override
public void withScope(@NotNull ScopeCallback callback) {
scopes.withScope(callback);
}

@Override
public void configureScope(@NotNull ScopeCallback callback) {
scopes.configureScope(callback);
}

@Override
public void bindClient(@NotNull ISentryClient client) {
scopes.bindClient(client);
}

@Override
public boolean isHealthy() {
return scopes.isHealthy();
}

@Override
public void flush(long timeoutMillis) {
scopes.flush(timeoutMillis);
}

@Override
public @NotNull IHub clone() {
return scopes.clone();
}

@ApiStatus.Internal
@Override
public @NotNull SentryId captureTransaction(
@NotNull SentryTransaction transaction,
@Nullable TraceContext traceContext,
@Nullable Hint hint,
@Nullable ProfilingTraceData profilingTraceData) {
return scopes.captureTransaction(transaction, traceContext, hint, profilingTraceData);
}

@Override
public @NotNull ITransaction startTransaction(
@NotNull TransactionContext transactionContext,
@NotNull TransactionOptions transactionOptions) {
return scopes.startTransaction(transactionContext, transactionOptions);
}

@Override
public @Nullable SentryTraceHeader traceHeaders() {
return scopes.traceHeaders();
}

@ApiStatus.Internal
@Override
public void setSpanContext(
@NotNull Throwable throwable, @NotNull ISpan span, @NotNull String transactionName) {
scopes.setSpanContext(throwable, span, transactionName);
}

@Override
public @Nullable ISpan getSpan() {
return scopes.getSpan();
}

@ApiStatus.Internal
@Override
public @Nullable ITransaction getTransaction() {
return scopes.getTransaction();
}

@Override
public @NotNull SentryOptions getOptions() {
return scopes.getOptions();
}

@Override
public @Nullable Boolean isCrashedLastRun() {
return scopes.isCrashedLastRun();
}

@Override
public void reportFullyDisplayed() {
scopes.reportFullyDisplayed();
}

@Override
public @Nullable TransactionContext continueTrace(
@Nullable String sentryTrace, @Nullable List<String> baggageHeaders) {
return scopes.continueTrace(sentryTrace, baggageHeaders);
}

@Override
public @Nullable SentryTraceHeader getTraceparent() {
return scopes.getTraceparent();
}

@Override
public @Nullable BaggageHeader getBaggage() {
return scopes.getBaggage();
}

@ApiStatus.Experimental
@Override
public @NotNull SentryId captureCheckIn(@NotNull CheckIn checkIn) {
return scopes.captureCheckIn(checkIn);
}

@ApiStatus.Internal
@Override
public @Nullable RateLimiter getRateLimiter() {
return scopes.getRateLimiter();
}

@ApiStatus.Experimental
@Override
public @NotNull MetricsApi metrics() {
return scopes.metrics();
}
}
Loading

0 comments on commit 27f2398

Please sign in to comment.