Skip to content
This repository was archived by the owner on Aug 30, 2023. It is now read-only.
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
import android.content.pm.PackageInfo;
import android.os.Build;
import io.sentry.core.ILogger;
import io.sentry.core.SendCachedEventFireAndForgetIntegration;
import io.sentry.core.SendCachedEnvelopeFireAndForgetIntegration;
import io.sentry.core.SendFireAndForgetEnvelopeSender;
import io.sentry.core.SendFireAndForgetEventSender;
import io.sentry.core.SendFireAndForgetOutboxSender;
import io.sentry.core.SentryLevel;
import io.sentry.core.SentryOptions;
import io.sentry.core.util.Objects;
Expand Down Expand Up @@ -116,12 +116,8 @@ private static void installDefaultIntegrations(
final @NotNull ILoadClass loadClass) {

options.addIntegration(
new SendCachedEventFireAndForgetIntegration(
new SendFireAndForgetEventSender(() -> options.getCacheDirPath())));

options.addIntegration(
new SendCachedEventFireAndForgetIntegration(
new SendFireAndForgetEnvelopeSender(() -> options.getSessionsPath())));
new SendCachedEnvelopeFireAndForgetIntegration(
new SendFireAndForgetEnvelopeSender(() -> options.getCacheDirPath())));

// Integrations are registered in the same order. NDK before adding Watch outbox,
// because sentry-native move files around and we don't want to watch that.
Expand All @@ -136,8 +132,8 @@ private static void installDefaultIntegrations(
// this should be executed after NdkIntegration because sentry-native move files on init.
// and we'd like to send them right away
options.addIntegration(
new SendCachedEventFireAndForgetIntegration(
new SendFireAndForgetEnvelopeSender(() -> options.getOutboxPath())));
new SendCachedEnvelopeFireAndForgetIntegration(
new SendFireAndForgetOutboxSender(() -> options.getOutboxPath())));

options.addIntegration(new AnrIntegration(context));
options.addIntegration(new AppLifecycleIntegration());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package io.sentry.android.core;

import io.sentry.core.EnvelopeSender;
import io.sentry.core.IHub;
import io.sentry.core.ILogger;
import io.sentry.core.Integration;
import io.sentry.core.OutboxSender;
import io.sentry.core.SentryLevel;
import io.sentry.core.SentryOptions;
import io.sentry.core.util.Objects;
Expand Down Expand Up @@ -37,16 +37,16 @@ public final void register(final @NotNull IHub hub, final @NotNull SentryOptions
logger.log(
SentryLevel.DEBUG, "Registering EnvelopeFileObserverIntegration for path: %s", path);

final EnvelopeSender envelopeSender =
new EnvelopeSender(
final OutboxSender outboxSender =
new OutboxSender(
hub,
options.getEnvelopeReader(),
options.getSerializer(),
logger,
options.getFlushTimeoutMillis());

observer =
new EnvelopeFileObserver(path, envelopeSender, logger, options.getFlushTimeoutMillis());
new EnvelopeFileObserver(path, outboxSender, logger, options.getFlushTimeoutMillis());
observer.startWatching();

logger.log(SentryLevel.DEBUG, "EnvelopeFileObserverIntegration installed.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ static void applyMetadata(
options.setEnableSessionTracking(sessionTrackingEnabled);

if (options.getSampleRate() == null) {
// TODO: it needs to read a Float I guess
Double sampleRate = metadata.getDouble(SAMPLE_RATE, -1);
options.getLogger().log(SentryLevel.DEBUG, "sampleRate read: %s", sampleRate);
if (sampleRate != -1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import com.nhaarman.mockitokotlin2.verify
import com.nhaarman.mockitokotlin2.whenever
import io.sentry.core.ILogger
import io.sentry.core.MainEventProcessor
import io.sentry.core.SendCachedEventFireAndForgetIntegration
import io.sentry.core.SendCachedEnvelopeFireAndForgetIntegration
import io.sentry.core.SentryLevel
import io.sentry.core.SentryOptions
import java.io.File
Expand Down Expand Up @@ -92,16 +92,6 @@ class AndroidOptionsInitializerTest {
assertTrue(sentryOptions.outboxPath?.endsWith("${File.separator}cache${File.separator}sentry${File.separator}outbox")!!)
}

@Test
fun `sessionDir should be set at initialization`() {
val sentryOptions = SentryAndroidOptions()
val mockContext = createMockContext()

AndroidOptionsInitializer.init(sentryOptions, mockContext)

assertTrue(sentryOptions.sessionsPath?.endsWith("${File.separator}cache${File.separator}sentry${File.separator}sessions")!!)
}

@Test
fun `init should set context package name as appInclude`() {
val sentryOptions = SentryAndroidOptions()
Expand Down Expand Up @@ -271,12 +261,12 @@ class AndroidOptionsInitializerTest {
}

@Test
fun `SendCachedEventFireAndForgetIntegration added to integration list`() {
fun `SendCachedEnvelopeFireAndForgetIntegration added to integration list`() {
val sentryOptions = SentryAndroidOptions()
val mockContext = createMockContext()

AndroidOptionsInitializer.init(sentryOptions, mockContext)
val actual = sentryOptions.integrations.firstOrNull { it is SendCachedEventFireAndForgetIntegration }
val actual = sentryOptions.integrations.firstOrNull { it is SendCachedEnvelopeFireAndForgetIntegration }
assertNotNull(actual)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
package io.sentry.core;

import io.sentry.core.cache.IEnvelopeCache;
import io.sentry.core.cache.IEventCache;
import io.sentry.core.transport.AsyncConnection;

final class AsyncConnectionFactory {
private AsyncConnectionFactory() {}

public static AsyncConnection create(
SentryOptions options, IEventCache eventCache, IEnvelopeCache sessionCache) {
public static AsyncConnection create(SentryOptions options, IEnvelopeCache envelopeCache) {

// the connection doesn't do any retries of failed sends and can hold at most the same number
// of pending events as there are being cached. The rest is dropped.
return new AsyncConnection(
options.getTransport(),
options.getTransportGate(),
eventCache,
sessionCache,
envelopeCache,
options.getMaxQueueSize(),
options);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ abstract class DirectoryProcessor {
this.flushTimeoutMillis = flushTimeoutMillis;
}

public void processDirectory(@NotNull File directory) {
public void processDirectory(final @NotNull File directory) {
try {
logger.log(SentryLevel.DEBUG, "Processing dir. %s", directory.getAbsolutePath());

Expand All @@ -39,13 +39,13 @@ public void processDirectory(@NotNull File directory) {
return;
}

File[] listFiles = directory.listFiles();
final File[] listFiles = directory.listFiles();
if (listFiles == null) {
logger.log(SentryLevel.ERROR, "Cache dir %s is null.", directory.getAbsolutePath());
return;
}

File[] filteredListFiles = directory.listFiles((d, name) -> isRelevantFileName(name));
final File[] filteredListFiles = directory.listFiles((d, name) -> isRelevantFileName(name));

logger.log(
SentryLevel.DEBUG,
Expand All @@ -62,19 +62,19 @@ public void processDirectory(@NotNull File directory) {

logger.log(SentryLevel.DEBUG, "Processing file: %s", file.getAbsolutePath());

final SendCachedEventHint hint = new SendCachedEventHint(flushTimeoutMillis, logger);
final SendCachedEnvelopeHint hint = new SendCachedEnvelopeHint(flushTimeoutMillis, logger);
processFile(file, hint);
}
} catch (Exception e) {
logger.log(SentryLevel.ERROR, e, "Failed processing '%s'", directory.getAbsolutePath());
}
}

protected abstract void processFile(File file, @Nullable Object hint);
protected abstract void processFile(final @NotNull File file, final @Nullable Object hint);

protected abstract boolean isRelevantFileName(String fileName);

private static final class SendCachedEventHint
private static final class SendCachedEnvelopeHint
implements Cached, Retryable, SubmissionResult, Flushable {
boolean retry = false;
boolean succeeded = false;
Expand All @@ -83,7 +83,7 @@ private static final class SendCachedEventHint
private final long flushTimeoutMillis;
private final @NotNull ILogger logger;

public SendCachedEventHint(final long flushTimeoutMillis, final @NotNull ILogger logger) {
public SendCachedEnvelopeHint(final long flushTimeoutMillis, final @NotNull ILogger logger) {
this.flushTimeoutMillis = flushTimeoutMillis;
this.latch = new CountDownLatch(1);
this.logger = logger;
Expand Down
Loading