Skip to content

Commit

Permalink
Replace IHub with IScopes in core
Browse files Browse the repository at this point in the history
  • Loading branch information
adinauer committed Apr 2, 2024
1 parent 27f2398 commit ce3c14f
Show file tree
Hide file tree
Showing 55 changed files with 1,092 additions and 793 deletions.
4 changes: 2 additions & 2 deletions sentry/src/main/java/io/sentry/Baggage.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ public final class Baggage {
@NotNull
public static Baggage fromHeader(final @Nullable String headerValue) {
return Baggage.fromHeader(
headerValue, false, HubAdapter.getInstance().getOptions().getLogger());
headerValue, false, ScopesAdapter.getInstance().getOptions().getLogger());
}

@NotNull
public static Baggage fromHeader(final @Nullable List<String> headerValues) {
return Baggage.fromHeader(
headerValues, false, HubAdapter.getInstance().getOptions().getLogger());
headerValues, false, ScopesAdapter.getInstance().getOptions().getLogger());
}

@ApiStatus.Internal
Expand Down
8 changes: 4 additions & 4 deletions sentry/src/main/java/io/sentry/DirectoryProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@
abstract class DirectoryProcessor {

private static final long ENVELOPE_PROCESSING_DELAY = 100L;
private final @NotNull IHub hub;
private final @NotNull IScopes scopes;
private final @NotNull ILogger logger;
private final long flushTimeoutMillis;
private final Queue<String> processedEnvelopes;

DirectoryProcessor(
final @NotNull IHub hub,
final @NotNull IScopes scopes,
final @NotNull ILogger logger,
final long flushTimeoutMillis,
final int maxQueueSize) {
this.hub = hub;
this.scopes = scopes;
this.logger = logger;
this.flushTimeoutMillis = flushTimeoutMillis;
this.processedEnvelopes =
Expand Down Expand Up @@ -86,7 +86,7 @@ public void processDirectory(final @NotNull File directory) {
}

// in case there's rate limiting active, skip processing
final @Nullable RateLimiter rateLimiter = hub.getRateLimiter();
final @Nullable RateLimiter rateLimiter = scopes.getRateLimiter();
if (rateLimiter != null && rateLimiter.isActiveForCategory(DataCategory.All)) {
logger.log(SentryLevel.INFO, "DirectoryProcessor, rate limiting active.");
return;
Expand Down
10 changes: 5 additions & 5 deletions sentry/src/main/java/io/sentry/EnvelopeSender.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@
@ApiStatus.Internal
public final class EnvelopeSender extends DirectoryProcessor implements IEnvelopeSender {

private final @NotNull IHub hub;
private final @NotNull IScopes scopes;
private final @NotNull ISerializer serializer;
private final @NotNull ILogger logger;

public EnvelopeSender(
final @NotNull IHub hub,
final @NotNull IScopes scopes,
final @NotNull ISerializer serializer,
final @NotNull ILogger logger,
final long flushTimeoutMillis,
final int maxQueueSize) {
super(hub, logger, flushTimeoutMillis, maxQueueSize);
this.hub = Objects.requireNonNull(hub, "Hub is required.");
super(scopes, logger, flushTimeoutMillis, maxQueueSize);
this.scopes = Objects.requireNonNull(scopes, "Hub is required.");
this.serializer = Objects.requireNonNull(serializer, "Serializer is required.");
this.logger = Objects.requireNonNull(logger, "Logger is required.");
}
Expand Down Expand Up @@ -60,7 +60,7 @@ protected void processFile(final @NotNull File file, final @NotNull Hint hint) {
logger.log(
SentryLevel.ERROR, "Failed to deserialize cached envelope %s", file.getAbsolutePath());
} else {
hub.captureEnvelope(envelope, hint);
scopes.captureEnvelope(envelope, hint);
}

HintUtils.runIfHasTypeLogIfNot(
Expand Down
4 changes: 2 additions & 2 deletions sentry/src/main/java/io/sentry/Integration.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ public interface Integration {
/**
* Registers an integration
*
* @param hub the Hub
* @param scopes the Scopes
* @param options the options
*/
void register(@NotNull IHub hub, @NotNull SentryOptions options);
void register(@NotNull IScopes scopes, @NotNull SentryOptions options);
}
2 changes: 1 addition & 1 deletion sentry/src/main/java/io/sentry/MonitorConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public final class MonitorConfig implements JsonUnknown, JsonSerializable {

public MonitorConfig(final @NotNull MonitorSchedule schedule) {
this.schedule = schedule;
final SentryOptions.Cron defaultCron = HubAdapter.getInstance().getOptions().getCron();
final SentryOptions.Cron defaultCron = ScopesAdapter.getInstance().getOptions().getCron();
if (defaultCron != null) {
this.checkinMargin = defaultCron.getDefaultCheckinMargin();
this.maxRuntime = defaultCron.getDefaultMaxRuntime();
Expand Down
14 changes: 7 additions & 7 deletions sentry/src/main/java/io/sentry/OutboxSender.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,20 @@ public final class OutboxSender extends DirectoryProcessor implements IEnvelopeS
@SuppressWarnings("CharsetObjectCanBeUsed")
private static final Charset UTF_8 = Charset.forName("UTF-8");

private final @NotNull IHub hub;
private final @NotNull IScopes scopes;
private final @NotNull IEnvelopeReader envelopeReader;
private final @NotNull ISerializer serializer;
private final @NotNull ILogger logger;

public OutboxSender(
final @NotNull IHub hub,
final @NotNull IScopes scopes,
final @NotNull IEnvelopeReader envelopeReader,
final @NotNull ISerializer serializer,
final @NotNull ILogger logger,
final long flushTimeoutMillis,
final int maxQueueSize) {
super(hub, logger, flushTimeoutMillis, maxQueueSize);
this.hub = Objects.requireNonNull(hub, "Hub is required.");
super(scopes, logger, flushTimeoutMillis, maxQueueSize);
this.scopes = Objects.requireNonNull(scopes, "Hub is required.");
this.envelopeReader = Objects.requireNonNull(envelopeReader, "Envelope reader is required.");
this.serializer = Objects.requireNonNull(serializer, "Serializer is required.");
this.logger = Objects.requireNonNull(logger, "Logger is required.");
Expand Down Expand Up @@ -144,7 +144,7 @@ private void processEnvelope(final @NotNull SentryEnvelope envelope, final @NotN
logUnexpectedEventId(envelope, event.getEventId(), currentItem);
continue;
}
hub.captureEvent(event, hint);
scopes.captureEvent(event, hint);
logItemCaptured(currentItem);

if (!waitFlush(hint)) {
Expand Down Expand Up @@ -181,7 +181,7 @@ private void processEnvelope(final @NotNull SentryEnvelope envelope, final @NotN
.getTrace()
.setSamplingDecision(extractSamplingDecision(traceContext));
}
hub.captureTransaction(transaction, traceContext, hint);
scopes.captureTransaction(transaction, traceContext, hint);
logItemCaptured(currentItem);

if (!waitFlush(hint)) {
Expand All @@ -197,7 +197,7 @@ private void processEnvelope(final @NotNull SentryEnvelope envelope, final @NotN
final SentryEnvelope newEnvelope =
new SentryEnvelope(
envelope.getHeader().getEventId(), envelope.getHeader().getSdkVersion(), item);
hub.captureEnvelope(newEnvelope, hint);
scopes.captureEnvelope(newEnvelope, hint);
logger.log(
SentryLevel.DEBUG,
"%s item %d is being captured.",
Expand Down
8 changes: 4 additions & 4 deletions sentry/src/main/java/io/sentry/PreviousSessionFinalizer.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ final class PreviousSessionFinalizer implements Runnable {

private final @NotNull SentryOptions options;

private final @NotNull IHub hub;
private final @NotNull IScopes scopes;

PreviousSessionFinalizer(final @NotNull SentryOptions options, final @NotNull IHub hub) {
PreviousSessionFinalizer(final @NotNull SentryOptions options, final @NotNull IScopes scopes) {
this.options = options;
this.hub = hub;
this.scopes = scopes;
}

@Override
Expand Down Expand Up @@ -116,7 +116,7 @@ public void run() {
// SdkVersion will be outdated.
final SentryEnvelope fromSession =
SentryEnvelope.from(serializer, session, options.getSdkVersion());
hub.captureEnvelope(fromSession);
scopes.captureEnvelope(fromSession);
}
} catch (Throwable e) {
options.getLogger().log(SentryLevel.ERROR, "Error processing previous session.", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public final class SendCachedEnvelopeFireAndForgetIntegration

private final @NotNull SendFireAndForgetFactory factory;
private @Nullable IConnectionStatusProvider connectionStatusProvider;
private @Nullable IHub hub;
private @Nullable IScopes scopes;
private @Nullable SentryOptions options;
private @Nullable SendFireAndForget sender;
private final AtomicBoolean isInitialized = new AtomicBoolean(false);
Expand All @@ -35,7 +35,7 @@ public interface SendFireAndForgetDirPath {

public interface SendFireAndForgetFactory {
@Nullable
SendFireAndForget create(@NotNull IHub hub, @NotNull SentryOptions options);
SendFireAndForget create(@NotNull IScopes scopes, @NotNull SentryOptions options);

default boolean hasValidPath(final @Nullable String dirPath, final @NotNull ILogger logger) {
if (dirPath == null || dirPath.isEmpty()) {
Expand Down Expand Up @@ -66,8 +66,8 @@ public SendCachedEnvelopeFireAndForgetIntegration(
}

@Override
public void register(final @NotNull IHub hub, final @NotNull SentryOptions options) {
this.hub = Objects.requireNonNull(hub, "Hub is required");
public void register(final @NotNull IScopes scopes, final @NotNull SentryOptions options) {
this.scopes = Objects.requireNonNull(scopes, "Hub is required");
this.options = Objects.requireNonNull(options, "SentryOptions is required");

final String cachedDir = options.getCacheDirPath();
Expand All @@ -81,7 +81,7 @@ public void register(final @NotNull IHub hub, final @NotNull SentryOptions optio
.log(SentryLevel.DEBUG, "SendCachedEventFireAndForgetIntegration installed.");
addIntegrationToSdkVersion(getClass());

sendCachedEnvelopes(hub, options);
sendCachedEnvelopes(scopes, options);
}

@Override
Expand All @@ -95,14 +95,14 @@ public void close() throws IOException {
@Override
public void onConnectionStatusChanged(
final @NotNull IConnectionStatusProvider.ConnectionStatus status) {
if (hub != null && options != null) {
sendCachedEnvelopes(hub, options);
if (scopes != null && options != null) {
sendCachedEnvelopes(scopes, options);
}
}

@SuppressWarnings({"FutureReturnValueIgnored", "NullAway"})
private synchronized void sendCachedEnvelopes(
final @NotNull IHub hub, final @NotNull SentryOptions options) {
final @NotNull IScopes scopes, final @NotNull SentryOptions options) {
try {
options
.getExecutorService()
Expand All @@ -122,7 +122,7 @@ private synchronized void sendCachedEnvelopes(
connectionStatusProvider = options.getConnectionStatusProvider();
connectionStatusProvider.addConnectionStatusObserver(this);

sender = factory.create(hub, options);
sender = factory.create(scopes, options);
}

// skip run only if we're certainly disconnected
Expand All @@ -138,7 +138,7 @@ private synchronized void sendCachedEnvelopes(
}

// in case there's rate limiting active, skip processing
final @Nullable RateLimiter rateLimiter = hub.getRateLimiter();
final @Nullable RateLimiter rateLimiter = scopes.getRateLimiter();
if (rateLimiter != null && rateLimiter.isActiveForCategory(DataCategory.All)) {
options
.getLogger()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public SendFireAndForgetEnvelopeSender(

@Override
public @Nullable SendCachedEnvelopeFireAndForgetIntegration.SendFireAndForget create(
final @NotNull IHub hub, final @NotNull SentryOptions options) {
Objects.requireNonNull(hub, "Hub is required");
final @NotNull IScopes scopes, final @NotNull SentryOptions options) {
Objects.requireNonNull(scopes, "Hub is required");
Objects.requireNonNull(options, "SentryOptions is required");

final String dirPath = sendFireAndForgetDirPath.getDirPath();
Expand All @@ -33,7 +33,7 @@ public SendFireAndForgetEnvelopeSender(

final EnvelopeSender envelopeSender =
new EnvelopeSender(
hub,
scopes,
options.getSerializer(),
options.getLogger(),
options.getFlushTimeoutMillis(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public SendFireAndForgetOutboxSender(

@Override
public @Nullable SendCachedEnvelopeFireAndForgetIntegration.SendFireAndForget create(
final @NotNull IHub hub, final @NotNull SentryOptions options) {
Objects.requireNonNull(hub, "Hub is required");
final @NotNull IScopes scopes, final @NotNull SentryOptions options) {
Objects.requireNonNull(scopes, "Hub is required");
Objects.requireNonNull(options, "SentryOptions is required");

final String dirPath = sendFireAndForgetDirPath.getDirPath();
Expand All @@ -33,7 +33,7 @@ public SendFireAndForgetOutboxSender(

final OutboxSender outboxSender =
new OutboxSender(
hub,
scopes,
options.getEnvelopeReader(),
options.getSerializer(),
options.getLogger(),
Expand Down
Loading

0 comments on commit ce3c14f

Please sign in to comment.