From ab2d082aa0843fa5608e8f4bb6ecbffe839480ba Mon Sep 17 00:00:00 2001 From: Alexander Dinauer Date: Thu, 12 May 2022 06:26:46 +0200 Subject: [PATCH 1/9] Replace hint Map with Hints object --- .../api/sentry-android-core.api | 2 +- .../core/ActivityLifecycleIntegration.java | 8 +- .../AppComponentsBreadcrumbsIntegration.java | 9 +- .../core/DefaultAndroidEventProcessor.java | 13 +- .../android/core/EnvelopeFileObserver.java | 10 +- .../PerformanceAndroidEventProcessor.java | 7 +- .../core/ScreenshotEventProcessor.java | 14 +- .../SystemEventsBreadcrumbsIntegration.java | 7 +- .../TempSensorBreadcrumbsIntegration.java | 9 +- .../gestures/SentryGestureListener.java | 10 +- .../core/DefaultAndroidEventProcessorTest.kt | 60 +++---- .../android/core/EnvelopeFileObserverTest.kt | 17 +- .../PerformanceAndroidEventProcessorTest.kt | 21 +-- .../core/ScreenshotEventProcessorTest.kt | 15 +- .../SentryFragmentLifecycleCallbacks.kt | 5 +- .../android/okhttp/SentryOkHttpInterceptor.kt | 7 +- .../api/sentry-apache-http-client-5.api | 2 +- .../apache/ApacheHttpClientTransport.java | 15 +- ...acheHttpClientTransportClientReportTest.kt | 4 +- .../sentry/apollo/SentryApolloInterceptor.kt | 8 +- .../SentryDataFetcherExceptionHandler.java | 9 +- .../java/io/sentry/jul/SentryHandler.java | 14 +- .../java/io/sentry/log4j2/SentryAppender.java | 14 +- .../io/sentry/logback/SentryAppender.java | 14 +- .../sentry/openfeign/SentryFeignClient.java | 10 +- .../java/io/sentry/samples/console/Main.java | 11 +- .../spring/boot/CustomEventProcessor.java | 6 +- ...tryRequestHttpServletRequestProcessor.java | 4 +- .../jakarta/SentryServletRequestListener.java | 9 +- ...yRequestHttpServletRequestProcessorTest.kt | 9 +- ...tryRequestHttpServletRequestProcessor.java | 4 +- .../servlet/SentryServletRequestListener.java | 9 +- ...yRequestHttpServletRequestProcessorTest.kt | 9 +- .../boot/SentryAutoConfigurationTest.kt | 7 +- sentry-spring/api/sentry-spring.api | 2 +- .../spring/SentryExceptionResolver.java | 11 +- ...tryRequestHttpServletRequestProcessor.java | 5 +- .../io/sentry/spring/SentrySpringFilter.java | 15 +- ...entrySpanClientHttpRequestInterceptor.java | 13 +- .../SentrySpanClientWebRequestFilter.java | 11 +- .../webflux/SentryWebExceptionHandler.java | 11 +- .../spring/webflux/SentryWebFilter.java | 11 +- ...yRequestHttpServletRequestProcessorTest.kt | 5 +- sentry/api/sentry.api | 147 ++++++++++-------- .../java/io/sentry/DirectoryProcessor.java | 14 +- ...DuplicateEventDetectionEventProcessor.java | 3 +- .../main/java/io/sentry/EnvelopeSender.java | 73 ++++----- .../main/java/io/sentry/EventProcessor.java | 11 +- sentry/src/main/java/io/sentry/Hub.java | 41 +++-- .../src/main/java/io/sentry/HubAdapter.java | 24 ++- .../main/java/io/sentry/IEnvelopeSender.java | 5 +- sentry/src/main/java/io/sentry/IHub.java | 36 ++--- .../main/java/io/sentry/ISentryClient.java | 53 +++---- .../java/io/sentry/MainEventProcessor.java | 27 ++-- sentry/src/main/java/io/sentry/NoOpHub.java | 14 +- .../main/java/io/sentry/NoOpSentryClient.java | 11 +- .../src/main/java/io/sentry/OutboxSender.java | 65 ++++---- sentry/src/main/java/io/sentry/Scope.java | 17 +- sentry/src/main/java/io/sentry/Sentry.java | 20 +-- .../src/main/java/io/sentry/SentryClient.java | 87 +++++------ .../main/java/io/sentry/SentryOptions.java | 9 +- .../sentry/SentryRuntimeEventProcessor.java | 6 +- .../main/java/io/sentry/TypeCheckHint.java | 1 + .../UncaughtExceptionHandlerIntegration.java | 10 +- .../java/io/sentry/cache/EnvelopeCache.java | 11 +- .../java/io/sentry/cache/IEnvelopeCache.java | 7 +- .../src/main/java/io/sentry/hints/Hints.java | 29 ++++ .../sentry/transport/AsyncHttpTransport.java | 127 ++++++++------- .../java/io/sentry/transport/ITransport.java | 8 +- .../sentry/transport/NoOpEnvelopeCache.java | 5 +- .../io/sentry/transport/NoOpTransport.java | 5 +- .../java/io/sentry/transport/RateLimiter.java | 19 +-- .../io/sentry/transport/StdoutTransport.java | 5 +- .../main/java/io/sentry/util/HintUtils.java | 97 ++++++++++-- .../main/java/io/sentry/util/LogUtils.java | 33 ++-- .../java/io/sentry/CustomEventProcessor.kt | 4 +- .../java/io/sentry/DirectoryProcessorTest.kt | 3 +- ...plicateEventDetectionEventProcessorTest.kt | 29 ++-- .../test/java/io/sentry/EnvelopeSenderTest.kt | 9 +- sentry/src/test/java/io/sentry/HubTest.kt | 72 ++++----- .../java/io/sentry/MainEventProcessorTest.kt | 79 +++++----- sentry/src/test/java/io/sentry/NoOpHubTest.kt | 3 +- .../test/java/io/sentry/OutboxSenderTest.kt | 34 ++-- sentry/src/test/java/io/sentry/ScopeTest.kt | 3 +- .../test/java/io/sentry/SentryClientTest.kt | 51 +++--- .../java/io/sentry/cache/EnvelopeCacheTest.kt | 50 +++--- .../sentry/clientreport/ClientReportTest.kt | 13 +- .../transport/AsyncHttpTransportTest.kt | 10 +- .../io/sentry/transport/RateLimiterTest.kt | 21 +-- .../test/java/io/sentry/util/HintUtilsTest.kt | 16 +- 90 files changed, 997 insertions(+), 876 deletions(-) create mode 100644 sentry/src/main/java/io/sentry/hints/Hints.java diff --git a/sentry-android-core/api/sentry-android-core.api b/sentry-android-core/api/sentry-android-core.api index c96869a338..1117339a3d 100644 --- a/sentry-android-core/api/sentry-android-core.api +++ b/sentry-android-core/api/sentry-android-core.api @@ -110,7 +110,7 @@ public final class io/sentry/android/core/ScreenshotEventProcessor : android/app public fun onActivitySaveInstanceState (Landroid/app/Activity;Landroid/os/Bundle;)V public fun onActivityStarted (Landroid/app/Activity;)V public fun onActivityStopped (Landroid/app/Activity;)V - public fun process (Lio/sentry/SentryEvent;Ljava/util/Map;)Lio/sentry/SentryEvent; + public fun process (Lio/sentry/SentryEvent;Lio/sentry/hints/Hints;)Lio/sentry/SentryEvent; } public final class io/sentry/android/core/SentryAndroid { diff --git a/sentry-android-core/src/main/java/io/sentry/android/core/ActivityLifecycleIntegration.java b/sentry-android-core/src/main/java/io/sentry/android/core/ActivityLifecycleIntegration.java index 461a4743c4..a8a1201adc 100644 --- a/sentry-android-core/src/main/java/io/sentry/android/core/ActivityLifecycleIntegration.java +++ b/sentry-android-core/src/main/java/io/sentry/android/core/ActivityLifecycleIntegration.java @@ -19,11 +19,11 @@ import io.sentry.SentryLevel; import io.sentry.SentryOptions; import io.sentry.SpanStatus; +import io.sentry.hints.Hints; import io.sentry.util.Objects; import java.io.Closeable; import java.io.IOException; import java.util.Date; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.WeakHashMap; @@ -126,10 +126,10 @@ private void addBreadcrumb(final @NotNull Activity activity, final @NotNull Stri breadcrumb.setCategory("ui.lifecycle"); breadcrumb.setLevel(SentryLevel.INFO); - final Map hintMap = new HashMap<>(); - hintMap.put(ANDROID_ACTIVITY, activity); + final Hints hints = new Hints(); + hints.set(ANDROID_ACTIVITY, activity); - hub.addBreadcrumb(breadcrumb, hintMap); + hub.addBreadcrumb(breadcrumb, hints); } } diff --git a/sentry-android-core/src/main/java/io/sentry/android/core/AppComponentsBreadcrumbsIntegration.java b/sentry-android-core/src/main/java/io/sentry/android/core/AppComponentsBreadcrumbsIntegration.java index 9536ef4b26..b062220037 100644 --- a/sentry-android-core/src/main/java/io/sentry/android/core/AppComponentsBreadcrumbsIntegration.java +++ b/sentry-android-core/src/main/java/io/sentry/android/core/AppComponentsBreadcrumbsIntegration.java @@ -11,13 +11,12 @@ import io.sentry.SentryLevel; import io.sentry.SentryOptions; import io.sentry.android.core.internal.util.DeviceOrientations; +import io.sentry.hints.Hints; import io.sentry.protocol.Device; import io.sentry.util.Objects; import java.io.Closeable; import java.io.IOException; -import java.util.HashMap; import java.util.Locale; -import java.util.Map; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -100,10 +99,10 @@ public void onConfigurationChanged(@NotNull Configuration newConfig) { breadcrumb.setData("position", orientation); breadcrumb.setLevel(SentryLevel.INFO); - final Map hintMap = new HashMap<>(); - hintMap.put(ANDROID_CONFIGURATION, newConfig); + final Hints hints = new Hints(); + hints.set(ANDROID_CONFIGURATION, newConfig); - hub.addBreadcrumb(breadcrumb, hintMap); + hub.addBreadcrumb(breadcrumb, hints); } } diff --git a/sentry-android-core/src/main/java/io/sentry/android/core/DefaultAndroidEventProcessor.java b/sentry-android-core/src/main/java/io/sentry/android/core/DefaultAndroidEventProcessor.java index 469ea2f837..d9947a42ae 100644 --- a/sentry-android-core/src/main/java/io/sentry/android/core/DefaultAndroidEventProcessor.java +++ b/sentry-android-core/src/main/java/io/sentry/android/core/DefaultAndroidEventProcessor.java @@ -28,6 +28,7 @@ import io.sentry.android.core.internal.util.DeviceOrientations; import io.sentry.android.core.internal.util.MainThreadChecker; import io.sentry.android.core.internal.util.RootChecker; +import io.sentry.hints.Hints; import io.sentry.protocol.App; import io.sentry.protocol.Device; import io.sentry.protocol.OperatingSystem; @@ -117,8 +118,8 @@ public DefaultAndroidEventProcessor( @Override public @NotNull SentryEvent process( - final @NotNull SentryEvent event, final @Nullable Map hint) { - final boolean applyScopeData = shouldApplyScopeData(event, hint); + final @NotNull SentryEvent event, final @NotNull Hints hints) { + final boolean applyScopeData = shouldApplyScopeData(event, hints); if (applyScopeData) { // we only set memory data if it's not a hard crash, when it's a hard crash the event is // enriched on restart, so non static data might be wrong, eg lowMemory or availMem will @@ -143,8 +144,8 @@ private void setCommons( } private boolean shouldApplyScopeData( - final @NotNull SentryBaseEvent event, final @Nullable Map hint) { - if (HintUtils.shouldApplyScopeData(hint)) { + final @NotNull SentryBaseEvent event, final @NotNull Hints hints) { + if (HintUtils.shouldApplyScopeData(hints)) { return true; } else { logger.log( @@ -857,8 +858,8 @@ private void setSideLoadedInfo(final @NotNull SentryBaseEvent event) { @Override public @NotNull SentryTransaction process( - final @NotNull SentryTransaction transaction, final @Nullable Map hint) { - final boolean applyScopeData = shouldApplyScopeData(transaction, hint); + final @NotNull SentryTransaction transaction, final @NotNull Hints hints) { + final boolean applyScopeData = shouldApplyScopeData(transaction, hints); if (applyScopeData) { processNonCachedEvent(transaction); diff --git a/sentry-android-core/src/main/java/io/sentry/android/core/EnvelopeFileObserver.java b/sentry-android-core/src/main/java/io/sentry/android/core/EnvelopeFileObserver.java index 57cadbcdd5..5442e015a1 100644 --- a/sentry-android-core/src/main/java/io/sentry/android/core/EnvelopeFileObserver.java +++ b/sentry-android-core/src/main/java/io/sentry/android/core/EnvelopeFileObserver.java @@ -1,7 +1,6 @@ package io.sentry.android.core; import static io.sentry.SentryLevel.ERROR; -import static io.sentry.TypeCheckHint.SENTRY_TYPE_CHECK_HINT; import android.os.FileObserver; import io.sentry.IEnvelopeSender; @@ -10,13 +9,13 @@ import io.sentry.hints.ApplyScopeData; import io.sentry.hints.Cached; import io.sentry.hints.Flushable; +import io.sentry.hints.Hints; import io.sentry.hints.Resettable; import io.sentry.hints.Retryable; import io.sentry.hints.SubmissionResult; +import io.sentry.util.HintUtils; import io.sentry.util.Objects; import java.io.File; -import java.util.HashMap; -import java.util.Map; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import org.jetbrains.annotations.NotNull; @@ -60,10 +59,9 @@ public void onEvent(int eventType, @Nullable String relativePath) { final CachedEnvelopeHint hint = new CachedEnvelopeHint(flushTimeoutMillis, logger); - final Map hintMap = new HashMap<>(); - hintMap.put(SENTRY_TYPE_CHECK_HINT, hint); + final Hints hints = HintUtils.createWithTypeCheckHint(hint); - envelopeSender.processEnvelopeFile(this.rootPath + File.separator + relativePath, hintMap); + envelopeSender.processEnvelopeFile(this.rootPath + File.separator + relativePath, hints); } private static final class CachedEnvelopeHint diff --git a/sentry-android-core/src/main/java/io/sentry/android/core/PerformanceAndroidEventProcessor.java b/sentry-android-core/src/main/java/io/sentry/android/core/PerformanceAndroidEventProcessor.java index 708d5ecd93..5c7f5cbb5e 100644 --- a/sentry-android-core/src/main/java/io/sentry/android/core/PerformanceAndroidEventProcessor.java +++ b/sentry-android-core/src/main/java/io/sentry/android/core/PerformanceAndroidEventProcessor.java @@ -7,6 +7,7 @@ import io.sentry.EventProcessor; import io.sentry.SentryEvent; import io.sentry.SpanContext; +import io.sentry.hints.Hints; import io.sentry.protocol.MeasurementValue; import io.sentry.protocol.SentryId; import io.sentry.protocol.SentrySpan; @@ -37,12 +38,12 @@ final class PerformanceAndroidEventProcessor implements EventProcessor { * Returns the event itself * * @param event the SentryEvent the SentryEvent - * @param hint the Hint the Hint + * @param hints the Hint the Hint * @return returns the event itself */ @Override @Nullable - public SentryEvent process(@NotNull SentryEvent event, @Nullable Map hint) { + public SentryEvent process(@NotNull SentryEvent event, @NotNull Hints hints) { // that's only necessary because on newer versions of Unity, if not overriding this method, it's // throwing 'java.lang.AbstractMethodError: abstract method' and the reason is probably // compilation mismatch. @@ -52,7 +53,7 @@ public SentryEvent process(@NotNull SentryEvent event, @Nullable Map hint) { + @NotNull SentryTransaction transaction, @NotNull Hints hints) { if (!options.isTracingEnabled()) { return transaction; diff --git a/sentry-android-core/src/main/java/io/sentry/android/core/ScreenshotEventProcessor.java b/sentry-android-core/src/main/java/io/sentry/android/core/ScreenshotEventProcessor.java index e738e40060..6fed7fcf3b 100644 --- a/sentry-android-core/src/main/java/io/sentry/android/core/ScreenshotEventProcessor.java +++ b/sentry-android-core/src/main/java/io/sentry/android/core/ScreenshotEventProcessor.java @@ -17,13 +17,12 @@ import io.sentry.EventProcessor; import io.sentry.SentryEvent; import io.sentry.SentryLevel; +import io.sentry.hints.Hints; import io.sentry.util.Objects; import java.io.ByteArrayOutputStream; import java.io.Closeable; import java.io.IOException; import java.lang.ref.WeakReference; -import java.util.HashMap; -import java.util.Map; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; @@ -68,8 +67,7 @@ public ScreenshotEventProcessor( @SuppressWarnings("NullAway") @Override - public @NotNull SentryEvent process( - final @NotNull SentryEvent event, @Nullable Map hint) { + public @NotNull SentryEvent process(final @NotNull SentryEvent event, @NotNull Hints hints) { if (options.isAttachScreenshot() && event.isErrored() && currentActivity != null) { final Activity activity = currentActivity.get(); if (isActivityValid(activity) @@ -93,16 +91,12 @@ public ScreenshotEventProcessor( // Some formats, like PNG which is lossless, will ignore the quality setting. bitmap.compress(Bitmap.CompressFormat.PNG, 0, byteArrayOutputStream); - if (hint == null) { - hint = new HashMap<>(); - } - if (byteArrayOutputStream.size() > 0) { // screenshot png is around ~100-150 kb - hint.put( + hints.set( SENTRY_SCREENSHOT, Attachment.fromScreenshot(byteArrayOutputStream.toByteArray())); - hint.put(ANDROID_ACTIVITY, activity); + hints.set(ANDROID_ACTIVITY, activity); } else { this.options .getLogger() diff --git a/sentry-android-core/src/main/java/io/sentry/android/core/SystemEventsBreadcrumbsIntegration.java b/sentry-android-core/src/main/java/io/sentry/android/core/SystemEventsBreadcrumbsIntegration.java index c626debf41..b39bcb7e30 100644 --- a/sentry-android-core/src/main/java/io/sentry/android/core/SystemEventsBreadcrumbsIntegration.java +++ b/sentry-android-core/src/main/java/io/sentry/android/core/SystemEventsBreadcrumbsIntegration.java @@ -43,6 +43,7 @@ import io.sentry.Integration; import io.sentry.SentryLevel; import io.sentry.SentryOptions; +import io.sentry.hints.Hints; import io.sentry.util.Objects; import io.sentry.util.StringUtils; import java.io.Closeable; @@ -215,10 +216,10 @@ public void onReceive(Context context, Intent intent) { } breadcrumb.setLevel(SentryLevel.INFO); - final Map hintMap = new HashMap<>(); - hintMap.put(ANDROID_INTENT, intent); + final Hints hints = new Hints(); + hints.set(ANDROID_INTENT, intent); - hub.addBreadcrumb(breadcrumb, hintMap); + hub.addBreadcrumb(breadcrumb, hints); } } } diff --git a/sentry-android-core/src/main/java/io/sentry/android/core/TempSensorBreadcrumbsIntegration.java b/sentry-android-core/src/main/java/io/sentry/android/core/TempSensorBreadcrumbsIntegration.java index 0d8877a407..7ce2a80f74 100644 --- a/sentry-android-core/src/main/java/io/sentry/android/core/TempSensorBreadcrumbsIntegration.java +++ b/sentry-android-core/src/main/java/io/sentry/android/core/TempSensorBreadcrumbsIntegration.java @@ -13,11 +13,10 @@ import io.sentry.Integration; import io.sentry.SentryLevel; import io.sentry.SentryOptions; +import io.sentry.hints.Hints; import io.sentry.util.Objects; import java.io.Closeable; import java.io.IOException; -import java.util.HashMap; -import java.util.Map; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.TestOnly; @@ -107,10 +106,10 @@ public void onSensorChanged(final @NotNull SensorEvent event) { breadcrumb.setLevel(SentryLevel.INFO); breadcrumb.setData("degree", event.values[0]); // Celsius - final Map hintMap = new HashMap<>(); - hintMap.put(ANDROID_SENSOR_EVENT, event); + final Hints hints = new Hints(); + hints.set(ANDROID_SENSOR_EVENT, event); - hub.addBreadcrumb(breadcrumb, hintMap); + hub.addBreadcrumb(breadcrumb, hints); } } diff --git a/sentry-android-core/src/main/java/io/sentry/android/core/internal/gestures/SentryGestureListener.java b/sentry-android-core/src/main/java/io/sentry/android/core/internal/gestures/SentryGestureListener.java index 4b65114ae5..0a50967ec8 100644 --- a/sentry-android-core/src/main/java/io/sentry/android/core/internal/gestures/SentryGestureListener.java +++ b/sentry-android-core/src/main/java/io/sentry/android/core/internal/gestures/SentryGestureListener.java @@ -11,9 +11,9 @@ import io.sentry.IHub; import io.sentry.SentryLevel; import io.sentry.android.core.SentryAndroidOptions; +import io.sentry.hints.Hints; import java.lang.ref.WeakReference; import java.util.Collections; -import java.util.HashMap; import java.util.Map; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; @@ -172,14 +172,14 @@ private void addBreadcrumb( className = target.getClass().getSimpleName(); } - final Map hintMap = new HashMap<>(); - hintMap.put(ANDROID_MOTION_EVENT, motionEvent); - hintMap.put(ANDROID_VIEW, target); + final Hints hints = new Hints(); + hints.set(ANDROID_MOTION_EVENT, motionEvent); + hints.set(ANDROID_VIEW, target); hub.addBreadcrumb( Breadcrumb.userInteraction( eventType, ViewUtils.getResourceId(target), className, additionalData), - hintMap); + hints); } private @Nullable View ensureWindowDecorView(final @NotNull String caller) { diff --git a/sentry-android-core/src/test/java/io/sentry/android/core/DefaultAndroidEventProcessorTest.kt b/sentry-android-core/src/test/java/io/sentry/android/core/DefaultAndroidEventProcessorTest.kt index 0a76a6ade5..14d901d3a9 100644 --- a/sentry-android-core/src/test/java/io/sentry/android/core/DefaultAndroidEventProcessorTest.kt +++ b/sentry-android-core/src/test/java/io/sentry/android/core/DefaultAndroidEventProcessorTest.kt @@ -16,17 +16,18 @@ import io.sentry.SentryLevel import io.sentry.SentryOptions import io.sentry.SentryTracer import io.sentry.TransactionContext -import io.sentry.TypeCheckHint.SENTRY_TYPE_CHECK_HINT import io.sentry.android.core.DefaultAndroidEventProcessor.EMULATOR import io.sentry.android.core.DefaultAndroidEventProcessor.KERNEL_VERSION import io.sentry.android.core.DefaultAndroidEventProcessor.ROOTED import io.sentry.android.core.DefaultAndroidEventProcessor.SIDE_LOADED +import io.sentry.hints.Hints import io.sentry.protocol.OperatingSystem import io.sentry.protocol.SdkVersion import io.sentry.protocol.SentryThread import io.sentry.protocol.SentryTransaction import io.sentry.protocol.User import io.sentry.test.getCtor +import io.sentry.util.HintUtils import org.junit.runner.RunWith import java.util.Locale import kotlin.test.BeforeTest @@ -106,7 +107,7 @@ class DefaultAndroidEventProcessorTest { fun `When Event and hint is not Cached, data should be applied`() { val sut = fixture.getSut(context) - assertNotNull(sut.process(SentryEvent(), null)) { + assertNotNull(sut.process(SentryEvent(), Hints())) { assertNotNull(it.contexts.app) assertNotNull(it.dist) } @@ -116,7 +117,7 @@ class DefaultAndroidEventProcessorTest { fun `When Transaction and hint is not Cached, data should be applied`() { val sut = fixture.getSut(context) - assertNotNull(sut.process(SentryTransaction(fixture.sentryTracer), null)) { + assertNotNull(sut.process(SentryTransaction(fixture.sentryTracer), Hints())) { assertNotNull(it.contexts.app) assertNotNull(it.dist) } @@ -133,7 +134,7 @@ class DefaultAndroidEventProcessorTest { threads = mutableListOf(sentryThread) } - assertNotNull(sut.process(event, null)) { + assertNotNull(sut.process(event, Hints())) { assertNotNull(it.threads) { threads -> assertTrue(threads.first().isCurrent == true) } @@ -152,7 +153,7 @@ class DefaultAndroidEventProcessorTest { ) } - assertNotNull(sut.process(event, null)) { + assertNotNull(sut.process(event, Hints())) { assertNotNull(it.threads) { threads -> assertFalse(threads.first().isCurrent == true) } @@ -163,8 +164,8 @@ class DefaultAndroidEventProcessorTest { fun `When Event and hint is Cached, data should not be applied`() { val sut = fixture.getSut(context) - val hintsMap = mutableMapOf(SENTRY_TYPE_CHECK_HINT to CachedEvent()) - assertNotNull(sut.process(SentryEvent(), hintsMap)) { + val hints = HintUtils.createWithTypeCheckHint(CachedEvent()) + assertNotNull(sut.process(SentryEvent(), hints)) { assertNull(it.contexts.app) assertNull(it.debugMeta) assertNull(it.dist) @@ -175,8 +176,8 @@ class DefaultAndroidEventProcessorTest { fun `When Transaction and hint is Cached, data should not be applied`() { val sut = fixture.getSut(context) - val hintsMap = mutableMapOf(SENTRY_TYPE_CHECK_HINT to CachedEvent()) - assertNotNull(sut.process(SentryTransaction(fixture.sentryTracer), hintsMap)) { + val hints = HintUtils.createWithTypeCheckHint(CachedEvent()) + assertNotNull(sut.process(SentryTransaction(fixture.sentryTracer), hints)) { assertNull(it.contexts.app) assertNull(it.dist) } @@ -185,9 +186,8 @@ class DefaultAndroidEventProcessorTest { @Test fun `When Event and hint is Cached, userId is applied anyway`() { val sut = fixture.getSut(context) - - val hintsMap = mutableMapOf(SENTRY_TYPE_CHECK_HINT to CachedEvent()) - assertNotNull(sut.process(SentryEvent(), hintsMap)) { + val hints = HintUtils.createWithTypeCheckHint(CachedEvent()) + assertNotNull(sut.process(SentryEvent(), hints)) { assertNotNull(it.user) } } @@ -196,8 +196,8 @@ class DefaultAndroidEventProcessorTest { fun `When Transaction and hint is Cached, userId is applied anyway`() { val sut = fixture.getSut(context) - val hintsMap = mutableMapOf(SENTRY_TYPE_CHECK_HINT to CachedEvent()) - assertNotNull(sut.process(SentryTransaction(fixture.sentryTracer), hintsMap)) { + val hints = HintUtils.createWithTypeCheckHint(CachedEvent()) + assertNotNull(sut.process(SentryTransaction(fixture.sentryTracer), hints)) { assertNotNull(it.user) } } @@ -213,7 +213,7 @@ class DefaultAndroidEventProcessorTest { setUser(user) } - assertNotNull(sut.process(event, null)) { + assertNotNull(sut.process(event, Hints())) { assertNotNull(it.user) assertSame(user, it.user) } @@ -227,7 +227,7 @@ class DefaultAndroidEventProcessorTest { user = User() } - assertNotNull(sut.process(event, null)) { + assertNotNull(sut.process(event, Hints())) { assertNotNull(it.user) assertNotNull(it.user!!.id) } @@ -250,7 +250,7 @@ class DefaultAndroidEventProcessorTest { fun `Processor won't throw exception`() { val sut = fixture.getSut(context) - sut.process(SentryEvent(), null) + sut.process(SentryEvent(), Hints()) verify((fixture.options.logger as DiagnosticLogger).logger, never())!!.log(eq(SentryLevel.ERROR), any(), any()) } @@ -259,8 +259,8 @@ class DefaultAndroidEventProcessorTest { fun `Processor won't throw exception when theres a hint`() { val processor = DefaultAndroidEventProcessor(context, fixture.options.logger, fixture.buildInfo, mock()) - val hintsMap = mutableMapOf(SENTRY_TYPE_CHECK_HINT to CachedEvent()) - processor.process(SentryEvent(), hintsMap) + val hints = HintUtils.createWithTypeCheckHint(CachedEvent()) + processor.process(SentryEvent(), hints) verify((fixture.options.logger as DiagnosticLogger).logger, never())!!.log(eq(SentryLevel.ERROR), any(), any()) } @@ -269,7 +269,7 @@ class DefaultAndroidEventProcessorTest { fun `When event is processed, sideLoaded info should be set`() { val sut = fixture.getSut(context) - assertNotNull(sut.process(SentryEvent(), null)) { + assertNotNull(sut.process(SentryEvent(), Hints())) { assertNotNull(it.getTag("isSideLoaded")) } } @@ -285,7 +285,7 @@ class DefaultAndroidEventProcessorTest { contexts.setOperatingSystem(osLinux) } - assertNotNull(sut.process(event, null)) { + assertNotNull(sut.process(event, Hints())) { assertSame(osLinux, (it.contexts["os_linux"] as OperatingSystem)) assertEquals("Android", it.contexts.operatingSystem!!.name) } @@ -302,7 +302,7 @@ class DefaultAndroidEventProcessorTest { contexts.setOperatingSystem(osNoName) } - assertNotNull(sut.process(event, null)) { + assertNotNull(sut.process(event, Hints())) { assertSame(osNoName, (it.contexts["os_1"] as OperatingSystem)) assertEquals("Android", it.contexts.operatingSystem!!.name) } @@ -312,8 +312,8 @@ class DefaultAndroidEventProcessorTest { fun `When hint is Cached, memory data should not be applied`() { val sut = fixture.getSut(context) - val hintsMap = mutableMapOf(SENTRY_TYPE_CHECK_HINT to CachedEvent()) - assertNotNull(sut.process(SentryEvent(), hintsMap)) { + val hints = HintUtils.createWithTypeCheckHint(CachedEvent()) + assertNotNull(sut.process(SentryEvent(), hints)) { assertNull(it.contexts.device!!.freeMemory) assertNull(it.contexts.device!!.isLowMemory) } @@ -323,7 +323,7 @@ class DefaultAndroidEventProcessorTest { fun `When hint is not Cached, memory data should be applied`() { val sut = fixture.getSut(context) - assertNotNull(sut.process(SentryEvent(), null)) { + assertNotNull(sut.process(SentryEvent(), Hints())) { assertNotNull(it.contexts.device!!.freeMemory) assertNotNull(it.contexts.device!!.isLowMemory) } @@ -333,7 +333,7 @@ class DefaultAndroidEventProcessorTest { fun `Device's context is set on transactions`() { val sut = fixture.getSut(context) - assertNotNull(sut.process(SentryTransaction(fixture.sentryTracer), null)) { + assertNotNull(sut.process(SentryTransaction(fixture.sentryTracer), Hints())) { assertNotNull(it.contexts.device) } } @@ -342,7 +342,7 @@ class DefaultAndroidEventProcessorTest { fun `Device's OS is set on transactions`() { val sut = fixture.getSut(context) - assertNotNull(sut.process(SentryTransaction(fixture.sentryTracer), null)) { + assertNotNull(sut.process(SentryTransaction(fixture.sentryTracer), Hints())) { assertNotNull(it.contexts.operatingSystem) } } @@ -351,7 +351,7 @@ class DefaultAndroidEventProcessorTest { fun `Transaction do not set device's context that requires heavy work`() { val sut = fixture.getSut(context) - assertNotNull(sut.process(SentryTransaction(fixture.sentryTracer), null)) { + assertNotNull(sut.process(SentryTransaction(fixture.sentryTracer), Hints())) { val device = it.contexts.device!! assertNull(device.batteryLevel) assertNull(device.isCharging) @@ -371,7 +371,7 @@ class DefaultAndroidEventProcessorTest { fun `Event sets device's context that requires heavy work`() { val sut = fixture.getSut(context) - assertNotNull(sut.process(SentryEvent(), null)) { + assertNotNull(sut.process(SentryEvent(), Hints())) { val device = it.contexts.device!! assertNotNull(device.freeMemory) assertNotNull(device.isLowMemory) @@ -393,7 +393,7 @@ class DefaultAndroidEventProcessorTest { fun `Event sets language and locale`() { val sut = fixture.getSut(context) - assertNotNull(sut.process(SentryEvent(), null)) { + assertNotNull(sut.process(SentryEvent(), Hints())) { val device = it.contexts.device!! assertEquals("en", device.language) assertEquals("en_US", device.locale) diff --git a/sentry-android-core/src/test/java/io/sentry/android/core/EnvelopeFileObserverTest.kt b/sentry-android-core/src/test/java/io/sentry/android/core/EnvelopeFileObserverTest.kt index 6a71706d1c..43338b5f96 100644 --- a/sentry-android-core/src/test/java/io/sentry/android/core/EnvelopeFileObserverTest.kt +++ b/sentry-android-core/src/test/java/io/sentry/android/core/EnvelopeFileObserverTest.kt @@ -74,7 +74,7 @@ class EnvelopeFileObserverTest { verify(fixture.envelopeSender).processEnvelopeFile( eq(fixture.path + File.separator + fixture.fileName), - check { it is ApplyScopeData } + check { HintUtils.hasType(it, ApplyScopeData::class.java) } ) } @@ -84,7 +84,7 @@ class EnvelopeFileObserverTest { verify(fixture.envelopeSender).processEnvelopeFile( eq(fixture.path + File.separator + fixture.fileName), - check { it is Resettable } + check { HintUtils.hasType(it, Resettable::class.java) } ) } @@ -94,15 +94,14 @@ class EnvelopeFileObserverTest { verify(fixture.envelopeSender).processEnvelopeFile( eq(fixture.path + File.separator + fixture.fileName), - check { - val hint = HintUtils.getSentrySdkHint(it) - (hint as SubmissionResult).setResult(true) - (hint as Retryable).isRetry = true + check { hints -> + HintUtils.runIfHasType(hints, SubmissionResult::class.java) { it.setResult(true) } + HintUtils.runIfHasType(hints, Retryable::class.java) { it.isRetry = true } - (hint as Resettable).reset() + HintUtils.runIfHasType(hints, Resettable::class.java) { it.reset() } - assertFalse(hint.isRetry) - assertFalse(hint.isSuccess) + assertFalse((HintUtils.getSentrySdkHint(hints) as Retryable).isRetry) + assertFalse((HintUtils.getSentrySdkHint(hints) as SubmissionResult).isSuccess) } ) } diff --git a/sentry-android-core/src/test/java/io/sentry/android/core/PerformanceAndroidEventProcessorTest.kt b/sentry-android-core/src/test/java/io/sentry/android/core/PerformanceAndroidEventProcessorTest.kt index 47d561e5c1..fe1446cf95 100644 --- a/sentry-android-core/src/test/java/io/sentry/android/core/PerformanceAndroidEventProcessorTest.kt +++ b/sentry-android-core/src/test/java/io/sentry/android/core/PerformanceAndroidEventProcessorTest.kt @@ -7,6 +7,7 @@ import io.sentry.IHub import io.sentry.SentryTracer import io.sentry.TransactionContext import io.sentry.android.core.ActivityLifecycleIntegration.UI_LOAD_OP +import io.sentry.hints.Hints import io.sentry.protocol.MeasurementValue import io.sentry.protocol.SentryTransaction import java.util.Date @@ -45,7 +46,7 @@ class PerformanceAndroidEventProcessorTest { var tr = getTransaction() setAppStart() - tr = sut.process(tr, null) + tr = sut.process(tr, Hints()) assertTrue(tr.measurements.containsKey("app_start_cold")) } @@ -57,7 +58,7 @@ class PerformanceAndroidEventProcessorTest { var tr = getTransaction("app.start.warm") setAppStart(false) - tr = sut.process(tr, null) + tr = sut.process(tr, Hints()) assertTrue(tr.measurements.containsKey("app_start_warm")) } @@ -69,10 +70,10 @@ class PerformanceAndroidEventProcessorTest { var tr1 = getTransaction() setAppStart(false) - tr1 = sut.process(tr1, null) + tr1 = sut.process(tr1, Hints()) var tr2 = getTransaction() - tr2 = sut.process(tr2, null) + tr2 = sut.process(tr2, Hints()) assertTrue(tr1.measurements.containsKey("app_start_warm")) assertTrue(tr2.measurements.isEmpty()) @@ -84,7 +85,7 @@ class PerformanceAndroidEventProcessorTest { var tr = getTransaction() - tr = sut.process(tr, null) + tr = sut.process(tr, Hints()) assertTrue(tr.measurements.isEmpty()) } @@ -95,7 +96,7 @@ class PerformanceAndroidEventProcessorTest { var tr = getTransaction() - tr = sut.process(tr, null) + tr = sut.process(tr, Hints()) assertTrue(tr.measurements.isEmpty()) } @@ -106,7 +107,7 @@ class PerformanceAndroidEventProcessorTest { var tr = getTransaction("task") - tr = sut.process(tr, null) + tr = sut.process(tr, Hints()) assertTrue(tr.measurements.isEmpty()) } @@ -116,7 +117,7 @@ class PerformanceAndroidEventProcessorTest { val sut = fixture.getSut() var tr = getTransaction("task") - tr = sut.process(tr, null) + tr = sut.process(tr, Hints()) assertTrue(tr.measurements.isEmpty()) } @@ -126,7 +127,7 @@ class PerformanceAndroidEventProcessorTest { val sut = fixture.getSut(null) var tr = getTransaction("task") - tr = sut.process(tr, null) + tr = sut.process(tr, Hints()) assertTrue(tr.measurements.isEmpty()) } @@ -141,7 +142,7 @@ class PerformanceAndroidEventProcessorTest { val metrics = mapOf("frames_total" to MeasurementValue(1f)) whenever(fixture.activityFramesTracker.takeMetrics(any())).thenReturn(metrics) - tr = sut.process(tr, null) + tr = sut.process(tr, Hints()) assertTrue(tr.measurements.containsKey("frames_total")) } diff --git a/sentry-android-core/src/test/java/io/sentry/android/core/ScreenshotEventProcessorTest.kt b/sentry-android-core/src/test/java/io/sentry/android/core/ScreenshotEventProcessorTest.kt index 65566c1f46..2e8ef405e7 100644 --- a/sentry-android-core/src/test/java/io/sentry/android/core/ScreenshotEventProcessorTest.kt +++ b/sentry-android-core/src/test/java/io/sentry/android/core/ScreenshotEventProcessorTest.kt @@ -15,6 +15,7 @@ import io.sentry.MainEventProcessor import io.sentry.SentryEvent import io.sentry.TypeCheckHint.ANDROID_ACTIVITY import io.sentry.TypeCheckHint.SENTRY_SCREENSHOT +import io.sentry.hints.Hints import org.junit.runner.RunWith import kotlin.test.BeforeTest import kotlin.test.Test @@ -95,7 +96,7 @@ class ScreenshotEventProcessorTest { @Test fun `when process is called and attachScreenshot is disabled, does nothing`() { val sut = fixture.getSut(false) - val hints = mutableMapOf() + val hints = Hints() sut.onActivityCreated(fixture.activity, null) @@ -108,7 +109,7 @@ class ScreenshotEventProcessorTest { @Test fun `when event is not errored, does nothing`() { val sut = fixture.getSut(true) - val hints = mutableMapOf() + val hints = Hints() sut.onActivityCreated(fixture.activity, null) @@ -121,7 +122,7 @@ class ScreenshotEventProcessorTest { @Test fun `when there is not activity, does nothing`() { val sut = fixture.getSut(true) - val hints = mutableMapOf() + val hints = Hints() val event = fixture.mainProcessor.process(getEvent(), hints) sut.process(event, hints) @@ -132,7 +133,7 @@ class ScreenshotEventProcessorTest { @Test fun `when activity is finishing, does nothing`() { val sut = fixture.getSut(true) - val hints = mutableMapOf() + val hints = Hints() whenever(fixture.activity.isFinishing).thenReturn(true) sut.onActivityCreated(fixture.activity, null) @@ -146,7 +147,7 @@ class ScreenshotEventProcessorTest { @Test fun `when view is zeroed, does nothing`() { val sut = fixture.getSut(true) - val hints = mutableMapOf() + val hints = Hints() whenever(fixture.rootView.width).thenReturn(0) whenever(fixture.rootView.height).thenReturn(0) @@ -161,7 +162,7 @@ class ScreenshotEventProcessorTest { @Test fun `when process is called and attachScreenshot is enabled, add attachment to hints`() { val sut = fixture.getSut(true) - val hints = mutableMapOf() + val hints = Hints() sut.onActivityCreated(fixture.activity, null) @@ -179,7 +180,7 @@ class ScreenshotEventProcessorTest { @Test fun `when activity is destroyed, does nothing`() { val sut = fixture.getSut(true) - val hints = mutableMapOf() + val hints = Hints() sut.onActivityCreated(fixture.activity, null) sut.onActivityDestroyed(fixture.activity) diff --git a/sentry-android-fragment/src/main/java/io/sentry/android/fragment/SentryFragmentLifecycleCallbacks.kt b/sentry-android-fragment/src/main/java/io/sentry/android/fragment/SentryFragmentLifecycleCallbacks.kt index 6db16485eb..d66036f366 100644 --- a/sentry-android-fragment/src/main/java/io/sentry/android/fragment/SentryFragmentLifecycleCallbacks.kt +++ b/sentry-android-fragment/src/main/java/io/sentry/android/fragment/SentryFragmentLifecycleCallbacks.kt @@ -13,6 +13,7 @@ import io.sentry.ISpan import io.sentry.SentryLevel.INFO import io.sentry.SpanStatus import io.sentry.TypeCheckHint.ANDROID_FRAGMENT +import io.sentry.hints.Hints import java.util.WeakHashMap @Suppress("TooManyFunctions") @@ -118,9 +119,9 @@ class SentryFragmentLifecycleCallbacks( level = INFO } - val hintsMap = mutableMapOf(ANDROID_FRAGMENT to fragment) + val hints = Hints().also { it.set(ANDROID_FRAGMENT, fragment) } - hub.addBreadcrumb(breadcrumb, hintsMap) + hub.addBreadcrumb(breadcrumb, hints) } private fun getFragmentName(fragment: Fragment): String { diff --git a/sentry-android-okhttp/src/main/java/io/sentry/android/okhttp/SentryOkHttpInterceptor.kt b/sentry-android-okhttp/src/main/java/io/sentry/android/okhttp/SentryOkHttpInterceptor.kt index 761a0104c5..b50f2c8381 100644 --- a/sentry-android-okhttp/src/main/java/io/sentry/android/okhttp/SentryOkHttpInterceptor.kt +++ b/sentry-android-okhttp/src/main/java/io/sentry/android/okhttp/SentryOkHttpInterceptor.kt @@ -8,6 +8,7 @@ import io.sentry.SpanStatus import io.sentry.TracingOrigins import io.sentry.TypeCheckHint.OKHTTP_REQUEST import io.sentry.TypeCheckHint.OKHTTP_RESPONSE +import io.sentry.hints.Hints import okhttp3.Interceptor import okhttp3.Request import okhttp3.Response @@ -62,16 +63,16 @@ class SentryOkHttpInterceptor( breadcrumb.setData("request_body_size", it) } - val hintsMap = mutableMapOf(OKHTTP_REQUEST to request) + val hints = Hints().also { it.set(OKHTTP_REQUEST, request) } response?.let { it.body?.contentLength().ifHasValidLength { responseBodySize -> breadcrumb.setData("response_body_size", responseBodySize) } - hintsMap[OKHTTP_RESPONSE] = it + hints[OKHTTP_RESPONSE] = it } - hub.addBreadcrumb(breadcrumb, hintsMap) + hub.addBreadcrumb(breadcrumb, hints) } } diff --git a/sentry-apache-http-client-5/api/sentry-apache-http-client-5.api b/sentry-apache-http-client-5/api/sentry-apache-http-client-5.api index 8c27b45c82..df1a42131e 100644 --- a/sentry-apache-http-client-5/api/sentry-apache-http-client-5.api +++ b/sentry-apache-http-client-5/api/sentry-apache-http-client-5.api @@ -2,7 +2,7 @@ public final class io/sentry/transport/apache/ApacheHttpClientTransport : io/sen public fun (Lio/sentry/SentryOptions;Lio/sentry/RequestDetails;Lorg/apache/hc/client5/http/impl/async/CloseableHttpAsyncClient;Lio/sentry/transport/RateLimiter;)V public fun close ()V public fun flush (J)V - public fun send (Lio/sentry/SentryEnvelope;Ljava/util/Map;)V + public fun send (Lio/sentry/SentryEnvelope;Lio/sentry/hints/Hints;)V } public final class io/sentry/transport/apache/ApacheHttpClientTransportFactory : io/sentry/ITransportFactory { diff --git a/sentry-apache-http-client-5/src/main/java/io/sentry/transport/apache/ApacheHttpClientTransport.java b/sentry-apache-http-client-5/src/main/java/io/sentry/transport/apache/ApacheHttpClientTransport.java index 04d8eb22e8..36abe7769f 100644 --- a/sentry-apache-http-client-5/src/main/java/io/sentry/transport/apache/ApacheHttpClientTransport.java +++ b/sentry-apache-http-client-5/src/main/java/io/sentry/transport/apache/ApacheHttpClientTransport.java @@ -7,6 +7,7 @@ import io.sentry.SentryLevel; import io.sentry.SentryOptions; import io.sentry.clientreport.DiscardReason; +import io.sentry.hints.Hints; import io.sentry.hints.Retryable; import io.sentry.transport.ITransport; import io.sentry.transport.RateLimiter; @@ -28,7 +29,6 @@ import org.apache.hc.core5.io.CloseMode; import org.apache.hc.core5.util.TimeValue; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; /** * {@link ITransport} implementation that executes request asynchronously in a non-blocking manner @@ -66,11 +66,10 @@ public ApacheHttpClientTransport( @Override @SuppressWarnings("FutureReturnValueIgnored") - public void send(final @NotNull SentryEnvelope envelope, final @Nullable Map hint) + public void send(final @NotNull SentryEnvelope envelope, final @NotNull Hints hints) throws IOException { if (isSchedulingAllowed()) { - Object sentrySdkHint = HintUtils.getSentrySdkHint(hint); - final SentryEnvelope filteredEnvelope = rateLimiter.filter(envelope, sentrySdkHint); + final SentryEnvelope filteredEnvelope = rateLimiter.filter(envelope, hints); if (filteredEnvelope != null) { final SentryEnvelope envelopeWithClientReport = @@ -111,7 +110,7 @@ public void completed(SimpleHttpResponse response) { .log(ERROR, "Request failed, API returned %s", response.getCode()); if (response.getCode() >= 400 && response.getCode() != 429) { - if (!(sentrySdkHint instanceof Retryable)) { + if (!HintUtils.hasType(hints, Retryable.class)) { options .getClientReportRecorder() .recordLostEnvelope( @@ -133,7 +132,7 @@ public void completed(SimpleHttpResponse response) { @Override public void failed(Exception ex) { options.getLogger().log(ERROR, "Error while sending an envelope", ex); - if (!(sentrySdkHint instanceof Retryable)) { + if (!HintUtils.hasType(hints, Retryable.class)) { options .getClientReportRecorder() .recordLostEnvelope( @@ -145,7 +144,7 @@ public void failed(Exception ex) { @Override public void cancelled() { options.getLogger().log(WARNING, "Request cancelled"); - if (!(sentrySdkHint instanceof Retryable)) { + if (!HintUtils.hasType(hints, Retryable.class)) { options .getClientReportRecorder() .recordLostEnvelope( @@ -156,7 +155,7 @@ public void cancelled() { }); } catch (Throwable e) { options.getLogger().log(ERROR, "Error when sending envelope", e); - if (!(sentrySdkHint instanceof Retryable)) { + if (!HintUtils.hasType(hints, Retryable.class)) { options .getClientReportRecorder() .recordLostEnvelope(DiscardReason.NETWORK_ERROR, envelopeWithClientReport); diff --git a/sentry-apache-http-client-5/src/test/kotlin/io/sentry/transport/apache/ApacheHttpClientTransportClientReportTest.kt b/sentry-apache-http-client-5/src/test/kotlin/io/sentry/transport/apache/ApacheHttpClientTransportClientReportTest.kt index 8fc1b6de8b..2dc23399ea 100644 --- a/sentry-apache-http-client-5/src/test/kotlin/io/sentry/transport/apache/ApacheHttpClientTransportClientReportTest.kt +++ b/sentry-apache-http-client-5/src/test/kotlin/io/sentry/transport/apache/ApacheHttpClientTransportClientReportTest.kt @@ -18,12 +18,12 @@ import io.sentry.SentryEvent import io.sentry.SentryLevel import io.sentry.SentryOptions import io.sentry.SentryOptionsManipulator -import io.sentry.TypeCheckHint import io.sentry.clientreport.DiscardReason import io.sentry.clientreport.IClientReportRecorder import io.sentry.hints.Retryable import io.sentry.transport.RateLimiter import io.sentry.transport.ReusableCountLatch +import io.sentry.util.HintUtils import org.apache.hc.client5.http.async.methods.SimpleHttpResponse import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient import org.apache.hc.core5.concurrent.FutureCallback @@ -209,7 +209,7 @@ class ApacheHttpClientTransportClientReportTest { verifyNoMoreInteractions(fixture.clientReportRecorder) } - private fun retryableHint() = mutableMapOf(TypeCheckHint.SENTRY_TYPE_CHECK_HINT to TestRetryable()) + private fun retryableHint() = HintUtils.createWithTypeCheckHint(TestRetryable()) } class TestRetryable : Retryable { diff --git a/sentry-apollo/src/main/java/io/sentry/apollo/SentryApolloInterceptor.kt b/sentry-apollo/src/main/java/io/sentry/apollo/SentryApolloInterceptor.kt index d0f53c6291..aa17e8b06b 100644 --- a/sentry-apollo/src/main/java/io/sentry/apollo/SentryApolloInterceptor.kt +++ b/sentry-apollo/src/main/java/io/sentry/apollo/SentryApolloInterceptor.kt @@ -19,6 +19,7 @@ import io.sentry.SentryLevel import io.sentry.SpanStatus import io.sentry.TypeCheckHint.APOLLO_REQUEST import io.sentry.TypeCheckHint.APOLLO_RESPONSE +import io.sentry.hints.Hints import java.util.concurrent.Executor class SentryApolloInterceptor( @@ -115,8 +116,11 @@ class SentryApolloInterceptor( breadcrumb.setData("response_body_size", contentLength) } - val hintsMap = mutableMapOf(APOLLO_REQUEST to httpRequest, APOLLO_RESPONSE to httpResponse) - hub.addBreadcrumb(breadcrumb, hintsMap) + val hints = Hints().also { + it.set(APOLLO_REQUEST, httpRequest) + it.set(APOLLO_RESPONSE, httpResponse) + } + hub.addBreadcrumb(breadcrumb, hints) } } } diff --git a/sentry-graphql/src/main/java/io/sentry/graphql/SentryDataFetcherExceptionHandler.java b/sentry-graphql/src/main/java/io/sentry/graphql/SentryDataFetcherExceptionHandler.java index d0f64a1442..d64cc9719f 100644 --- a/sentry-graphql/src/main/java/io/sentry/graphql/SentryDataFetcherExceptionHandler.java +++ b/sentry-graphql/src/main/java/io/sentry/graphql/SentryDataFetcherExceptionHandler.java @@ -7,9 +7,8 @@ import graphql.execution.DataFetcherExceptionHandlerResult; import io.sentry.HubAdapter; import io.sentry.IHub; +import io.sentry.hints.Hints; import io.sentry.util.Objects; -import java.util.HashMap; -import java.util.Map; import org.jetbrains.annotations.NotNull; /** @@ -34,10 +33,10 @@ public SentryDataFetcherExceptionHandler(final @NotNull DataFetcherExceptionHand @SuppressWarnings("deprecation") public DataFetcherExceptionHandlerResult onException( final @NotNull DataFetcherExceptionHandlerParameters handlerParameters) { - final Map hintMap = new HashMap<>(); - hintMap.put(GRAPHQL_HANDLER_PARAMETERS, handlerParameters); + final Hints hints = new Hints(); + hints.set(GRAPHQL_HANDLER_PARAMETERS, handlerParameters); - hub.captureException(handlerParameters.getException(), hintMap); + hub.captureException(handlerParameters.getException(), hints); return delegate.onException(handlerParameters); } } diff --git a/sentry-jul/src/main/java/io/sentry/jul/SentryHandler.java b/sentry-jul/src/main/java/io/sentry/jul/SentryHandler.java index b1b2be0dba..40ecee562e 100644 --- a/sentry-jul/src/main/java/io/sentry/jul/SentryHandler.java +++ b/sentry-jul/src/main/java/io/sentry/jul/SentryHandler.java @@ -9,13 +9,13 @@ import io.sentry.SentryEvent; import io.sentry.SentryLevel; import io.sentry.SentryOptions; +import io.sentry.hints.Hints; import io.sentry.protocol.Message; import io.sentry.protocol.SdkVersion; import io.sentry.util.CollectionUtils; import java.text.MessageFormat; import java.util.ArrayList; import java.util.Date; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.logging.ErrorManager; @@ -81,16 +81,16 @@ public void publish(final @NotNull LogRecord record) { } try { if (record.getLevel().intValue() >= minimumEventLevel.intValue()) { - final Map hintMap = new HashMap<>(); - hintMap.put(SENTRY_SYNTHETIC_EXCEPTION, record); + final Hints hints = new Hints(); + hints.set(SENTRY_SYNTHETIC_EXCEPTION, record); - Sentry.captureEvent(createEvent(record), hintMap); + Sentry.captureEvent(createEvent(record), hints); } if (record.getLevel().intValue() >= minimumBreadcrumbLevel.intValue()) { - final Map hintMap = new HashMap<>(); - hintMap.put(JUL_LOG_RECORD, record); + final Hints hints = new Hints(); + hints.set(JUL_LOG_RECORD, record); - Sentry.addBreadcrumb(createBreadcrumb(record), hintMap); + Sentry.addBreadcrumb(createBreadcrumb(record), hints); } } catch (RuntimeException e) { reportError( diff --git a/sentry-log4j2/src/main/java/io/sentry/log4j2/SentryAppender.java b/sentry-log4j2/src/main/java/io/sentry/log4j2/SentryAppender.java index 9d04b401ce..bb95d19531 100644 --- a/sentry-log4j2/src/main/java/io/sentry/log4j2/SentryAppender.java +++ b/sentry-log4j2/src/main/java/io/sentry/log4j2/SentryAppender.java @@ -13,12 +13,12 @@ import io.sentry.SentryEvent; import io.sentry.SentryLevel; import io.sentry.SentryOptions; +import io.sentry.hints.Hints; import io.sentry.protocol.Message; import io.sentry.protocol.SdkVersion; import io.sentry.util.CollectionUtils; import java.util.Arrays; import java.util.Collections; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; @@ -139,16 +139,16 @@ public void start() { @Override public void append(final @NotNull LogEvent eventObject) { if (eventObject.getLevel().isMoreSpecificThan(minimumEventLevel)) { - final Map hintMap = new HashMap<>(); - hintMap.put(SENTRY_SYNTHETIC_EXCEPTION, eventObject); + final Hints hints = new Hints(); + hints.set(SENTRY_SYNTHETIC_EXCEPTION, eventObject); - hub.captureEvent(createEvent(eventObject), hintMap); + hub.captureEvent(createEvent(eventObject), hints); } if (eventObject.getLevel().isMoreSpecificThan(minimumBreadcrumbLevel)) { - final Map hintMap = new HashMap<>(); - hintMap.put(LOG4J_LOG_EVENT, eventObject); + final Hints hints = new Hints(); + hints.set(LOG4J_LOG_EVENT, eventObject); - hub.addBreadcrumb(createBreadcrumb(eventObject), hintMap); + hub.addBreadcrumb(createBreadcrumb(eventObject), hints); } } diff --git a/sentry-logback/src/main/java/io/sentry/logback/SentryAppender.java b/sentry-logback/src/main/java/io/sentry/logback/SentryAppender.java index b6cf879620..87fc1f91d7 100644 --- a/sentry-logback/src/main/java/io/sentry/logback/SentryAppender.java +++ b/sentry-logback/src/main/java/io/sentry/logback/SentryAppender.java @@ -15,12 +15,12 @@ import io.sentry.SentryEvent; import io.sentry.SentryLevel; import io.sentry.SentryOptions; +import io.sentry.hints.Hints; import io.sentry.protocol.Message; import io.sentry.protocol.SdkVersion; import io.sentry.util.CollectionUtils; import java.util.Arrays; import java.util.Collections; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; @@ -63,16 +63,16 @@ public void start() { @Override protected void append(@NotNull ILoggingEvent eventObject) { if (eventObject.getLevel().isGreaterOrEqual(minimumEventLevel)) { - final Map hintMap = new HashMap<>(); - hintMap.put(SENTRY_SYNTHETIC_EXCEPTION, eventObject); + final Hints hints = new Hints(); + hints.set(SENTRY_SYNTHETIC_EXCEPTION, eventObject); - Sentry.captureEvent(createEvent(eventObject), hintMap); + Sentry.captureEvent(createEvent(eventObject), hints); } if (eventObject.getLevel().isGreaterOrEqual(minimumBreadcrumbLevel)) { - final Map hintMap = new HashMap<>(); - hintMap.put(LOGBACK_LOGGING_EVENT, eventObject); + final Hints hints = new Hints(); + hints.set(LOGBACK_LOGGING_EVENT, eventObject); - Sentry.addBreadcrumb(createBreadcrumb(eventObject), hintMap); + Sentry.addBreadcrumb(createBreadcrumb(eventObject), hints); } } diff --git a/sentry-openfeign/src/main/java/io/sentry/openfeign/SentryFeignClient.java b/sentry-openfeign/src/main/java/io/sentry/openfeign/SentryFeignClient.java index 121ac287e0..4d89a4ebce 100644 --- a/sentry-openfeign/src/main/java/io/sentry/openfeign/SentryFeignClient.java +++ b/sentry-openfeign/src/main/java/io/sentry/openfeign/SentryFeignClient.java @@ -11,11 +11,11 @@ import io.sentry.ISpan; import io.sentry.SentryTraceHeader; import io.sentry.SpanStatus; +import io.sentry.hints.Hints; import io.sentry.util.Objects; import java.io.IOException; import java.util.Collection; import java.util.Collections; -import java.util.HashMap; import java.util.LinkedHashMap; import java.util.Map; import org.jetbrains.annotations.NotNull; @@ -92,13 +92,13 @@ private void addBreadcrumb(final @NotNull Request request, final @Nullable Respo breadcrumb.setData("response_body_size", response.body().length()); } - final Map hintMap = new HashMap<>(); - hintMap.put(OPEN_FEIGN_REQUEST, request); + final Hints hints = new Hints(); + hints.set(OPEN_FEIGN_REQUEST, request); if (response != null) { - hintMap.put(OPEN_FEIGN_RESPONSE, response); + hints.set(OPEN_FEIGN_RESPONSE, response); } - hub.addBreadcrumb(breadcrumb, hintMap); + hub.addBreadcrumb(breadcrumb, hints); } static final class RequestWrapper { diff --git a/sentry-samples/sentry-samples-console/src/main/java/io/sentry/samples/console/Main.java b/sentry-samples/sentry-samples-console/src/main/java/io/sentry/samples/console/Main.java index 0d963e0f9b..3b922df84c 100644 --- a/sentry-samples/sentry-samples-console/src/main/java/io/sentry/samples/console/Main.java +++ b/sentry-samples/sentry-samples-console/src/main/java/io/sentry/samples/console/Main.java @@ -8,11 +8,10 @@ import io.sentry.SentryEvent; import io.sentry.SentryLevel; import io.sentry.SpanStatus; +import io.sentry.hints.Hints; import io.sentry.protocol.Message; import io.sentry.protocol.User; import java.util.Collections; -import java.util.HashMap; -import java.util.Map; public class Main { @@ -137,9 +136,9 @@ public static void main(String[] args) throws InterruptedException { SentryEvent event = new SentryEvent(); event.setMessage(message); - final Map hintsMap = new HashMap<>(); - hintsMap.put("level", SentryLevel.DEBUG); - Sentry.captureEvent(event, hintsMap); + final Hints hints = new Hints(); + hints.set("level", SentryLevel.DEBUG); + Sentry.captureEvent(event, hints); } // Performance feature @@ -171,7 +170,7 @@ public static void main(String[] args) throws InterruptedException { private static class SomeEventProcessor implements EventProcessor { @Override - public SentryEvent process(SentryEvent event, Map hint) { + public SentryEvent process(SentryEvent event, Hints hints) { // Here you can modify the event as you need if (event.getLevel() != null && event.getLevel().ordinal() > SentryLevel.INFO.ordinal()) { event.addBreadcrumb(new Breadcrumb("Processed by " + SomeEventProcessor.class)); diff --git a/sentry-samples/sentry-samples-spring-boot/src/main/java/io/sentry/samples/spring/boot/CustomEventProcessor.java b/sentry-samples/sentry-samples-spring-boot/src/main/java/io/sentry/samples/spring/boot/CustomEventProcessor.java index c21763cc00..00e90d0002 100644 --- a/sentry-samples/sentry-samples-spring-boot/src/main/java/io/sentry/samples/spring/boot/CustomEventProcessor.java +++ b/sentry-samples/sentry-samples-spring-boot/src/main/java/io/sentry/samples/spring/boot/CustomEventProcessor.java @@ -2,10 +2,9 @@ import io.sentry.EventProcessor; import io.sentry.SentryEvent; +import io.sentry.hints.Hints; import io.sentry.protocol.SentryRuntime; -import java.util.Map; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import org.springframework.boot.SpringBootVersion; import org.springframework.stereotype.Component; @@ -26,8 +25,7 @@ public CustomEventProcessor() { } @Override - public @NotNull SentryEvent process( - @NotNull SentryEvent event, @Nullable Map hint) { + public @NotNull SentryEvent process(@NotNull SentryEvent event, @NotNull Hints hints) { final SentryRuntime runtime = new SentryRuntime(); runtime.setVersion(springBootVersion); runtime.setName("Spring Boot"); diff --git a/sentry-servlet-jakarta/src/main/java/io/sentry/servlet/jakarta/SentryRequestHttpServletRequestProcessor.java b/sentry-servlet-jakarta/src/main/java/io/sentry/servlet/jakarta/SentryRequestHttpServletRequestProcessor.java index bebfc36412..1310576026 100644 --- a/sentry-servlet-jakarta/src/main/java/io/sentry/servlet/jakarta/SentryRequestHttpServletRequestProcessor.java +++ b/sentry-servlet-jakarta/src/main/java/io/sentry/servlet/jakarta/SentryRequestHttpServletRequestProcessor.java @@ -2,6 +2,7 @@ import io.sentry.EventProcessor; import io.sentry.SentryEvent; +import io.sentry.hints.Hints; import io.sentry.protocol.Request; import io.sentry.util.Objects; import jakarta.servlet.http.HttpServletRequest; @@ -29,8 +30,7 @@ public SentryRequestHttpServletRequestProcessor(@NotNull HttpServletRequest http // httpRequest.getRequestURL() returns StringBuffer which is considered an obsolete class. @SuppressWarnings("JdkObsolete") @Override - public @NotNull SentryEvent process( - @NotNull SentryEvent event, @Nullable Map hint) { + public @NotNull SentryEvent process(@NotNull SentryEvent event, @NotNull Hints hints) { final Request sentryRequest = new Request(); sentryRequest.setMethod(httpRequest.getMethod()); sentryRequest.setQueryString(httpRequest.getQueryString()); diff --git a/sentry-servlet-jakarta/src/main/java/io/sentry/servlet/jakarta/SentryServletRequestListener.java b/sentry-servlet-jakarta/src/main/java/io/sentry/servlet/jakarta/SentryServletRequestListener.java index fc7f516a44..416b984450 100644 --- a/sentry-servlet-jakarta/src/main/java/io/sentry/servlet/jakarta/SentryServletRequestListener.java +++ b/sentry-servlet-jakarta/src/main/java/io/sentry/servlet/jakarta/SentryServletRequestListener.java @@ -6,13 +6,12 @@ import io.sentry.Breadcrumb; import io.sentry.HubAdapter; import io.sentry.IHub; +import io.sentry.hints.Hints; import io.sentry.util.Objects; import jakarta.servlet.ServletRequest; import jakarta.servlet.ServletRequestEvent; import jakarta.servlet.ServletRequestListener; import jakarta.servlet.http.HttpServletRequest; -import java.util.HashMap; -import java.util.Map; import org.jetbrains.annotations.NotNull; /** @@ -45,11 +44,11 @@ public void requestInitialized(@NotNull ServletRequestEvent servletRequestEvent) if (servletRequest instanceof HttpServletRequest) { final HttpServletRequest httpRequest = (HttpServletRequest) servletRequest; - final Map hintMap = new HashMap<>(); - hintMap.put(SERVLET_REQUEST, httpRequest); + final Hints hints = new Hints(); + hints.set(SERVLET_REQUEST, httpRequest); hub.addBreadcrumb( - Breadcrumb.http(httpRequest.getRequestURI(), httpRequest.getMethod()), hintMap); + Breadcrumb.http(httpRequest.getRequestURI(), httpRequest.getMethod()), hints); hub.configureScope( scope -> { diff --git a/sentry-servlet-jakarta/src/test/kotlin/io/sentry/servlet/jakarta/SentryRequestHttpServletRequestProcessorTest.kt b/sentry-servlet-jakarta/src/test/kotlin/io/sentry/servlet/jakarta/SentryRequestHttpServletRequestProcessorTest.kt index 20b47ae0fb..9668a93af7 100644 --- a/sentry-servlet-jakarta/src/test/kotlin/io/sentry/servlet/jakarta/SentryRequestHttpServletRequestProcessorTest.kt +++ b/sentry-servlet-jakarta/src/test/kotlin/io/sentry/servlet/jakarta/SentryRequestHttpServletRequestProcessorTest.kt @@ -5,6 +5,7 @@ import com.nhaarman.mockitokotlin2.mock import com.nhaarman.mockitokotlin2.whenever import io.sentry.SentryEvent import io.sentry.SentryOptions +import io.sentry.hints.Hints import jakarta.servlet.http.HttpServletRequest import java.net.URI import java.util.Collections @@ -29,7 +30,7 @@ class SentryRequestHttpServletRequestProcessorTest { val eventProcessor = SentryRequestHttpServletRequestProcessor(request) val event = SentryEvent() - eventProcessor.process(event, null) + eventProcessor.process(event, Hints()) assertNotNull(event.request) val eventRequest = event.request!! @@ -56,7 +57,7 @@ class SentryRequestHttpServletRequestProcessorTest { val eventProcessor = SentryRequestHttpServletRequestProcessor(request) val event = SentryEvent() - eventProcessor.process(event, null) + eventProcessor.process(event, Hints()) assertNotNull(event.request) { assertEquals( @@ -81,7 +82,7 @@ class SentryRequestHttpServletRequestProcessorTest { val eventProcessor = SentryRequestHttpServletRequestProcessor(request) val event = SentryEvent() - eventProcessor.process(event, null) + eventProcessor.process(event, Hints()) assertNotNull(event.request) { assertNull(it.cookies) @@ -105,7 +106,7 @@ class SentryRequestHttpServletRequestProcessorTest { val eventProcessor = SentryRequestHttpServletRequestProcessor(request) val event = SentryEvent() - eventProcessor.process(event, null) + eventProcessor.process(event, Hints()) assertNotNull(event.request) { req -> assertNotNull(req.headers) { diff --git a/sentry-servlet/src/main/java/io/sentry/servlet/SentryRequestHttpServletRequestProcessor.java b/sentry-servlet/src/main/java/io/sentry/servlet/SentryRequestHttpServletRequestProcessor.java index 5b6c53c464..0ff80fb335 100644 --- a/sentry-servlet/src/main/java/io/sentry/servlet/SentryRequestHttpServletRequestProcessor.java +++ b/sentry-servlet/src/main/java/io/sentry/servlet/SentryRequestHttpServletRequestProcessor.java @@ -2,6 +2,7 @@ import io.sentry.EventProcessor; import io.sentry.SentryEvent; +import io.sentry.hints.Hints; import io.sentry.protocol.Request; import io.sentry.util.Objects; import java.util.Arrays; @@ -29,8 +30,7 @@ public SentryRequestHttpServletRequestProcessor(@NotNull HttpServletRequest http // httpRequest.getRequestURL() returns StringBuffer which is considered an obsolete class. @SuppressWarnings("JdkObsolete") @Override - public @NotNull SentryEvent process( - @NotNull SentryEvent event, @Nullable Map hint) { + public @NotNull SentryEvent process(@NotNull SentryEvent event, @NotNull Hints hints) { final Request sentryRequest = new Request(); sentryRequest.setMethod(httpRequest.getMethod()); sentryRequest.setQueryString(httpRequest.getQueryString()); diff --git a/sentry-servlet/src/main/java/io/sentry/servlet/SentryServletRequestListener.java b/sentry-servlet/src/main/java/io/sentry/servlet/SentryServletRequestListener.java index 2050b78e14..544ec8e68f 100644 --- a/sentry-servlet/src/main/java/io/sentry/servlet/SentryServletRequestListener.java +++ b/sentry-servlet/src/main/java/io/sentry/servlet/SentryServletRequestListener.java @@ -6,9 +6,8 @@ import io.sentry.Breadcrumb; import io.sentry.HubAdapter; import io.sentry.IHub; +import io.sentry.hints.Hints; import io.sentry.util.Objects; -import java.util.HashMap; -import java.util.Map; import javax.servlet.ServletRequest; import javax.servlet.ServletRequestEvent; import javax.servlet.ServletRequestListener; @@ -45,11 +44,11 @@ public void requestInitialized(@NotNull ServletRequestEvent servletRequestEvent) if (servletRequest instanceof HttpServletRequest) { final HttpServletRequest httpRequest = (HttpServletRequest) servletRequest; - final Map hintMap = new HashMap<>(); - hintMap.put(SERVLET_REQUEST, httpRequest); + final Hints hints = new Hints(); + hints.set(SERVLET_REQUEST, httpRequest); hub.addBreadcrumb( - Breadcrumb.http(httpRequest.getRequestURI(), httpRequest.getMethod()), hintMap); + Breadcrumb.http(httpRequest.getRequestURI(), httpRequest.getMethod()), hints); hub.configureScope( scope -> { diff --git a/sentry-servlet/src/test/kotlin/io/sentry/servlet/SentryRequestHttpServletRequestProcessorTest.kt b/sentry-servlet/src/test/kotlin/io/sentry/servlet/SentryRequestHttpServletRequestProcessorTest.kt index c4a1f568f3..7ec61b7ca2 100644 --- a/sentry-servlet/src/test/kotlin/io/sentry/servlet/SentryRequestHttpServletRequestProcessorTest.kt +++ b/sentry-servlet/src/test/kotlin/io/sentry/servlet/SentryRequestHttpServletRequestProcessorTest.kt @@ -2,6 +2,7 @@ package io.sentry.servlet import io.sentry.SentryEvent import io.sentry.SentryOptions +import io.sentry.hints.Hints import org.springframework.mock.web.MockServletContext import org.springframework.test.web.servlet.request.MockMvcRequestBuilders import java.net.URI @@ -24,7 +25,7 @@ class SentryRequestHttpServletRequestProcessorTest { val eventProcessor = SentryRequestHttpServletRequestProcessor(request) val event = SentryEvent() - eventProcessor.process(event, null) + eventProcessor.process(event, Hints()) assertNotNull(event.request) val eventRequest = event.request!! @@ -50,7 +51,7 @@ class SentryRequestHttpServletRequestProcessorTest { val eventProcessor = SentryRequestHttpServletRequestProcessor(request) val event = SentryEvent() - eventProcessor.process(event, null) + eventProcessor.process(event, Hints()) assertNotNull(event.request) { assertEquals( @@ -73,7 +74,7 @@ class SentryRequestHttpServletRequestProcessorTest { val eventProcessor = SentryRequestHttpServletRequestProcessor(request) val event = SentryEvent() - eventProcessor.process(event, null) + eventProcessor.process(event, Hints()) assertNotNull(event.request) { assertNull(it.cookies) @@ -95,7 +96,7 @@ class SentryRequestHttpServletRequestProcessorTest { val eventProcessor = SentryRequestHttpServletRequestProcessor(request) val event = SentryEvent() - eventProcessor.process(event, null) + eventProcessor.process(event, Hints()) assertNotNull(event.request) { req -> assertNotNull(req.headers) { diff --git a/sentry-spring-boot-starter/src/test/kotlin/io/sentry/spring/boot/SentryAutoConfigurationTest.kt b/sentry-spring-boot-starter/src/test/kotlin/io/sentry/spring/boot/SentryAutoConfigurationTest.kt index 00a7135a7f..94c317cef4 100644 --- a/sentry-spring-boot-starter/src/test/kotlin/io/sentry/spring/boot/SentryAutoConfigurationTest.kt +++ b/sentry-spring-boot-starter/src/test/kotlin/io/sentry/spring/boot/SentryAutoConfigurationTest.kt @@ -19,6 +19,7 @@ import io.sentry.SentryEvent import io.sentry.SentryLevel import io.sentry.SentryOptions import io.sentry.checkEvent +import io.sentry.hints.Hints import io.sentry.protocol.User import io.sentry.spring.HttpServletRequestSentryUserProvider import io.sentry.spring.SentryExceptionResolver @@ -661,7 +662,7 @@ class SentryAutoConfigurationTest { } class CustomBeforeSendCallback : SentryOptions.BeforeSendCallback { - override fun execute(event: SentryEvent, hint: Map?): SentryEvent? = null + override fun execute(event: SentryEvent, hints: Hints): SentryEvent? = null } @Configuration(proxyBeanMethods = false) @@ -672,7 +673,7 @@ class SentryAutoConfigurationTest { } class CustomBeforeBreadcrumbCallback : SentryOptions.BeforeBreadcrumbCallback { - override fun execute(breadcrumb: Breadcrumb, hint: Map?): Breadcrumb? = null + override fun execute(breadcrumb: Breadcrumb, hints: Hints): Breadcrumb? = null } @Configuration(proxyBeanMethods = false) @@ -683,7 +684,7 @@ class SentryAutoConfigurationTest { } class CustomEventProcessor : EventProcessor { - override fun process(event: SentryEvent, hint: Map?) = null + override fun process(event: SentryEvent, hints: Hints) = null } @Configuration(proxyBeanMethods = false) diff --git a/sentry-spring/api/sentry-spring.api b/sentry-spring/api/sentry-spring.api index dfe84709bc..b461ee70f3 100644 --- a/sentry-spring/api/sentry-spring.api +++ b/sentry-spring/api/sentry-spring.api @@ -36,7 +36,7 @@ public class io/sentry/spring/SentryInitBeanPostProcessor : org/springframework/ public class io/sentry/spring/SentryRequestHttpServletRequestProcessor : io/sentry/EventProcessor { public fun (Lio/sentry/spring/tracing/TransactionNameProvider;Ljavax/servlet/http/HttpServletRequest;)V - public fun process (Lio/sentry/SentryEvent;Ljava/util/Map;)Lio/sentry/SentryEvent; + public fun process (Lio/sentry/SentryEvent;Lio/sentry/hints/Hints;)Lio/sentry/SentryEvent; } public class io/sentry/spring/SentryRequestResolver { diff --git a/sentry-spring/src/main/java/io/sentry/spring/SentryExceptionResolver.java b/sentry-spring/src/main/java/io/sentry/spring/SentryExceptionResolver.java index 1c8cc9d241..5db04fa335 100644 --- a/sentry-spring/src/main/java/io/sentry/spring/SentryExceptionResolver.java +++ b/sentry-spring/src/main/java/io/sentry/spring/SentryExceptionResolver.java @@ -8,11 +8,10 @@ import io.sentry.SentryEvent; import io.sentry.SentryLevel; import io.sentry.exception.ExceptionMechanismException; +import io.sentry.hints.Hints; import io.sentry.protocol.Mechanism; import io.sentry.spring.tracing.TransactionNameProvider; import io.sentry.util.Objects; -import java.util.HashMap; -import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.jetbrains.annotations.NotNull; @@ -60,11 +59,11 @@ public SentryExceptionResolver( event.setLevel(SentryLevel.FATAL); event.setTransaction(transactionNameProvider.provideTransactionName(request)); - final Map hintMap = new HashMap<>(); - hintMap.put(SPRING_RESOLVER_REQUEST, request); - hintMap.put(SPRING_RESOLVER_RESPONSE, response); + final Hints hints = new Hints(); + hints.set(SPRING_RESOLVER_REQUEST, request); + hints.set(SPRING_RESOLVER_RESPONSE, response); - hub.captureEvent(event, hintMap); + hub.captureEvent(event, hints); // null = run other HandlerExceptionResolvers to actually handle the exception return null; diff --git a/sentry-spring/src/main/java/io/sentry/spring/SentryRequestHttpServletRequestProcessor.java b/sentry-spring/src/main/java/io/sentry/spring/SentryRequestHttpServletRequestProcessor.java index 4d62dbd3ac..5c2b58fd70 100644 --- a/sentry-spring/src/main/java/io/sentry/spring/SentryRequestHttpServletRequestProcessor.java +++ b/sentry-spring/src/main/java/io/sentry/spring/SentryRequestHttpServletRequestProcessor.java @@ -3,12 +3,11 @@ import com.jakewharton.nopen.annotation.Open; import io.sentry.EventProcessor; import io.sentry.SentryEvent; +import io.sentry.hints.Hints; import io.sentry.spring.tracing.TransactionNameProvider; import io.sentry.util.Objects; -import java.util.Map; import javax.servlet.http.HttpServletRequest; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; /** Attaches transaction name from the HTTP request to {@link SentryEvent}. */ @Open @@ -26,7 +25,7 @@ public SentryRequestHttpServletRequestProcessor( @Override public @NotNull SentryEvent process( - final @NotNull SentryEvent event, final @Nullable Map hint) { + final @NotNull SentryEvent event, final @NotNull Hints hints) { if (event.getTransaction() == null) { event.setTransaction(transactionNameProvider.provideTransactionName(request)); } diff --git a/sentry-spring/src/main/java/io/sentry/spring/SentrySpringFilter.java b/sentry-spring/src/main/java/io/sentry/spring/SentrySpringFilter.java index a33d2103d0..a0b45614a6 100644 --- a/sentry-spring/src/main/java/io/sentry/spring/SentrySpringFilter.java +++ b/sentry-spring/src/main/java/io/sentry/spring/SentrySpringFilter.java @@ -13,18 +13,16 @@ import io.sentry.SentryLevel; import io.sentry.SentryOptions; import io.sentry.SentryOptions.RequestSize; +import io.sentry.hints.Hints; import io.sentry.spring.tracing.SpringMvcTransactionNameProvider; import io.sentry.spring.tracing.TransactionNameProvider; import io.sentry.util.Objects; import java.io.IOException; -import java.util.HashMap; -import java.util.Map; import javax.servlet.FilterChain; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import org.springframework.http.MediaType; import org.springframework.util.MimeType; import org.springframework.web.filter.OncePerRequestFilter; @@ -64,11 +62,11 @@ protected void doFilterInternal( final HttpServletRequest request = resolveHttpServletRequest(servletRequest); hub.pushScope(); try { - final Map hintMap = new HashMap<>(); - hintMap.put(SPRING_REQUEST_FILTER_REQUEST, servletRequest); - hintMap.put(SPRING_REQUEST_FILTER_RESPONSE, response); + final Hints hints = new Hints(); + hints.set(SPRING_REQUEST_FILTER_REQUEST, servletRequest); + hints.set(SPRING_REQUEST_FILTER_RESPONSE, response); - hub.addBreadcrumb(Breadcrumb.http(request.getRequestURI(), request.getMethod()), hintMap); + hub.addBreadcrumb(Breadcrumb.http(request.getRequestURI(), request.getMethod()), hints); configureScope(request); filterChain.doFilter(request, response); } finally { @@ -150,8 +148,7 @@ public RequestBodyExtractingEventProcessor( } @Override - public @NotNull SentryEvent process( - @NotNull SentryEvent event, @Nullable Map hint) { + public @NotNull SentryEvent process(@NotNull SentryEvent event, @NotNull Hints hints) { if (event.getRequest() != null) { event.getRequest().setData(requestPayloadExtractor.extract(request, options)); } diff --git a/sentry-spring/src/main/java/io/sentry/spring/tracing/SentrySpanClientHttpRequestInterceptor.java b/sentry-spring/src/main/java/io/sentry/spring/tracing/SentrySpanClientHttpRequestInterceptor.java index ad8fc1682a..1c1319f750 100644 --- a/sentry-spring/src/main/java/io/sentry/spring/tracing/SentrySpanClientHttpRequestInterceptor.java +++ b/sentry-spring/src/main/java/io/sentry/spring/tracing/SentrySpanClientHttpRequestInterceptor.java @@ -11,10 +11,9 @@ import io.sentry.SentryTraceHeader; import io.sentry.SpanStatus; import io.sentry.TracingOrigins; +import io.sentry.hints.Hints; import io.sentry.util.Objects; import java.io.IOException; -import java.util.HashMap; -import java.util.Map; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.springframework.http.HttpRequest; @@ -81,13 +80,13 @@ private void addBreadcrumb( Breadcrumb.http(request.getURI().toString(), request.getMethodValue(), responseStatusCode); breadcrumb.setData("request_body_size", body.length); - final Map hintMap = new HashMap<>(); - hintMap.put(SPRING_REQUEST_INTERCEPTOR_REQUEST, request); - hintMap.put(SPRING_REQUEST_INTERCEPTOR_REQUEST_BODY, body); + final Hints hints = new Hints(); + hints.set(SPRING_REQUEST_INTERCEPTOR_REQUEST, request); + hints.set(SPRING_REQUEST_INTERCEPTOR_REQUEST_BODY, body); if (response != null) { - hintMap.put(SPRING_REQUEST_INTERCEPTOR_RESPONSE, response); + hints.set(SPRING_REQUEST_INTERCEPTOR_RESPONSE, response); } - hub.addBreadcrumb(breadcrumb, hintMap); + hub.addBreadcrumb(breadcrumb, hints); } } diff --git a/sentry-spring/src/main/java/io/sentry/spring/tracing/SentrySpanClientWebRequestFilter.java b/sentry-spring/src/main/java/io/sentry/spring/tracing/SentrySpanClientWebRequestFilter.java index 17a8650a27..de5f2535bb 100644 --- a/sentry-spring/src/main/java/io/sentry/spring/tracing/SentrySpanClientWebRequestFilter.java +++ b/sentry-spring/src/main/java/io/sentry/spring/tracing/SentrySpanClientWebRequestFilter.java @@ -10,9 +10,8 @@ import io.sentry.SentryTraceHeader; import io.sentry.SpanStatus; import io.sentry.TracingOrigins; +import io.sentry.hints.Hints; import io.sentry.util.Objects; -import java.util.HashMap; -import java.util.Map; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.springframework.web.reactive.function.client.ClientRequest; @@ -77,12 +76,12 @@ private void addBreadcrumb( request.method().name(), response != null ? response.rawStatusCode() : null); - final Map hintMap = new HashMap<>(); - hintMap.put(SPRING_EXCHANGE_FILTER_REQUEST, request); + final Hints hints = new Hints(); + hints.set(SPRING_EXCHANGE_FILTER_REQUEST, request); if (response != null) { - hintMap.put(SPRING_EXCHANGE_FILTER_RESPONSE, response); + hints.set(SPRING_EXCHANGE_FILTER_RESPONSE, response); } - hub.addBreadcrumb(breadcrumb, hintMap); + hub.addBreadcrumb(breadcrumb, hints); } } diff --git a/sentry-spring/src/main/java/io/sentry/spring/webflux/SentryWebExceptionHandler.java b/sentry-spring/src/main/java/io/sentry/spring/webflux/SentryWebExceptionHandler.java index 38d7750d81..4099bd842e 100644 --- a/sentry-spring/src/main/java/io/sentry/spring/webflux/SentryWebExceptionHandler.java +++ b/sentry-spring/src/main/java/io/sentry/spring/webflux/SentryWebExceptionHandler.java @@ -7,10 +7,9 @@ import io.sentry.SentryEvent; import io.sentry.SentryLevel; import io.sentry.exception.ExceptionMechanismException; +import io.sentry.hints.Hints; import io.sentry.protocol.Mechanism; import io.sentry.util.Objects; -import java.util.HashMap; -import java.util.Map; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; import org.springframework.core.annotation.Order; @@ -44,11 +43,11 @@ public SentryWebExceptionHandler(final @NotNull IHub hub) { event.setLevel(SentryLevel.FATAL); event.setTransaction(TransactionNameProvider.provideTransactionName(serverWebExchange)); - final Map hintMap = new HashMap<>(); - hintMap.put(WEBFLUX_EXCEPTION_HANDLER_REQUEST, serverWebExchange.getRequest()); - hintMap.put(WEBFLUX_EXCEPTION_HANDLER_RESPONSE, serverWebExchange.getResponse()); + final Hints hints = new Hints(); + hints.set(WEBFLUX_EXCEPTION_HANDLER_REQUEST, serverWebExchange.getRequest()); + hints.set(WEBFLUX_EXCEPTION_HANDLER_RESPONSE, serverWebExchange.getResponse()); - hub.captureEvent(event, hintMap); + hub.captureEvent(event, hints); } return Mono.error(ex); } diff --git a/sentry-spring/src/main/java/io/sentry/spring/webflux/SentryWebFilter.java b/sentry-spring/src/main/java/io/sentry/spring/webflux/SentryWebFilter.java index 8cd060779a..e349ac4e9c 100644 --- a/sentry-spring/src/main/java/io/sentry/spring/webflux/SentryWebFilter.java +++ b/sentry-spring/src/main/java/io/sentry/spring/webflux/SentryWebFilter.java @@ -5,9 +5,8 @@ import io.sentry.Breadcrumb; import io.sentry.IHub; +import io.sentry.hints.Hints; import io.sentry.util.Objects; -import java.util.HashMap; -import java.util.Map; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; import org.springframework.http.server.reactive.ServerHttpRequest; @@ -44,12 +43,12 @@ public Mono filter( final ServerHttpRequest request = serverWebExchange.getRequest(); final ServerHttpResponse response = serverWebExchange.getResponse(); - final Map hintMap = new HashMap<>(); - hintMap.put(WEBFLUX_FILTER_REQUEST, request); - hintMap.put(WEBFLUX_FILTER_RESPONSE, response); + final Hints hints = new Hints(); + hints.set(WEBFLUX_FILTER_REQUEST, request); + hints.set(WEBFLUX_FILTER_RESPONSE, response); hub.addBreadcrumb( - Breadcrumb.http(request.getURI().toString(), request.getMethodValue()), hintMap); + Breadcrumb.http(request.getURI().toString(), request.getMethodValue()), hints); hub.configureScope( scope -> scope.setRequest(sentryRequestResolver.resolveSentryRequest(request))); }); diff --git a/sentry-spring/src/test/kotlin/io/sentry/spring/SentryRequestHttpServletRequestProcessorTest.kt b/sentry-spring/src/test/kotlin/io/sentry/spring/SentryRequestHttpServletRequestProcessorTest.kt index 360d505fb0..95bf6f5538 100644 --- a/sentry-spring/src/test/kotlin/io/sentry/spring/SentryRequestHttpServletRequestProcessorTest.kt +++ b/sentry-spring/src/test/kotlin/io/sentry/spring/SentryRequestHttpServletRequestProcessorTest.kt @@ -5,6 +5,7 @@ import com.nhaarman.mockitokotlin2.whenever import io.sentry.IHub import io.sentry.SentryEvent import io.sentry.SentryOptions +import io.sentry.hints.Hints import io.sentry.spring.tracing.SpringMvcTransactionNameProvider import org.springframework.mock.web.MockServletContext import org.springframework.test.web.servlet.request.MockMvcRequestBuilders @@ -37,7 +38,7 @@ class SentryRequestHttpServletRequestProcessorTest { val eventProcessor = fixture.getSut(request) val event = SentryEvent() - eventProcessor.process(event, null) + eventProcessor.process(event, Hints()) assertNotNull(event.transaction) assertEquals("GET /some-path", event.transaction) @@ -53,7 +54,7 @@ class SentryRequestHttpServletRequestProcessorTest { val event = SentryEvent() event.transaction = "some-transaction" - eventProcessor.process(event, null) + eventProcessor.process(event, Hints()) assertNotNull(event.transaction) assertEquals("some-transaction", event.transaction) diff --git a/sentry/api/sentry.api b/sentry/api/sentry.api index a13d37b9e7..2489f2d3bb 100644 --- a/sentry/api/sentry.api +++ b/sentry/api/sentry.api @@ -119,7 +119,7 @@ public final class io/sentry/DiagnosticLogger : io/sentry/ILogger { public final class io/sentry/DuplicateEventDetectionEventProcessor : io/sentry/EventProcessor { public fun (Lio/sentry/SentryOptions;)V - public fun process (Lio/sentry/SentryEvent;Ljava/util/Map;)Lio/sentry/SentryEvent; + public fun process (Lio/sentry/SentryEvent;Lio/sentry/hints/Hints;)Lio/sentry/SentryEvent; } public final class io/sentry/EnvelopeReader : io/sentry/IEnvelopeReader { @@ -130,12 +130,12 @@ public final class io/sentry/EnvelopeReader : io/sentry/IEnvelopeReader { public final class io/sentry/EnvelopeSender : io/sentry/IEnvelopeSender { public fun (Lio/sentry/IHub;Lio/sentry/ISerializer;Lio/sentry/ILogger;J)V public synthetic fun processDirectory (Ljava/io/File;)V - public fun processEnvelopeFile (Ljava/lang/String;Ljava/util/Map;)V + public fun processEnvelopeFile (Ljava/lang/String;Lio/sentry/hints/Hints;)V } public abstract interface class io/sentry/EventProcessor { - public fun process (Lio/sentry/SentryEvent;Ljava/util/Map;)Lio/sentry/SentryEvent; - public fun process (Lio/sentry/protocol/SentryTransaction;Ljava/util/Map;)Lio/sentry/protocol/SentryTransaction; + public fun process (Lio/sentry/SentryEvent;Lio/sentry/hints/Hints;)Lio/sentry/SentryEvent; + public fun process (Lio/sentry/protocol/SentryTransaction;Lio/sentry/hints/Hints;)Lio/sentry/protocol/SentryTransaction; } public final class io/sentry/ExternalOptions { @@ -185,13 +185,13 @@ public final class io/sentry/ExternalOptions { public final class io/sentry/Hub : io/sentry/IHub { public fun (Lio/sentry/SentryOptions;)V - public fun addBreadcrumb (Lio/sentry/Breadcrumb;Ljava/util/Map;)V + public fun addBreadcrumb (Lio/sentry/Breadcrumb;Lio/sentry/hints/Hints;)V public fun bindClient (Lio/sentry/ISentryClient;)V - public fun captureEnvelope (Lio/sentry/SentryEnvelope;Ljava/util/Map;)Lio/sentry/protocol/SentryId; - public fun captureEvent (Lio/sentry/SentryEvent;Ljava/util/Map;)Lio/sentry/protocol/SentryId; - public fun captureException (Ljava/lang/Throwable;Ljava/util/Map;)Lio/sentry/protocol/SentryId; + public fun captureEnvelope (Lio/sentry/SentryEnvelope;Lio/sentry/hints/Hints;)Lio/sentry/protocol/SentryId; + public fun captureEvent (Lio/sentry/SentryEvent;Lio/sentry/hints/Hints;)Lio/sentry/protocol/SentryId; + public fun captureException (Ljava/lang/Throwable;Lio/sentry/hints/Hints;)Lio/sentry/protocol/SentryId; public fun captureMessage (Ljava/lang/String;Lio/sentry/SentryLevel;)Lio/sentry/protocol/SentryId; - public fun captureTransaction (Lio/sentry/protocol/SentryTransaction;Lio/sentry/TraceState;Ljava/util/Map;Lio/sentry/ProfilingTraceData;)Lio/sentry/protocol/SentryId; + public fun captureTransaction (Lio/sentry/protocol/SentryTransaction;Lio/sentry/TraceState;Lio/sentry/hints/Hints;Lio/sentry/ProfilingTraceData;)Lio/sentry/protocol/SentryId; public fun captureUserFeedback (Lio/sentry/UserFeedback;)V public fun clearBreadcrumbs ()V public fun clone ()Lio/sentry/IHub; @@ -225,13 +225,13 @@ public final class io/sentry/Hub : io/sentry/IHub { } public final class io/sentry/HubAdapter : io/sentry/IHub { - public fun addBreadcrumb (Lio/sentry/Breadcrumb;Ljava/util/Map;)V + public fun addBreadcrumb (Lio/sentry/Breadcrumb;Lio/sentry/hints/Hints;)V public fun bindClient (Lio/sentry/ISentryClient;)V - public fun captureEnvelope (Lio/sentry/SentryEnvelope;Ljava/util/Map;)Lio/sentry/protocol/SentryId; - public fun captureEvent (Lio/sentry/SentryEvent;Ljava/util/Map;)Lio/sentry/protocol/SentryId; - public fun captureException (Ljava/lang/Throwable;Ljava/util/Map;)Lio/sentry/protocol/SentryId; + public fun captureEnvelope (Lio/sentry/SentryEnvelope;Lio/sentry/hints/Hints;)Lio/sentry/protocol/SentryId; + public fun captureEvent (Lio/sentry/SentryEvent;Lio/sentry/hints/Hints;)Lio/sentry/protocol/SentryId; + public fun captureException (Ljava/lang/Throwable;Lio/sentry/hints/Hints;)Lio/sentry/protocol/SentryId; public fun captureMessage (Ljava/lang/String;Lio/sentry/SentryLevel;)Lio/sentry/protocol/SentryId; - public fun captureTransaction (Lio/sentry/protocol/SentryTransaction;Lio/sentry/TraceState;Ljava/util/Map;Lio/sentry/ProfilingTraceData;)Lio/sentry/protocol/SentryId; + public fun captureTransaction (Lio/sentry/protocol/SentryTransaction;Lio/sentry/TraceState;Lio/sentry/hints/Hints;Lio/sentry/ProfilingTraceData;)Lio/sentry/protocol/SentryId; public fun captureUserFeedback (Lio/sentry/UserFeedback;)V public fun clearBreadcrumbs ()V public fun clone ()Lio/sentry/IHub; @@ -271,27 +271,27 @@ public abstract interface class io/sentry/IEnvelopeReader { } public abstract interface class io/sentry/IEnvelopeSender { - public abstract fun processEnvelopeFile (Ljava/lang/String;Ljava/util/Map;)V + public abstract fun processEnvelopeFile (Ljava/lang/String;Lio/sentry/hints/Hints;)V } public abstract interface class io/sentry/IHub { public fun addBreadcrumb (Lio/sentry/Breadcrumb;)V - public abstract fun addBreadcrumb (Lio/sentry/Breadcrumb;Ljava/util/Map;)V + public abstract fun addBreadcrumb (Lio/sentry/Breadcrumb;Lio/sentry/hints/Hints;)V public fun addBreadcrumb (Ljava/lang/String;)V public fun addBreadcrumb (Ljava/lang/String;Ljava/lang/String;)V public abstract fun bindClient (Lio/sentry/ISentryClient;)V public fun captureEnvelope (Lio/sentry/SentryEnvelope;)Lio/sentry/protocol/SentryId; - public abstract fun captureEnvelope (Lio/sentry/SentryEnvelope;Ljava/util/Map;)Lio/sentry/protocol/SentryId; + public abstract fun captureEnvelope (Lio/sentry/SentryEnvelope;Lio/sentry/hints/Hints;)Lio/sentry/protocol/SentryId; public fun captureEvent (Lio/sentry/SentryEvent;)Lio/sentry/protocol/SentryId; - public abstract fun captureEvent (Lio/sentry/SentryEvent;Ljava/util/Map;)Lio/sentry/protocol/SentryId; + public abstract fun captureEvent (Lio/sentry/SentryEvent;Lio/sentry/hints/Hints;)Lio/sentry/protocol/SentryId; public fun captureException (Ljava/lang/Throwable;)Lio/sentry/protocol/SentryId; - public abstract fun captureException (Ljava/lang/Throwable;Ljava/util/Map;)Lio/sentry/protocol/SentryId; + public abstract fun captureException (Ljava/lang/Throwable;Lio/sentry/hints/Hints;)Lio/sentry/protocol/SentryId; public fun captureMessage (Ljava/lang/String;)Lio/sentry/protocol/SentryId; public abstract fun captureMessage (Ljava/lang/String;Lio/sentry/SentryLevel;)Lio/sentry/protocol/SentryId; public fun captureTransaction (Lio/sentry/protocol/SentryTransaction;Lio/sentry/TraceState;)Lio/sentry/protocol/SentryId; - public fun captureTransaction (Lio/sentry/protocol/SentryTransaction;Lio/sentry/TraceState;Ljava/util/Map;)Lio/sentry/protocol/SentryId; - public abstract fun captureTransaction (Lio/sentry/protocol/SentryTransaction;Lio/sentry/TraceState;Ljava/util/Map;Lio/sentry/ProfilingTraceData;)Lio/sentry/protocol/SentryId; - public fun captureTransaction (Lio/sentry/protocol/SentryTransaction;Ljava/util/Map;)Lio/sentry/protocol/SentryId; + public fun captureTransaction (Lio/sentry/protocol/SentryTransaction;Lio/sentry/TraceState;Lio/sentry/hints/Hints;)Lio/sentry/protocol/SentryId; + public abstract fun captureTransaction (Lio/sentry/protocol/SentryTransaction;Lio/sentry/TraceState;Lio/sentry/hints/Hints;Lio/sentry/ProfilingTraceData;)Lio/sentry/protocol/SentryId; + public fun captureTransaction (Lio/sentry/protocol/SentryTransaction;Lio/sentry/hints/Hints;)Lio/sentry/protocol/SentryId; public abstract fun captureUserFeedback (Lio/sentry/UserFeedback;)V public abstract fun clearBreadcrumbs ()V public abstract fun clone ()Lio/sentry/IHub; @@ -349,24 +349,24 @@ public abstract interface class io/sentry/IScopeObserver { public abstract interface class io/sentry/ISentryClient { public fun captureEnvelope (Lio/sentry/SentryEnvelope;)Lio/sentry/protocol/SentryId; - public abstract fun captureEnvelope (Lio/sentry/SentryEnvelope;Ljava/util/Map;)Lio/sentry/protocol/SentryId; + public abstract fun captureEnvelope (Lio/sentry/SentryEnvelope;Lio/sentry/hints/Hints;)Lio/sentry/protocol/SentryId; public fun captureEvent (Lio/sentry/SentryEvent;)Lio/sentry/protocol/SentryId; public fun captureEvent (Lio/sentry/SentryEvent;Lio/sentry/Scope;)Lio/sentry/protocol/SentryId; - public abstract fun captureEvent (Lio/sentry/SentryEvent;Lio/sentry/Scope;Ljava/util/Map;)Lio/sentry/protocol/SentryId; - public fun captureEvent (Lio/sentry/SentryEvent;Ljava/util/Map;)Lio/sentry/protocol/SentryId; + public abstract fun captureEvent (Lio/sentry/SentryEvent;Lio/sentry/Scope;Lio/sentry/hints/Hints;)Lio/sentry/protocol/SentryId; + public fun captureEvent (Lio/sentry/SentryEvent;Lio/sentry/hints/Hints;)Lio/sentry/protocol/SentryId; public fun captureException (Ljava/lang/Throwable;)Lio/sentry/protocol/SentryId; public fun captureException (Ljava/lang/Throwable;Lio/sentry/Scope;)Lio/sentry/protocol/SentryId; - public fun captureException (Ljava/lang/Throwable;Lio/sentry/Scope;Ljava/util/Map;)Lio/sentry/protocol/SentryId; - public fun captureException (Ljava/lang/Throwable;Ljava/util/Map;)Lio/sentry/protocol/SentryId; + public fun captureException (Ljava/lang/Throwable;Lio/sentry/Scope;Lio/sentry/hints/Hints;)Lio/sentry/protocol/SentryId; + public fun captureException (Ljava/lang/Throwable;Lio/sentry/hints/Hints;)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/Scope;)Lio/sentry/protocol/SentryId; public fun captureSession (Lio/sentry/Session;)V - public abstract fun captureSession (Lio/sentry/Session;Ljava/util/Map;)V + public abstract fun captureSession (Lio/sentry/Session;Lio/sentry/hints/Hints;)V public fun captureTransaction (Lio/sentry/protocol/SentryTransaction;)Lio/sentry/protocol/SentryId; - public fun captureTransaction (Lio/sentry/protocol/SentryTransaction;Lio/sentry/Scope;Ljava/util/Map;)Lio/sentry/protocol/SentryId; + public fun captureTransaction (Lio/sentry/protocol/SentryTransaction;Lio/sentry/Scope;Lio/sentry/hints/Hints;)Lio/sentry/protocol/SentryId; public fun captureTransaction (Lio/sentry/protocol/SentryTransaction;Lio/sentry/TraceState;)Lio/sentry/protocol/SentryId; - public fun captureTransaction (Lio/sentry/protocol/SentryTransaction;Lio/sentry/TraceState;Lio/sentry/Scope;Ljava/util/Map;)Lio/sentry/protocol/SentryId; - public abstract fun captureTransaction (Lio/sentry/protocol/SentryTransaction;Lio/sentry/TraceState;Lio/sentry/Scope;Ljava/util/Map;Lio/sentry/ProfilingTraceData;)Lio/sentry/protocol/SentryId; + public fun captureTransaction (Lio/sentry/protocol/SentryTransaction;Lio/sentry/TraceState;Lio/sentry/Scope;Lio/sentry/hints/Hints;)Lio/sentry/protocol/SentryId; + public abstract fun captureTransaction (Lio/sentry/protocol/SentryTransaction;Lio/sentry/TraceState;Lio/sentry/Scope;Lio/sentry/hints/Hints;Lio/sentry/ProfilingTraceData;)Lio/sentry/protocol/SentryId; public abstract fun captureUserFeedback (Lio/sentry/UserFeedback;)V public abstract fun close ()V public abstract fun flush (J)V @@ -504,8 +504,8 @@ public abstract interface class io/sentry/JsonUnknown { public final class io/sentry/MainEventProcessor : io/sentry/EventProcessor, java/io/Closeable { public fun (Lio/sentry/SentryOptions;)V public fun close ()V - public fun process (Lio/sentry/SentryEvent;Ljava/util/Map;)Lio/sentry/SentryEvent; - public fun process (Lio/sentry/protocol/SentryTransaction;Ljava/util/Map;)Lio/sentry/protocol/SentryTransaction; + public fun process (Lio/sentry/SentryEvent;Lio/sentry/hints/Hints;)Lio/sentry/SentryEvent; + public fun process (Lio/sentry/protocol/SentryTransaction;Lio/sentry/hints/Hints;)Lio/sentry/protocol/SentryTransaction; } public final class io/sentry/NoOpEnvelopeReader : io/sentry/IEnvelopeReader { @@ -514,13 +514,13 @@ public final class io/sentry/NoOpEnvelopeReader : io/sentry/IEnvelopeReader { } public final class io/sentry/NoOpHub : io/sentry/IHub { - public fun addBreadcrumb (Lio/sentry/Breadcrumb;Ljava/util/Map;)V + public fun addBreadcrumb (Lio/sentry/Breadcrumb;Lio/sentry/hints/Hints;)V public fun bindClient (Lio/sentry/ISentryClient;)V - public fun captureEnvelope (Lio/sentry/SentryEnvelope;Ljava/util/Map;)Lio/sentry/protocol/SentryId; - public fun captureEvent (Lio/sentry/SentryEvent;Ljava/util/Map;)Lio/sentry/protocol/SentryId; - public fun captureException (Ljava/lang/Throwable;Ljava/util/Map;)Lio/sentry/protocol/SentryId; + public fun captureEnvelope (Lio/sentry/SentryEnvelope;Lio/sentry/hints/Hints;)Lio/sentry/protocol/SentryId; + public fun captureEvent (Lio/sentry/SentryEvent;Lio/sentry/hints/Hints;)Lio/sentry/protocol/SentryId; + public fun captureException (Ljava/lang/Throwable;Lio/sentry/hints/Hints;)Lio/sentry/protocol/SentryId; public fun captureMessage (Ljava/lang/String;Lio/sentry/SentryLevel;)Lio/sentry/protocol/SentryId; - public fun captureTransaction (Lio/sentry/protocol/SentryTransaction;Lio/sentry/TraceState;Ljava/util/Map;Lio/sentry/ProfilingTraceData;)Lio/sentry/protocol/SentryId; + public fun captureTransaction (Lio/sentry/protocol/SentryTransaction;Lio/sentry/TraceState;Lio/sentry/hints/Hints;Lio/sentry/ProfilingTraceData;)Lio/sentry/protocol/SentryId; public fun captureUserFeedback (Lio/sentry/UserFeedback;)V public fun clearBreadcrumbs ()V public fun clone ()Lio/sentry/IHub; @@ -640,7 +640,7 @@ public final class io/sentry/OptionsContainer { public final class io/sentry/OutboxSender : io/sentry/IEnvelopeSender { public fun (Lio/sentry/IHub;Lio/sentry/IEnvelopeReader;Lio/sentry/ISerializer;Lio/sentry/ILogger;J)V public synthetic fun processDirectory (Ljava/io/File;)V - public fun processEnvelopeFile (Ljava/lang/String;Ljava/util/Map;)V + public fun processEnvelopeFile (Ljava/lang/String;Lio/sentry/hints/Hints;)V } public final class io/sentry/ProfilingTraceData : io/sentry/JsonSerializable, io/sentry/JsonUnknown { @@ -740,7 +740,7 @@ public final class io/sentry/Scope { public fun (Lio/sentry/SentryOptions;)V public fun addAttachment (Lio/sentry/Attachment;)V public fun addBreadcrumb (Lio/sentry/Breadcrumb;)V - public fun addBreadcrumb (Lio/sentry/Breadcrumb;Ljava/util/Map;)V + public fun addBreadcrumb (Lio/sentry/Breadcrumb;Lio/sentry/hints/Hints;)V public fun addEventProcessor (Lio/sentry/EventProcessor;)V public fun clear ()V public fun clearAttachments ()V @@ -814,14 +814,14 @@ public final class io/sentry/SendFireAndForgetOutboxSender : io/sentry/SendCache public final class io/sentry/Sentry { public static fun addBreadcrumb (Lio/sentry/Breadcrumb;)V - public static fun addBreadcrumb (Lio/sentry/Breadcrumb;Ljava/util/Map;)V + public static fun addBreadcrumb (Lio/sentry/Breadcrumb;Lio/sentry/hints/Hints;)V public static fun addBreadcrumb (Ljava/lang/String;)V public static fun addBreadcrumb (Ljava/lang/String;Ljava/lang/String;)V public static fun bindClient (Lio/sentry/ISentryClient;)V public static fun captureEvent (Lio/sentry/SentryEvent;)Lio/sentry/protocol/SentryId; - public static fun captureEvent (Lio/sentry/SentryEvent;Ljava/util/Map;)Lio/sentry/protocol/SentryId; + public static fun captureEvent (Lio/sentry/SentryEvent;Lio/sentry/hints/Hints;)Lio/sentry/protocol/SentryId; public static fun captureException (Ljava/lang/Throwable;)Lio/sentry/protocol/SentryId; - public static fun captureException (Ljava/lang/Throwable;Ljava/util/Map;)Lio/sentry/protocol/SentryId; + public static fun captureException (Ljava/lang/Throwable;Lio/sentry/hints/Hints;)Lio/sentry/protocol/SentryId; public static fun captureMessage (Ljava/lang/String;)Lio/sentry/protocol/SentryId; public static fun captureMessage (Ljava/lang/String;Lio/sentry/SentryLevel;)Lio/sentry/protocol/SentryId; public static fun captureUserFeedback (Lio/sentry/UserFeedback;)V @@ -943,10 +943,10 @@ public final class io/sentry/SentryBaseEvent$Serializer { } public final class io/sentry/SentryClient : io/sentry/ISentryClient { - public fun captureEnvelope (Lio/sentry/SentryEnvelope;Ljava/util/Map;)Lio/sentry/protocol/SentryId; - public fun captureEvent (Lio/sentry/SentryEvent;Lio/sentry/Scope;Ljava/util/Map;)Lio/sentry/protocol/SentryId; - public fun captureSession (Lio/sentry/Session;Ljava/util/Map;)V - public fun captureTransaction (Lio/sentry/protocol/SentryTransaction;Lio/sentry/TraceState;Lio/sentry/Scope;Ljava/util/Map;Lio/sentry/ProfilingTraceData;)Lio/sentry/protocol/SentryId; + public fun captureEnvelope (Lio/sentry/SentryEnvelope;Lio/sentry/hints/Hints;)Lio/sentry/protocol/SentryId; + public fun captureEvent (Lio/sentry/SentryEvent;Lio/sentry/Scope;Lio/sentry/hints/Hints;)Lio/sentry/protocol/SentryId; + public fun captureSession (Lio/sentry/Session;Lio/sentry/hints/Hints;)V + public fun captureTransaction (Lio/sentry/protocol/SentryTransaction;Lio/sentry/TraceState;Lio/sentry/Scope;Lio/sentry/hints/Hints;Lio/sentry/ProfilingTraceData;)Lio/sentry/protocol/SentryId; public fun captureUserFeedback (Lio/sentry/UserFeedback;)V public fun close ()V public fun flush (J)V @@ -1257,11 +1257,11 @@ public class io/sentry/SentryOptions { } public abstract interface class io/sentry/SentryOptions$BeforeBreadcrumbCallback { - public abstract fun execute (Lio/sentry/Breadcrumb;Ljava/util/Map;)Lio/sentry/Breadcrumb; + public abstract fun execute (Lio/sentry/Breadcrumb;Lio/sentry/hints/Hints;)Lio/sentry/Breadcrumb; } public abstract interface class io/sentry/SentryOptions$BeforeSendCallback { - public abstract fun execute (Lio/sentry/SentryEvent;Ljava/util/Map;)Lio/sentry/SentryEvent; + public abstract fun execute (Lio/sentry/SentryEvent;Lio/sentry/hints/Hints;)Lio/sentry/SentryEvent; } public final class io/sentry/SentryOptions$Proxy { @@ -1704,13 +1704,13 @@ public final class io/sentry/cache/EnvelopeCache : io/sentry/cache/IEnvelopeCach public static fun create (Lio/sentry/SentryOptions;)Lio/sentry/cache/IEnvelopeCache; public fun discard (Lio/sentry/SentryEnvelope;)V public fun iterator ()Ljava/util/Iterator; - public fun store (Lio/sentry/SentryEnvelope;Ljava/util/Map;)V + public fun store (Lio/sentry/SentryEnvelope;Lio/sentry/hints/Hints;)V } public abstract interface class io/sentry/cache/IEnvelopeCache : java/lang/Iterable { public abstract fun discard (Lio/sentry/SentryEnvelope;)V public fun store (Lio/sentry/SentryEnvelope;)V - public abstract fun store (Lio/sentry/SentryEnvelope;Ljava/util/Map;)V + public abstract fun store (Lio/sentry/SentryEnvelope;Lio/sentry/hints/Hints;)V } public final class io/sentry/clientreport/ClientReport : io/sentry/JsonSerializable, io/sentry/JsonUnknown { @@ -1846,6 +1846,13 @@ public abstract interface class io/sentry/hints/Flushable { public abstract fun waitFlush ()Z } +public final class io/sentry/hints/Hints { + public fun ()V + public fun get (Ljava/lang/String;)Ljava/lang/Object; + public fun remove (Ljava/lang/String;)V + public fun set (Ljava/lang/String;Ljava/lang/Object;)V +} + public abstract interface class io/sentry/hints/Resettable { public abstract fun reset ()V } @@ -2825,7 +2832,7 @@ public final class io/sentry/transport/AsyncHttpTransport : io/sentry/transport/ public fun (Lio/sentry/transport/QueuedThreadPoolExecutor;Lio/sentry/SentryOptions;Lio/sentry/transport/RateLimiter;Lio/sentry/transport/ITransportGate;Lio/sentry/transport/HttpConnection;)V public fun close ()V public fun flush (J)V - public fun send (Lio/sentry/SentryEnvelope;Ljava/util/Map;)V + public fun send (Lio/sentry/SentryEnvelope;Lio/sentry/hints/Hints;)V } public final class io/sentry/transport/CurrentDateProvider : io/sentry/transport/ICurrentDateProvider { @@ -2840,7 +2847,7 @@ public abstract interface class io/sentry/transport/ICurrentDateProvider { public abstract interface class io/sentry/transport/ITransport : java/io/Closeable { public abstract fun flush (J)V public fun send (Lio/sentry/SentryEnvelope;)V - public abstract fun send (Lio/sentry/SentryEnvelope;Ljava/util/Map;)V + public abstract fun send (Lio/sentry/SentryEnvelope;Lio/sentry/hints/Hints;)V } public abstract interface class io/sentry/transport/ITransportGate { @@ -2852,14 +2859,14 @@ public final class io/sentry/transport/NoOpEnvelopeCache : io/sentry/cache/IEnve public fun discard (Lio/sentry/SentryEnvelope;)V public static fun getInstance ()Lio/sentry/transport/NoOpEnvelopeCache; public fun iterator ()Ljava/util/Iterator; - public fun store (Lio/sentry/SentryEnvelope;Ljava/util/Map;)V + public fun store (Lio/sentry/SentryEnvelope;Lio/sentry/hints/Hints;)V } public final class io/sentry/transport/NoOpTransport : io/sentry/transport/ITransport { public fun close ()V public fun flush (J)V public static fun getInstance ()Lio/sentry/transport/NoOpTransport; - public fun send (Lio/sentry/SentryEnvelope;Ljava/util/Map;)V + public fun send (Lio/sentry/SentryEnvelope;Lio/sentry/hints/Hints;)V } public final class io/sentry/transport/NoOpTransportGate : io/sentry/transport/ITransportGate { @@ -2870,7 +2877,7 @@ public final class io/sentry/transport/NoOpTransportGate : io/sentry/transport/I public final class io/sentry/transport/RateLimiter { public fun (Lio/sentry/SentryOptions;)V public fun (Lio/sentry/transport/ICurrentDateProvider;Lio/sentry/SentryOptions;)V - public fun filter (Lio/sentry/SentryEnvelope;Ljava/lang/Object;)Lio/sentry/SentryEnvelope; + public fun filter (Lio/sentry/SentryEnvelope;Lio/sentry/hints/Hints;)Lio/sentry/SentryEnvelope; public fun updateRetryAfterLimits (Ljava/lang/String;Ljava/lang/String;I)V } @@ -2888,7 +2895,7 @@ public final class io/sentry/transport/StdoutTransport : io/sentry/transport/ITr public fun (Lio/sentry/ISerializer;)V public fun close ()V public fun flush (J)V - public fun send (Lio/sentry/SentryEnvelope;Ljava/util/Map;)V + public fun send (Lio/sentry/SentryEnvelope;Lio/sentry/hints/Hints;)V } public abstract class io/sentry/transport/TransportResult { @@ -2923,14 +2930,32 @@ public final class io/sentry/util/FileUtils { } public final class io/sentry/util/HintUtils { - public static fun getSentrySdkHint (Ljava/util/Map;)Ljava/lang/Object; - public static fun shouldApplyScopeData (Ljava/util/Map;)Z + public static fun createWithTypeCheckHint (Ljava/lang/Object;)Lio/sentry/hints/Hints; + public static fun getSentrySdkHint (Lio/sentry/hints/Hints;)Ljava/lang/Object; + public static fun hasType (Lio/sentry/hints/Hints;Ljava/lang/Class;)Z + public static fun runIfDoesNotHaveType (Lio/sentry/hints/Hints;Ljava/lang/Class;Lio/sentry/util/HintUtils$SentryNullableConsumer;)V + public static fun runIfHasType (Lio/sentry/hints/Hints;Ljava/lang/Class;Lio/sentry/util/HintUtils$SentryConsumer;)V + public static fun runIfHasType (Lio/sentry/hints/Hints;Ljava/lang/Class;Lio/sentry/util/HintUtils$SentryConsumer;Lio/sentry/util/HintUtils$SentryFallbackConsumer;)V + public static fun runIfHasTypeLogIfNot (Lio/sentry/hints/Hints;Ljava/lang/Class;Lio/sentry/ILogger;Lio/sentry/util/HintUtils$SentryConsumer;)V + public static fun setTypeCheckHint (Lio/sentry/hints/Hints;Ljava/lang/Object;)V + public static fun shouldApplyScopeData (Lio/sentry/hints/Hints;)Z +} + +public abstract interface class io/sentry/util/HintUtils$SentryConsumer { + public abstract fun accept (Ljava/lang/Object;)V +} + +public abstract interface class io/sentry/util/HintUtils$SentryFallbackConsumer { + public abstract fun accept (Ljava/lang/Object;Ljava/lang/Class;)V +} + +public abstract interface class io/sentry/util/HintUtils$SentryNullableConsumer { + public abstract fun accept (Ljava/lang/Object;)V } public final class io/sentry/util/LogUtils { public fun ()V - public static fun logIfNotFlushable (Lio/sentry/ILogger;Ljava/lang/Object;)V - public static fun logIfNotRetryable (Lio/sentry/ILogger;Ljava/lang/Object;)V + public static fun logNotInstanceOf (Ljava/lang/Class;Ljava/lang/Object;Lio/sentry/ILogger;)V } public final class io/sentry/util/Objects { diff --git a/sentry/src/main/java/io/sentry/DirectoryProcessor.java b/sentry/src/main/java/io/sentry/DirectoryProcessor.java index 3277715021..31bf14f5b9 100644 --- a/sentry/src/main/java/io/sentry/DirectoryProcessor.java +++ b/sentry/src/main/java/io/sentry/DirectoryProcessor.java @@ -1,19 +1,17 @@ package io.sentry; import static io.sentry.SentryLevel.ERROR; -import static io.sentry.TypeCheckHint.SENTRY_TYPE_CHECK_HINT; import io.sentry.hints.Cached; import io.sentry.hints.Flushable; +import io.sentry.hints.Hints; import io.sentry.hints.Retryable; import io.sentry.hints.SubmissionResult; +import io.sentry.util.HintUtils; import java.io.File; -import java.util.HashMap; -import java.util.Map; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; abstract class DirectoryProcessor { @@ -67,18 +65,16 @@ public void processDirectory(final @NotNull File directory) { final SendCachedEnvelopeHint hint = new SendCachedEnvelopeHint(flushTimeoutMillis, logger); - final Map hintMap = new HashMap<>(); - hintMap.put(SENTRY_TYPE_CHECK_HINT, hint); + final Hints hints = HintUtils.createWithTypeCheckHint(hint); - processFile(file, hintMap); + processFile(file, hints); } } catch (Throwable e) { logger.log(SentryLevel.ERROR, e, "Failed processing '%s'", directory.getAbsolutePath()); } } - protected abstract void processFile( - final @NotNull File file, final @Nullable Map hint); + protected abstract void processFile(final @NotNull File file, final @NotNull Hints hints); protected abstract boolean isRelevantFileName(String fileName); diff --git a/sentry/src/main/java/io/sentry/DuplicateEventDetectionEventProcessor.java b/sentry/src/main/java/io/sentry/DuplicateEventDetectionEventProcessor.java index a5baa3c5fc..2b049fa26d 100644 --- a/sentry/src/main/java/io/sentry/DuplicateEventDetectionEventProcessor.java +++ b/sentry/src/main/java/io/sentry/DuplicateEventDetectionEventProcessor.java @@ -1,5 +1,6 @@ package io.sentry; +import io.sentry.hints.Hints; import io.sentry.util.Objects; import java.util.ArrayList; import java.util.Collections; @@ -21,7 +22,7 @@ public DuplicateEventDetectionEventProcessor(final @NotNull SentryOptions option @Override public @Nullable SentryEvent process( - final @NotNull SentryEvent event, final @Nullable Map hint) { + final @NotNull SentryEvent event, final @NotNull Hints hints) { if (options.isEnableDeduplication()) { final Throwable throwable = event.getThrowable(); if (throwable != null) { diff --git a/sentry/src/main/java/io/sentry/EnvelopeSender.java b/sentry/src/main/java/io/sentry/EnvelopeSender.java index bae79a6997..628f1b273d 100644 --- a/sentry/src/main/java/io/sentry/EnvelopeSender.java +++ b/sentry/src/main/java/io/sentry/EnvelopeSender.java @@ -2,9 +2,9 @@ import io.sentry.cache.EnvelopeCache; import io.sentry.hints.Flushable; +import io.sentry.hints.Hints; import io.sentry.hints.Retryable; import io.sentry.util.HintUtils; -import io.sentry.util.LogUtils; import io.sentry.util.Objects; import java.io.BufferedInputStream; import java.io.File; @@ -12,10 +12,8 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; -import java.util.Map; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; @ApiStatus.Internal public final class EnvelopeSender extends DirectoryProcessor implements IEnvelopeSender { @@ -36,7 +34,7 @@ public EnvelopeSender( } @Override - protected void processFile(final @NotNull File file, final @Nullable Map hint) { + protected void processFile(final @NotNull File file, final @NotNull Hints hints) { if (!file.isFile()) { logger.log(SentryLevel.DEBUG, "'%s' is not a file.", file.getAbsolutePath()); return; @@ -56,24 +54,24 @@ protected void processFile(final @NotNull File file, final @Nullable Map { + if (!flushable.waitFlush()) { + logger.log(SentryLevel.WARNING, "Timed out waiting for envelope submission."); + } + }); } catch (FileNotFoundException e) { logger.log(SentryLevel.ERROR, e, "File '%s' cannot be found.", file.getAbsolutePath()); } catch (IOException e) { @@ -81,27 +79,31 @@ protected void processFile(final @NotNull File file, final @Nullable Map { + retryable.setRetry(false); + logger.log(SentryLevel.INFO, e, "File '%s' won't retry.", file.getAbsolutePath()); + }); } finally { // Unless the transport marked this to be retried, it'll be deleted. - if (sentrySdkHint instanceof Retryable) { - if (!((Retryable) sentrySdkHint).isRetry()) { - safeDelete(file, "after trying to capture it"); - logger.log(SentryLevel.DEBUG, "Deleted file %s.", file.getAbsolutePath()); - } else { - logger.log( - SentryLevel.INFO, - "File not deleted since retry was marked. %s.", - file.getAbsolutePath()); - } - } else { - LogUtils.logIfNotRetryable(logger, sentrySdkHint); - } + HintUtils.runIfHasTypeLogIfNot( + hints, + Retryable.class, + logger, + (retryable) -> { + if (!retryable.isRetry()) { + safeDelete(file, "after trying to capture it"); + logger.log(SentryLevel.DEBUG, "Deleted file %s.", file.getAbsolutePath()); + } else { + logger.log( + SentryLevel.INFO, + "File not deleted since retry was marked. %s.", + file.getAbsolutePath()); + } + }); } } @@ -111,11 +113,10 @@ protected boolean isRelevantFileName(final @NotNull String fileName) { } @Override - public void processEnvelopeFile( - final @NotNull String path, final @Nullable Map hint) { + public void processEnvelopeFile(final @NotNull String path, final @NotNull Hints hints) { Objects.requireNonNull(path, "Path is required."); - processFile(new File(path), hint); + processFile(new File(path), hints); } private void safeDelete(final @NotNull File file, final @NotNull String errorMessageSuffix) { diff --git a/sentry/src/main/java/io/sentry/EventProcessor.java b/sentry/src/main/java/io/sentry/EventProcessor.java index 8f4a3b2cd4..cb18300c90 100644 --- a/sentry/src/main/java/io/sentry/EventProcessor.java +++ b/sentry/src/main/java/io/sentry/EventProcessor.java @@ -1,7 +1,7 @@ package io.sentry; +import io.sentry.hints.Hints; import io.sentry.protocol.SentryTransaction; -import java.util.Map; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -14,11 +14,11 @@ public interface EventProcessor { * May mutate or drop a SentryEvent * * @param event the SentryEvent - * @param hint the Hint + * @param hints the Hint * @return the event itself, a mutated SentryEvent or null */ @Nullable - default SentryEvent process(@NotNull SentryEvent event, @Nullable Map hint) { + default SentryEvent process(@NotNull SentryEvent event, @NotNull Hints hints) { return event; } @@ -26,12 +26,11 @@ default SentryEvent process(@NotNull SentryEvent event, @Nullable Map hint) { + default SentryTransaction process(@NotNull SentryTransaction transaction, @NotNull Hints hints) { return transaction; } } diff --git a/sentry/src/main/java/io/sentry/Hub.java b/sentry/src/main/java/io/sentry/Hub.java index fd3dc0e18a..b46ef85727 100644 --- a/sentry/src/main/java/io/sentry/Hub.java +++ b/sentry/src/main/java/io/sentry/Hub.java @@ -1,21 +1,20 @@ package io.sentry; -import static io.sentry.TypeCheckHint.SENTRY_TYPE_CHECK_HINT; - import io.sentry.Stack.StackItem; import io.sentry.clientreport.DiscardReason; +import io.sentry.hints.Hints; import io.sentry.hints.SessionEndHint; import io.sentry.hints.SessionStartHint; import io.sentry.protocol.SentryId; import io.sentry.protocol.SentryTransaction; import io.sentry.protocol.User; import io.sentry.util.ExceptionUtils; +import io.sentry.util.HintUtils; import io.sentry.util.Objects; import io.sentry.util.Pair; import java.io.Closeable; import java.util.Collections; import java.util.Date; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.WeakHashMap; @@ -77,7 +76,7 @@ public boolean isEnabled() { @Override public @NotNull SentryId captureEvent( - final @NotNull SentryEvent event, final @Nullable Map hint) { + final @NotNull SentryEvent event, final @Nullable Hints hints) { SentryId sentryId = SentryId.EMPTY_ID; if (!isEnabled()) { options @@ -90,7 +89,7 @@ public boolean isEnabled() { try { assignTraceContext(event); final StackItem item = stack.peek(); - sentryId = item.getClient().captureEvent(event, item.getScope(), hint); + sentryId = item.getClient().captureEvent(event, item.getScope(), hints); this.lastEventId = sentryId; } catch (Throwable e) { options @@ -129,7 +128,7 @@ public boolean isEnabled() { @ApiStatus.Internal @Override public @NotNull SentryId captureEnvelope( - final @NotNull SentryEnvelope envelope, final @Nullable Map hint) { + final @NotNull SentryEnvelope envelope, final @Nullable Hints hints) { Objects.requireNonNull(envelope, "SentryEnvelope is required."); SentryId sentryId = SentryId.EMPTY_ID; @@ -142,7 +141,7 @@ public boolean isEnabled() { } else { try { final SentryId capturedEnvelopeId = - stack.peek().getClient().captureEnvelope(envelope, hint); + stack.peek().getClient().captureEnvelope(envelope, hints); if (capturedEnvelopeId != null) { sentryId = capturedEnvelopeId; } @@ -155,7 +154,7 @@ public boolean isEnabled() { @Override public @NotNull SentryId captureException( - final @NotNull Throwable throwable, final @Nullable Map hint) { + final @NotNull Throwable throwable, final @Nullable Hints hints) { SentryId sentryId = SentryId.EMPTY_ID; if (!isEnabled()) { options @@ -170,7 +169,7 @@ public boolean isEnabled() { final StackItem item = stack.peek(); final SentryEvent event = new SentryEvent(throwable); assignTraceContext(event); - sentryId = item.getClient().captureEvent(event, item.getScope(), hint); + sentryId = item.getClient().captureEvent(event, item.getScope(), hints); } catch (Throwable e) { options .getLogger() @@ -237,16 +236,14 @@ public void startSession() { // single envelope // Or create the envelope here with both items and call `captureEnvelope` if (pair.getPrevious() != null) { - final Map hintMap = new HashMap<>(); - hintMap.put(SENTRY_TYPE_CHECK_HINT, new SessionEndHint()); + final Hints hints = HintUtils.createWithTypeCheckHint(new SessionEndHint()); - item.getClient().captureSession(pair.getPrevious(), hintMap); + item.getClient().captureSession(pair.getPrevious(), hints); } - final Map hintMap = new HashMap<>(); - hintMap.put(SENTRY_TYPE_CHECK_HINT, new SessionStartHint()); + final Hints hints = HintUtils.createWithTypeCheckHint(new SessionStartHint()); - item.getClient().captureSession(pair.getCurrent(), hintMap); + item.getClient().captureSession(pair.getCurrent(), hints); } else { options.getLogger().log(SentryLevel.WARNING, "Session could not be started."); } @@ -263,10 +260,9 @@ public void endSession() { final StackItem item = this.stack.peek(); final Session previousSession = item.getScope().endSession(); if (previousSession != null) { - final Map hintMap = new HashMap<>(); - hintMap.put(SENTRY_TYPE_CHECK_HINT, new SessionEndHint()); + final Hints hints = HintUtils.createWithTypeCheckHint(new SessionEndHint()); - item.getClient().captureSession(previousSession, hintMap); + item.getClient().captureSession(previousSession, hints); } } } @@ -298,8 +294,7 @@ public void close() { } @Override - public void addBreadcrumb( - final @NotNull Breadcrumb breadcrumb, final @Nullable Map hint) { + public void addBreadcrumb(final @NotNull Breadcrumb breadcrumb, final @Nullable Hints hints) { if (!isEnabled()) { options .getLogger() @@ -309,7 +304,7 @@ public void addBreadcrumb( } else if (breadcrumb == null) { options.getLogger().log(SentryLevel.WARNING, "addBreadcrumb called with null parameter."); } else { - stack.peek().getScope().addBreadcrumb(breadcrumb, hint); + stack.peek().getScope().addBreadcrumb(breadcrumb, hints); } } @@ -552,7 +547,7 @@ public void flush(long timeoutMillis) { public @NotNull SentryId captureTransaction( final @NotNull SentryTransaction transaction, final @Nullable TraceState traceState, - final @Nullable Map hint, + final @Nullable Hints hints, final @Nullable ProfilingTraceData profilingTraceData) { Objects.requireNonNull(transaction, "transaction is required"); @@ -589,7 +584,7 @@ public void flush(long timeoutMillis) { sentryId = item.getClient() .captureTransaction( - transaction, traceState, item.getScope(), hint, profilingTraceData); + transaction, traceState, item.getScope(), hints, profilingTraceData); } catch (Throwable e) { options .getLogger() diff --git a/sentry/src/main/java/io/sentry/HubAdapter.java b/sentry/src/main/java/io/sentry/HubAdapter.java index 73403e950a..05deaee59a 100644 --- a/sentry/src/main/java/io/sentry/HubAdapter.java +++ b/sentry/src/main/java/io/sentry/HubAdapter.java @@ -1,11 +1,11 @@ package io.sentry; +import io.sentry.hints.Hints; import io.sentry.protocol.SentryId; import io.sentry.protocol.SentryTransaction; import io.sentry.protocol.User; import java.util.Date; import java.util.List; -import java.util.Map; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -26,9 +26,8 @@ public boolean isEnabled() { } @Override - public @NotNull SentryId captureEvent( - @NotNull SentryEvent event, @Nullable Map hint) { - return Sentry.captureEvent(event, hint); + public @NotNull SentryId captureEvent(@NotNull SentryEvent event, @Nullable Hints hints) { + return Sentry.captureEvent(event, hints); } @Override @@ -39,14 +38,13 @@ public boolean isEnabled() { @ApiStatus.Internal @Override public @NotNull SentryId captureEnvelope( - @NotNull SentryEnvelope envelope, @Nullable Map hint) { - return Sentry.getCurrentHub().captureEnvelope(envelope, hint); + @NotNull SentryEnvelope envelope, @Nullable Hints hints) { + return Sentry.getCurrentHub().captureEnvelope(envelope, hints); } @Override - public @NotNull SentryId captureException( - @NotNull Throwable throwable, @Nullable Map hint) { - return Sentry.captureException(throwable, hint); + public @NotNull SentryId captureException(@NotNull Throwable throwable, @Nullable Hints hints) { + return Sentry.captureException(throwable, hints); } @Override @@ -70,8 +68,8 @@ public void close() { } @Override - public void addBreadcrumb(@NotNull Breadcrumb breadcrumb, @Nullable Map hint) { - Sentry.addBreadcrumb(breadcrumb, hint); + public void addBreadcrumb(@NotNull Breadcrumb breadcrumb, @Nullable Hints hints) { + Sentry.addBreadcrumb(breadcrumb, hints); } @Override @@ -163,10 +161,10 @@ public void flush(long timeoutMillis) { public @NotNull SentryId captureTransaction( @NotNull SentryTransaction transaction, @Nullable TraceState traceState, - @Nullable Map hint, + @Nullable Hints hints, @Nullable ProfilingTraceData profilingTraceData) { return Sentry.getCurrentHub() - .captureTransaction(transaction, traceState, hint, profilingTraceData); + .captureTransaction(transaction, traceState, hints, profilingTraceData); } @Override diff --git a/sentry/src/main/java/io/sentry/IEnvelopeSender.java b/sentry/src/main/java/io/sentry/IEnvelopeSender.java index 2a346e7400..f944804682 100644 --- a/sentry/src/main/java/io/sentry/IEnvelopeSender.java +++ b/sentry/src/main/java/io/sentry/IEnvelopeSender.java @@ -1,9 +1,8 @@ package io.sentry; -import java.util.Map; +import io.sentry.hints.Hints; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; public interface IEnvelopeSender { - void processEnvelopeFile(@NotNull String path, @Nullable Map hint); + void processEnvelopeFile(@NotNull String path, @NotNull Hints hints); } diff --git a/sentry/src/main/java/io/sentry/IHub.java b/sentry/src/main/java/io/sentry/IHub.java index 1045d23803..c23c4f52fe 100644 --- a/sentry/src/main/java/io/sentry/IHub.java +++ b/sentry/src/main/java/io/sentry/IHub.java @@ -1,11 +1,11 @@ package io.sentry; +import io.sentry.hints.Hints; import io.sentry.protocol.SentryId; import io.sentry.protocol.SentryTransaction; import io.sentry.protocol.User; import java.util.Date; import java.util.List; -import java.util.Map; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -24,11 +24,11 @@ public interface IHub { * Captures the event. * * @param event the event - * @param hint SDK specific but provides high level information about the origin of the event + * @param hints SDK specific but provides high level information about the origin of the event * @return The Id (SentryId object) of the event */ @NotNull - SentryId captureEvent(@NotNull SentryEvent event, @Nullable Map hint); + SentryId captureEvent(@NotNull SentryEvent event, @Nullable Hints hints); /** * Captures the event. @@ -64,11 +64,11 @@ public interface IHub { * Captures an envelope. * * @param envelope the SentryEnvelope to send. - * @param hint SDK specific but provides high level information about the origin of the event + * @param hints SDK specific but provides high level information about the origin of the event * @return The Id (SentryId object) of the event */ @NotNull - SentryId captureEnvelope(@NotNull SentryEnvelope envelope, @Nullable Map hint); + SentryId captureEnvelope(@NotNull SentryEnvelope envelope, @Nullable Hints hints); /** * Captures an envelope. @@ -77,18 +77,18 @@ public interface IHub { * @return The Id (SentryId object) of the event */ default @NotNull SentryId captureEnvelope(@NotNull SentryEnvelope envelope) { - return captureEnvelope(envelope, null); + return captureEnvelope(envelope, new Hints()); } /** * Captures the exception. * * @param throwable The exception. - * @param hint SDK specific but provides high level information about the origin of the event + * @param hints SDK specific but provides high level information about the origin of the event * @return The Id (SentryId object) of the event */ @NotNull - SentryId captureException(@NotNull Throwable throwable, @Nullable Map hint); + SentryId captureException(@NotNull Throwable throwable, @Nullable Hints hints); /** * Captures the exception. @@ -120,9 +120,9 @@ public interface IHub { * Adds a breadcrumb to the current Scope * * @param breadcrumb the breadcrumb - * @param hint SDK specific but provides high level information about the origin of the event + * @param hints SDK specific but provides high level information about the origin of the event */ - void addBreadcrumb(@NotNull Breadcrumb breadcrumb, @Nullable Map hint); + void addBreadcrumb(@NotNull Breadcrumb breadcrumb, @Nullable Hints hints); /** * Adds a breadcrumb to the current Scope @@ -130,7 +130,7 @@ public interface IHub { * @param breadcrumb the breadcrumb */ default void addBreadcrumb(@NotNull Breadcrumb breadcrumb) { - addBreadcrumb(breadcrumb, null); + addBreadcrumb(breadcrumb, new Hints()); } /** @@ -272,7 +272,7 @@ default void addBreadcrumb(@NotNull String message, @NotNull String category) { * * @param transaction the transaction * @param traceState the trace state - * @param hint the hint + * @param hints the hints * @param profilingTraceData the profiling trace data * @return transaction's id */ @@ -281,7 +281,7 @@ default void addBreadcrumb(@NotNull String message, @NotNull String category) { SentryId captureTransaction( @NotNull SentryTransaction transaction, @Nullable TraceState traceState, - @Nullable Map hint, + @Nullable Hints hints, final @Nullable ProfilingTraceData profilingTraceData); /** @@ -289,7 +289,7 @@ SentryId captureTransaction( * * @param transaction the transaction * @param traceState the trace state - * @param hint the hint + * @param hints the hints * @return transaction's id */ @ApiStatus.Internal @@ -297,15 +297,15 @@ SentryId captureTransaction( default SentryId captureTransaction( @NotNull SentryTransaction transaction, @Nullable TraceState traceState, - @Nullable Map hint) { - return captureTransaction(transaction, traceState, hint, null); + @Nullable Hints hints) { + return captureTransaction(transaction, traceState, hints, null); } @ApiStatus.Internal @NotNull default SentryId captureTransaction( - @NotNull SentryTransaction transaction, @Nullable Map hint) { - return captureTransaction(transaction, null, hint); + @NotNull SentryTransaction transaction, @Nullable Hints hints) { + return captureTransaction(transaction, null, hints); } /** diff --git a/sentry/src/main/java/io/sentry/ISentryClient.java b/sentry/src/main/java/io/sentry/ISentryClient.java index 3c6c1a9e13..6b421542cf 100644 --- a/sentry/src/main/java/io/sentry/ISentryClient.java +++ b/sentry/src/main/java/io/sentry/ISentryClient.java @@ -1,9 +1,9 @@ package io.sentry; +import io.sentry.hints.Hints; import io.sentry.protocol.Message; import io.sentry.protocol.SentryId; import io.sentry.protocol.SentryTransaction; -import java.util.Map; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -23,12 +23,11 @@ public interface ISentryClient { * * @param event the event * @param scope An optional scope to be applied to the event. - * @param hint SDK specific but provides high level information about the origin of the event. + * @param hints SDK specific but provides high level information about the origin of the event. * @return The Id (SentryId object) of the event. */ @NotNull - SentryId captureEvent( - @NotNull SentryEvent event, @Nullable Scope scope, @Nullable Map hint); + SentryId captureEvent(@NotNull SentryEvent event, @Nullable Scope scope, @Nullable Hints hints); /** Flushes out the queue for up to timeout seconds and disable the client. */ void close(); @@ -65,12 +64,11 @@ SentryId captureEvent( * Capture the event * * @param event the event - * @param hint SDK specific but provides high level information about the origin of the event. + * @param hints SDK specific but provides high level information about the origin of the event. * @return The Id (SentryId object) of the event. */ - default @NotNull SentryId captureEvent( - @NotNull SentryEvent event, @Nullable Map hint) { - return captureEvent(event, null, hint); + default @NotNull SentryId captureEvent(@NotNull SentryEvent event, @Nullable Hints hints) { + return captureEvent(event, null, hints); } /** @@ -117,26 +115,25 @@ SentryId captureEvent( * Captures the exception. * * @param throwable The exception. - * @param hint SDK specific but provides high level information about the origin of the event + * @param hints SDK specific but provides high level information about the origin of the event * @param scope An optional scope to be applied to the event. * @return The Id (SentryId object) of the event */ default @NotNull SentryId captureException( - @NotNull Throwable throwable, @Nullable Scope scope, @Nullable Map hint) { + @NotNull Throwable throwable, @Nullable Scope scope, @Nullable Hints hints) { SentryEvent event = new SentryEvent(throwable); - return captureEvent(event, scope, hint); + return captureEvent(event, scope, hints); } /** * Captures the exception. * * @param throwable The exception. - * @param hint SDK specific but provides high level information about the origin of the event + * @param hints SDK specific but provides high level information about the origin of the event * @return The Id (SentryId object) of the event */ - default @NotNull SentryId captureException( - @NotNull Throwable throwable, @Nullable Map hint) { - return captureException(throwable, null, hint); + default @NotNull SentryId captureException(@NotNull Throwable throwable, @Nullable Hints hints) { + return captureException(throwable, null, hints); } /** @@ -161,10 +158,10 @@ SentryId captureEvent( * Captures a session. This method transform a session to an envelope and forwards to * captureEnvelope * - * @param hint SDK specific but provides high level information about the origin of the event + * @param hints SDK specific but provides high level information about the origin of the event * @param session the Session */ - void captureSession(@NotNull Session session, @Nullable Map hint); + void captureSession(@NotNull Session session, @Nullable Hints hints); /** * Captures a session. This method transform a session to an envelope and forwards to @@ -180,11 +177,11 @@ default void captureSession(@NotNull Session session) { * Captures an envelope. * * @param envelope the SentryEnvelope to send. - * @param hint SDK specific but provides high level information about the origin of the event + * @param hints SDK specific but provides high level information about the origin of the event * @return The Id (SentryId object) of the event */ @Nullable - SentryId captureEnvelope(@NotNull SentryEnvelope envelope, @Nullable Map hint); + SentryId captureEnvelope(@NotNull SentryEnvelope envelope, @Nullable Hints hints); /** * Captures an envelope. @@ -201,15 +198,13 @@ default void captureSession(@NotNull Session session) { * * @param transaction the {@link ITransaction} to send * @param scope An optional scope to be applied to the event. - * @param hint SDK specific but provides high level information about the origin of the event + * @param hints SDK specific but provides high level information about the origin of the event * @return The Id (SentryId object) of the event */ @NotNull default SentryId captureTransaction( - @NotNull SentryTransaction transaction, - @Nullable Scope scope, - @Nullable Map hint) { - return captureTransaction(transaction, null, scope, hint); + @NotNull SentryTransaction transaction, @Nullable Scope scope, @Nullable Hints hints) { + return captureTransaction(transaction, null, scope, hints); } /** @@ -218,7 +213,7 @@ default SentryId captureTransaction( * @param transaction the {@link ITransaction} to send * @param traceState the trace state * @param scope An optional scope to be applied to the event. - * @param hint SDK specific but provides high level information about the origin of the event + * @param hints SDK specific but provides high level information about the origin of the event * @return The Id (SentryId object) of the event */ @NotNull @@ -227,8 +222,8 @@ default SentryId captureTransaction( @NotNull SentryTransaction transaction, @Nullable TraceState traceState, @Nullable Scope scope, - @Nullable Map hint) { - return captureTransaction(transaction, traceState, scope, hint, null); + @Nullable Hints hints) { + return captureTransaction(transaction, traceState, scope, hints, null); } /** @@ -237,7 +232,7 @@ default SentryId captureTransaction( * @param transaction the {@link ITransaction} to send * @param traceState the trace state * @param scope An optional scope to be applied to the event. - * @param hint SDK specific but provides high level information about the origin of the event + * @param hints SDK specific but provides high level information about the origin of the event * @param profilingTraceData An optional profiling trace data captured during the transaction * @return The Id (SentryId object) of the event */ @@ -247,7 +242,7 @@ SentryId captureTransaction( @NotNull SentryTransaction transaction, @Nullable TraceState traceState, @Nullable Scope scope, - @Nullable Map hint, + @Nullable Hints hints, @Nullable ProfilingTraceData profilingTraceData); /** diff --git a/sentry/src/main/java/io/sentry/MainEventProcessor.java b/sentry/src/main/java/io/sentry/MainEventProcessor.java index d17450d892..37cfece2df 100644 --- a/sentry/src/main/java/io/sentry/MainEventProcessor.java +++ b/sentry/src/main/java/io/sentry/MainEventProcessor.java @@ -1,6 +1,7 @@ package io.sentry; import io.sentry.hints.Cached; +import io.sentry.hints.Hints; import io.sentry.protocol.DebugImage; import io.sentry.protocol.DebugMeta; import io.sentry.protocol.SentryException; @@ -65,14 +66,14 @@ public MainEventProcessor(final @NotNull SentryOptions options) { @Override public @NotNull SentryEvent process( - final @NotNull SentryEvent event, final @Nullable Map hint) { + final @NotNull SentryEvent event, final @NotNull Hints hints) { setCommons(event); setExceptions(event); setDebugMeta(event); - if (shouldApplyScopeData(event, hint)) { + if (shouldApplyScopeData(event, hints)) { processNonCachedEvent(event); - setThreads(event, hint); + setThreads(event, hints); } return event; @@ -100,8 +101,8 @@ private void setDebugMeta(final @NotNull SentryEvent event) { } private boolean shouldApplyScopeData( - final @NotNull SentryBaseEvent event, final @Nullable Map hint) { - if (HintUtils.shouldApplyScopeData(hint)) { + final @NotNull SentryBaseEvent event, final @NotNull Hints hints) { + if (HintUtils.shouldApplyScopeData(hints)) { return true; } else { options @@ -126,10 +127,10 @@ private void processNonCachedEvent(final @NotNull SentryBaseEvent event) { @Override public @NotNull SentryTransaction process( - final @NotNull SentryTransaction transaction, final @Nullable Map hint) { + final @NotNull SentryTransaction transaction, final @NotNull Hints hints) { setCommons(transaction); - if (shouldApplyScopeData(transaction, hint)) { + if (shouldApplyScopeData(transaction, hints)) { processNonCachedEvent(transaction); } @@ -213,8 +214,7 @@ private void setExceptions(final @NotNull SentryEvent event) { } } - private void setThreads( - final @NotNull SentryEvent event, final @Nullable Map hint) { + private void setThreads(final @NotNull SentryEvent event, final @NotNull Hints hints) { if (event.getThreads() == null) { // collecting threadIds that came from the exception mechanism, so we can mark threads as // crashed properly @@ -233,12 +233,11 @@ private void setThreads( } } - Object sentrySdkHint = HintUtils.getSentrySdkHint(hint); if (options.isAttachThreads()) { event.setThreads(sentryThreadFactory.getCurrentThreads(mechanismThreadIds)); } else if (options.isAttachStacktrace() && (eventExceptions == null || eventExceptions.isEmpty()) - && !isCachedHint(sentrySdkHint)) { + && !isCachedHint(hints)) { // when attachStacktrace is enabled, we attach only the current thread and its stack traces, // if there are no exceptions, exceptions have its own stack traces. event.setThreads(sentryThreadFactory.getCurrentThread()); @@ -250,11 +249,11 @@ private void setThreads( * If the event has a Cached Hint, it means that it came from the EnvelopeFileObserver. We don't * want to append the current thread to the event. * - * @param sentrySdkHint the Hint + * @param hints the Hints * @return true if Cached or false otherwise */ - private boolean isCachedHint(final @Nullable Object sentrySdkHint) { - return (sentrySdkHint instanceof Cached); + private boolean isCachedHint(final @NotNull Hints hints) { + return HintUtils.hasType(hints, Cached.class); } @Override diff --git a/sentry/src/main/java/io/sentry/NoOpHub.java b/sentry/src/main/java/io/sentry/NoOpHub.java index 9309ac1cc9..46ece2c91b 100644 --- a/sentry/src/main/java/io/sentry/NoOpHub.java +++ b/sentry/src/main/java/io/sentry/NoOpHub.java @@ -1,11 +1,11 @@ package io.sentry; +import io.sentry.hints.Hints; import io.sentry.protocol.SentryId; import io.sentry.protocol.SentryTransaction; import io.sentry.protocol.User; import java.util.Date; import java.util.List; -import java.util.Map; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -27,8 +27,7 @@ public boolean isEnabled() { } @Override - public @NotNull SentryId captureEvent( - @NotNull SentryEvent event, @Nullable Map hint) { + public @NotNull SentryId captureEvent(@NotNull SentryEvent event, @Nullable Hints hints) { return SentryId.EMPTY_ID; } @@ -39,13 +38,12 @@ public boolean isEnabled() { @Override public @NotNull SentryId captureEnvelope( - @NotNull SentryEnvelope envelope, @Nullable Map hint) { + @NotNull SentryEnvelope envelope, @Nullable Hints hints) { return SentryId.EMPTY_ID; } @Override - public @NotNull SentryId captureException( - @NotNull Throwable throwable, @Nullable Map hint) { + public @NotNull SentryId captureException(@NotNull Throwable throwable, @Nullable Hints hints) { return SentryId.EMPTY_ID; } @@ -62,7 +60,7 @@ public void endSession() {} public void close() {} @Override - public void addBreadcrumb(@NotNull Breadcrumb breadcrumb, @Nullable Map hint) {} + public void addBreadcrumb(@NotNull Breadcrumb breadcrumb, @Nullable Hints hints) {} @Override public void setLevel(@Nullable SentryLevel level) {} @@ -123,7 +121,7 @@ public void flush(long timeoutMillis) {} public @NotNull SentryId captureTransaction( final @NotNull SentryTransaction transaction, final @Nullable TraceState traceState, - final @Nullable Map hint, + final @Nullable Hints hints, final @Nullable ProfilingTraceData profilingTraceData) { return SentryId.EMPTY_ID; } diff --git a/sentry/src/main/java/io/sentry/NoOpSentryClient.java b/sentry/src/main/java/io/sentry/NoOpSentryClient.java index b8eb1d598b..d86f2165cd 100644 --- a/sentry/src/main/java/io/sentry/NoOpSentryClient.java +++ b/sentry/src/main/java/io/sentry/NoOpSentryClient.java @@ -1,8 +1,8 @@ package io.sentry; +import io.sentry.hints.Hints; import io.sentry.protocol.SentryId; import io.sentry.protocol.SentryTransaction; -import java.util.Map; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -23,7 +23,7 @@ public boolean isEnabled() { @Override public @NotNull SentryId captureEvent( - @NotNull SentryEvent event, @Nullable Scope scope, @Nullable Map hint) { + @NotNull SentryEvent event, @Nullable Scope scope, @Nullable Hints hints) { return SentryId.EMPTY_ID; } @@ -37,11 +37,10 @@ public void flush(long timeoutMillis) {} public void captureUserFeedback(@NotNull UserFeedback userFeedback) {} @Override - public void captureSession(@NotNull Session session, @Nullable Map hint) {} + public void captureSession(@NotNull Session session, @Nullable Hints hints) {} @Override - public SentryId captureEnvelope( - @NotNull SentryEnvelope envelope, @Nullable Map hint) { + public SentryId captureEnvelope(@NotNull SentryEnvelope envelope, @Nullable Hints hints) { return SentryId.EMPTY_ID; } @@ -50,7 +49,7 @@ public SentryId captureEnvelope( @NotNull SentryTransaction transaction, @Nullable TraceState traceState, @Nullable Scope scope, - @Nullable Map hint, + @Nullable Hints hints, @Nullable ProfilingTraceData profilingTraceData) { return SentryId.EMPTY_ID; } diff --git a/sentry/src/main/java/io/sentry/OutboxSender.java b/sentry/src/main/java/io/sentry/OutboxSender.java index 5f9529292c..122347765e 100644 --- a/sentry/src/main/java/io/sentry/OutboxSender.java +++ b/sentry/src/main/java/io/sentry/OutboxSender.java @@ -4,6 +4,7 @@ import static io.sentry.cache.EnvelopeCache.PREFIX_CURRENT_SESSION_FILE; import io.sentry.hints.Flushable; +import io.sentry.hints.Hints; import io.sentry.hints.Resettable; import io.sentry.hints.Retryable; import io.sentry.hints.SubmissionResult; @@ -23,7 +24,6 @@ import java.io.InputStreamReader; import java.io.Reader; import java.nio.charset.Charset; -import java.util.Map; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -53,7 +53,7 @@ public OutboxSender( } @Override - protected void processFile(final @NotNull File file, @Nullable Map hint) { + protected void processFile(final @NotNull File file, @NotNull Hints hints) { Objects.requireNonNull(file, "File is required."); if (!isRelevantFileName(file.getName())) { @@ -61,8 +61,6 @@ protected void processFile(final @NotNull File file, @Nullable Map { + if (!retryable.isRetry()) { + try { + if (!file.delete()) { + logger.log(SentryLevel.ERROR, "Failed to delete: %s", file.getAbsolutePath()); + } + } catch (RuntimeException e) { + logger.log(SentryLevel.ERROR, e, "Failed to delete: %s", file.getAbsolutePath()); + } } - } catch (RuntimeException e) { - logger.log(SentryLevel.ERROR, e, "Failed to delete: %s", file.getAbsolutePath()); - } - } - } else { - LogUtils.logIfNotRetryable(logger, sentrySdkHint); - } + }); } } @@ -101,14 +101,13 @@ protected boolean isRelevantFileName(final @Nullable String fileName) { } @Override - public void processEnvelopeFile(@NotNull String path, @Nullable Map hint) { + public void processEnvelopeFile(@NotNull String path, @NotNull Hints hints) { Objects.requireNonNull(path, "Path is required."); - processFile(new File(path), hint); + processFile(new File(path), hints); } - private void processEnvelope( - final @NotNull SentryEnvelope envelope, final @Nullable Map hint) + private void processEnvelope(final @NotNull SentryEnvelope envelope, final @NotNull Hints hints) throws IOException { logger.log( SentryLevel.DEBUG, @@ -116,8 +115,6 @@ private void processEnvelope( CollectionUtils.size(envelope.getItems())); int currentItem = 0; - Object sentrySdkHint = HintUtils.getSentrySdkHint(hint); - for (final SentryEnvelopeItem item : envelope.getItems()) { currentItem++; @@ -138,10 +135,10 @@ private void processEnvelope( logUnexpectedEventId(envelope, event.getEventId(), currentItem); continue; } - hub.captureEvent(event, hint); + hub.captureEvent(event, hints); logItemCaptured(currentItem); - if (!waitFlush(sentrySdkHint)) { + if (!waitFlush(hints)) { logTimeout(event.getEventId()); break; } @@ -170,10 +167,10 @@ private void processEnvelope( // transient property. transaction.getContexts().getTrace().setSampled(true); } - hub.captureTransaction(transaction, envelope.getHeader().getTrace(), hint); + hub.captureTransaction(transaction, envelope.getHeader().getTrace(), hints); logItemCaptured(currentItem); - if (!waitFlush(sentrySdkHint)) { + if (!waitFlush(hints)) { logTimeout(transaction.getEventId()); break; } @@ -186,14 +183,14 @@ private void processEnvelope( final SentryEnvelope newEnvelope = new SentryEnvelope( envelope.getHeader().getEventId(), envelope.getHeader().getSdkVersion(), item); - hub.captureEnvelope(newEnvelope, hint); + hub.captureEnvelope(newEnvelope, hints); logger.log( SentryLevel.DEBUG, "%s item %d is being captured.", item.getHeader().getType().getItemType(), currentItem); - if (!waitFlush(sentrySdkHint)) { + if (!waitFlush(hints)) { logger.log( SentryLevel.WARNING, "Timed out waiting for item type submission: %s", @@ -202,6 +199,7 @@ private void processEnvelope( } } + final Object sentrySdkHint = HintUtils.getSentrySdkHint(hints); if (sentrySdkHint instanceof SubmissionResult) { if (!((SubmissionResult) sentrySdkHint).isSuccess()) { // Failed to send an item of the envelope: Stop attempting to send the rest (an attachment @@ -215,9 +213,7 @@ private void processEnvelope( } // reset the Hint to its initial state as we use it multiple times. - if (sentrySdkHint instanceof Resettable) { - ((Resettable) sentrySdkHint).reset(); - } + HintUtils.runIfHasType(hints, Resettable.class, (resettable) -> resettable.reset()); } } @@ -247,11 +243,12 @@ private void logTimeout(final @Nullable SentryId eventId) { logger.log(SentryLevel.WARNING, "Timed out waiting for event id submission: %s", eventId); } - private boolean waitFlush(final @Nullable Object sentrySdkHint) { + private boolean waitFlush(final @NotNull Hints hints) { + @Nullable Object sentrySdkHint = HintUtils.getSentrySdkHint(hints); if (sentrySdkHint instanceof Flushable) { return ((Flushable) sentrySdkHint).waitFlush(); } else { - LogUtils.logIfNotFlushable(logger, sentrySdkHint); + LogUtils.logNotInstanceOf(Flushable.class, sentrySdkHint, logger); } return true; } diff --git a/sentry/src/main/java/io/sentry/Scope.java b/sentry/src/main/java/io/sentry/Scope.java index 6ee070f6c8..331ae59f82 100644 --- a/sentry/src/main/java/io/sentry/Scope.java +++ b/sentry/src/main/java/io/sentry/Scope.java @@ -1,5 +1,6 @@ package io.sentry; +import io.sentry.hints.Hints; import io.sentry.protocol.Contexts; import io.sentry.protocol.Request; import io.sentry.protocol.User; @@ -288,15 +289,15 @@ Queue getBreadcrumbs() { * * @param callback the BeforeBreadcrumb callback * @param breadcrumb the breadcrumb - * @param hint the hint + * @param hints the hints * @return the mutated breadcrumb or null if dropped */ private @Nullable Breadcrumb executeBeforeBreadcrumb( final @NotNull SentryOptions.BeforeBreadcrumbCallback callback, @NotNull Breadcrumb breadcrumb, - final @Nullable Map hint) { + final @NotNull Hints hints) { try { - breadcrumb = callback.execute(breadcrumb, hint); + breadcrumb = callback.execute(breadcrumb, hints); } catch (Throwable e) { options .getLogger() @@ -317,17 +318,19 @@ Queue getBreadcrumbs() { * set * * @param breadcrumb the breadcrumb - * @param hint the hint + * @param hints the hint */ - public void addBreadcrumb( - @NotNull Breadcrumb breadcrumb, final @Nullable Map hint) { + public void addBreadcrumb(@NotNull Breadcrumb breadcrumb, @Nullable Hints hints) { if (breadcrumb == null) { return; } + if (hints == null) { + hints = new Hints(); + } SentryOptions.BeforeBreadcrumbCallback callback = options.getBeforeBreadcrumb(); if (callback != null) { - breadcrumb = executeBeforeBreadcrumb(callback, breadcrumb, hint); + breadcrumb = executeBeforeBreadcrumb(callback, breadcrumb, hints); } if (breadcrumb != null) { this.breadcrumbs.add(breadcrumb); diff --git a/sentry/src/main/java/io/sentry/Sentry.java b/sentry/src/main/java/io/sentry/Sentry.java index 008cc1a2ad..a3dbc6c143 100644 --- a/sentry/src/main/java/io/sentry/Sentry.java +++ b/sentry/src/main/java/io/sentry/Sentry.java @@ -2,6 +2,7 @@ import io.sentry.cache.EnvelopeCache; import io.sentry.config.PropertiesProviderFactory; +import io.sentry.hints.Hints; import io.sentry.protocol.SentryId; import io.sentry.protocol.User; import io.sentry.util.FileUtils; @@ -9,7 +10,6 @@ import java.lang.reflect.InvocationTargetException; import java.util.Date; import java.util.List; -import java.util.Map; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -281,12 +281,12 @@ public static synchronized void close() { * Captures the event. * * @param event the event - * @param hint SDK specific but provides high level information about the origin of the event + * @param hints SDK specific but provides high level information about the origin of the event * @return The Id (SentryId object) of the event */ public static @NotNull SentryId captureEvent( - final @NotNull SentryEvent event, final @Nullable Map hint) { - return getCurrentHub().captureEvent(event, hint); + final @NotNull SentryEvent event, final @Nullable Hints hints) { + return getCurrentHub().captureEvent(event, hints); } /** @@ -325,12 +325,12 @@ public static synchronized void close() { * Captures the exception. * * @param throwable The exception. - * @param hint SDK specific but provides high level information about the origin of the event + * @param hints SDK specific but provides high level information about the origin of the event * @return The Id (SentryId object) of the event */ public static @NotNull SentryId captureException( - final @NotNull Throwable throwable, final @Nullable Map hint) { - return getCurrentHub().captureException(throwable, hint); + final @NotNull Throwable throwable, final @Nullable Hints hints) { + return getCurrentHub().captureException(throwable, hints); } /** @@ -346,11 +346,11 @@ public static void captureUserFeedback(final @NotNull UserFeedback userFeedback) * Adds a breadcrumb to the current Scope * * @param breadcrumb the breadcrumb - * @param hint SDK specific but provides high level information about the origin of the event + * @param hints SDK specific but provides high level information about the origin of the event */ public static void addBreadcrumb( - final @NotNull Breadcrumb breadcrumb, final @Nullable Map hint) { - getCurrentHub().addBreadcrumb(breadcrumb, hint); + final @NotNull Breadcrumb breadcrumb, final @Nullable Hints hints) { + getCurrentHub().addBreadcrumb(breadcrumb, hints); } /** diff --git a/sentry/src/main/java/io/sentry/SentryClient.java b/sentry/src/main/java/io/sentry/SentryClient.java index 269574ca64..790434e6c9 100644 --- a/sentry/src/main/java/io/sentry/SentryClient.java +++ b/sentry/src/main/java/io/sentry/SentryClient.java @@ -5,6 +5,7 @@ import io.sentry.clientreport.DiscardReason; import io.sentry.exception.SentryEnvelopeException; import io.sentry.hints.DiskFlushNotification; +import io.sentry.hints.Hints; import io.sentry.protocol.Contexts; import io.sentry.protocol.SentryId; import io.sentry.protocol.SentryTransaction; @@ -59,8 +60,8 @@ public boolean isEnabled() { } private boolean shouldApplyScopeData( - final @NotNull SentryBaseEvent event, final @NotNull Map hint) { - if (HintUtils.shouldApplyScopeData(hint)) { + final @NotNull SentryBaseEvent event, final @NotNull Hints hints) { + if (HintUtils.shouldApplyScopeData(hints)) { return true; } else { options @@ -72,11 +73,11 @@ private boolean shouldApplyScopeData( @Override public @NotNull SentryId captureEvent( - @NotNull SentryEvent event, final @Nullable Scope scope, @Nullable Map hint) { + @NotNull SentryEvent event, final @Nullable Scope scope, @Nullable Hints hints) { Objects.requireNonNull(event, "SentryEvent is required."); - if (hint == null) { - hint = new HashMap<>(); + if (hints == null) { + hints = new Hints(); } options.getLogger().log(SentryLevel.DEBUG, "Capturing event: %s", event.getEventId()); @@ -97,11 +98,11 @@ private boolean shouldApplyScopeData( } } - if (shouldApplyScopeData(event, hint)) { + if (shouldApplyScopeData(event, hints)) { // Event has already passed through here before it was cached // Going through again could be reading data that is no longer relevant // i.e proguard id, app version, threads - event = applyScope(event, scope, hint); + event = applyScope(event, scope, hints); if (event == null) { options.getLogger().log(SentryLevel.DEBUG, "Event was dropped by applyScope"); @@ -109,10 +110,10 @@ private boolean shouldApplyScopeData( } } - event = processEvent(event, hint, options.getEventProcessors()); + event = processEvent(event, hints, options.getEventProcessors()); if (event != null) { - event = executeBeforeSend(event, hint); + event = executeBeforeSend(event, hints); if (event == null) { options.getLogger().log(SentryLevel.DEBUG, "Event was dropped by beforeSend"); @@ -132,7 +133,7 @@ private boolean shouldApplyScopeData( @Nullable Session session = null; if (event != null) { - session = updateSessionData(event, hint, scope); + session = updateSessionData(event, hints, scope); if (!sample()) { options @@ -172,11 +173,11 @@ private boolean shouldApplyScopeData( ? scope.getTransaction().traceState() : null; final boolean shouldSendAttachments = event != null; - List attachments = shouldSendAttachments ? getAttachments(scope, hint) : null; + List attachments = shouldSendAttachments ? getAttachments(scope, hints) : null; final SentryEnvelope envelope = buildEnvelope(event, attachments, session, traceState, null); if (envelope != null) { - transport.send(envelope, hint); + transport.send(envelope, hints); } } catch (IOException | SentryEnvelopeException e) { options.getLogger().log(SentryLevel.WARNING, e, "Capturing event %s failed.", sentryId); @@ -215,13 +216,13 @@ private boolean shouldSendSessionUpdateForDroppedEvent( } private @Nullable List getAttachments( - final @Nullable Scope scope, final @NotNull Map hint) { + final @Nullable Scope scope, final @NotNull Hints hints) { List attachments = null; if (scope != null) { attachments = scope.getAttachments(); } - final Object screenshotAttachment = hint.get(SENTRY_SCREENSHOT); + final Object screenshotAttachment = hints.get(SENTRY_SCREENSHOT); if (screenshotAttachment instanceof Attachment) { if (attachments == null) { @@ -285,11 +286,11 @@ private boolean shouldSendSessionUpdateForDroppedEvent( @Nullable private SentryEvent processEvent( @NotNull SentryEvent event, - final @NotNull Map hint, + final @NotNull Hints hints, final @NotNull List eventProcessors) { for (final EventProcessor processor : eventProcessors) { try { - event = processor.process(event, hint); + event = processor.process(event, hints); } catch (Throwable e) { options .getLogger() @@ -319,11 +320,11 @@ private SentryEvent processEvent( @Nullable private SentryTransaction processTransaction( @NotNull SentryTransaction transaction, - final @NotNull Map hint, + final @NotNull Hints hints, final @NotNull List eventProcessors) { for (final EventProcessor processor : eventProcessors) { try { - transaction = processor.process(transaction, hint); + transaction = processor.process(transaction, hints); } catch (Throwable e) { options .getLogger() @@ -393,18 +394,16 @@ public void captureUserFeedback(final @NotNull UserFeedback userFeedback) { * Updates the session data based on the event, hint and scope data * * @param event the SentryEvent - * @param hint the hint or null + * @param hints the hint or null * @param scope the Scope or null */ @TestOnly @Nullable Session updateSessionData( - final @NotNull SentryEvent event, - final @Nullable Map hint, - final @Nullable Scope scope) { + final @NotNull SentryEvent event, final @NotNull Hints hints, final @Nullable Scope scope) { Session clonedSession = null; - if (HintUtils.shouldApplyScopeData(hint)) { + if (HintUtils.shouldApplyScopeData(hints)) { if (scope != null) { clonedSession = scope.withSession( @@ -428,10 +427,9 @@ Session updateSessionData( } if (session.update(status, userAgent, crashedOrErrored)) { - Object sentrySdkHint = HintUtils.getSentrySdkHint(hint); // if hint is DiskFlushNotification, it means we have an uncaughtException // and we can end the session. - if (sentrySdkHint instanceof DiskFlushNotification) { + if (HintUtils.hasType(hints, DiskFlushNotification.class)) { session.end(); } } @@ -450,8 +448,7 @@ Session updateSessionData( @ApiStatus.Internal @Override - public void captureSession( - final @NotNull Session session, final @Nullable Map hint) { + public void captureSession(final @NotNull Session session, final @Nullable Hints hints) { Objects.requireNonNull(session, "Session is required."); if (session.getRelease() == null || session.getRelease().isEmpty()) { @@ -469,17 +466,21 @@ public void captureSession( return; } - captureEnvelope(envelope, hint); + captureEnvelope(envelope, hints); } @ApiStatus.Internal @Override public @NotNull SentryId captureEnvelope( - final @NotNull SentryEnvelope envelope, final @Nullable Map hint) { + final @NotNull SentryEnvelope envelope, @Nullable Hints hints) { Objects.requireNonNull(envelope, "SentryEnvelope is required."); + if (hints == null) { + hints = new Hints(); + } + try { - transport.send(envelope, hint); + transport.send(envelope, hints); } catch (IOException e) { options.getLogger().log(SentryLevel.ERROR, "Failed to capture envelope.", e); return SentryId.EMPTY_ID; @@ -497,12 +498,12 @@ public void captureSession( @NotNull SentryTransaction transaction, @Nullable TraceState traceState, final @Nullable Scope scope, - @Nullable Map hint, + @Nullable Hints hints, final @Nullable ProfilingTraceData profilingTraceData) { Objects.requireNonNull(transaction, "Transaction is required."); - if (hint == null) { - hint = new HashMap<>(); + if (hints == null) { + hints = new Hints(); } options @@ -514,11 +515,11 @@ public void captureSession( sentryId = transaction.getEventId(); } - if (shouldApplyScopeData(transaction, hint)) { + if (shouldApplyScopeData(transaction, hints)) { transaction = applyScope(transaction, scope); if (transaction != null && scope != null) { - transaction = processTransaction(transaction, hint, scope.getEventProcessors()); + transaction = processTransaction(transaction, hints, scope.getEventProcessors()); } if (transaction == null) { @@ -527,7 +528,7 @@ public void captureSession( } if (transaction != null) { - transaction = processTransaction(transaction, hint, options.getEventProcessors()); + transaction = processTransaction(transaction, hints, options.getEventProcessors()); } if (transaction == null) { @@ -539,13 +540,13 @@ public void captureSession( final SentryEnvelope envelope = buildEnvelope( transaction, - filterForTransaction(getAttachments(scope, hint)), + filterForTransaction(getAttachments(scope, hints)), null, traceState, profilingTraceData); if (envelope != null) { - transport.send(envelope, hint); + transport.send(envelope, hints); } else { sentryId = SentryId.EMPTY_ID; } @@ -574,9 +575,7 @@ public void captureSession( } private @Nullable SentryEvent applyScope( - @NotNull SentryEvent event, - final @Nullable Scope scope, - final @NotNull Map hint) { + @NotNull SentryEvent event, final @Nullable Scope scope, final @NotNull Hints hints) { if (scope != null) { applyScope(event, scope); @@ -596,7 +595,7 @@ public void captureSession( event.getContexts().setTrace(span.getSpanContext()); } - event = processEvent(event, hint, scope.getEventProcessors()); + event = processEvent(event, hints, scope.getEventProcessors()); } return event; } @@ -654,11 +653,11 @@ private void sortBreadcrumbsByDate( } private @Nullable SentryEvent executeBeforeSend( - @NotNull SentryEvent event, final @NotNull Map hint) { + @NotNull SentryEvent event, final @NotNull Hints hints) { final SentryOptions.BeforeSendCallback beforeSend = options.getBeforeSend(); if (beforeSend != null) { try { - event = beforeSend.execute(event, hint); + event = beforeSend.execute(event, hints); } catch (Throwable e) { options .getLogger() diff --git a/sentry/src/main/java/io/sentry/SentryOptions.java b/sentry/src/main/java/io/sentry/SentryOptions.java index 6eda907d3e..c1e1e28fa2 100644 --- a/sentry/src/main/java/io/sentry/SentryOptions.java +++ b/sentry/src/main/java/io/sentry/SentryOptions.java @@ -5,6 +5,7 @@ import io.sentry.clientreport.ClientReportRecorder; import io.sentry.clientreport.IClientReportRecorder; import io.sentry.clientreport.NoOpClientReportRecorder; +import io.sentry.hints.Hints; import io.sentry.protocol.SdkVersion; import io.sentry.transport.ITransportGate; import io.sentry.transport.NoOpEnvelopeCache; @@ -1593,11 +1594,11 @@ public interface BeforeSendCallback { * Mutates or drop an event before being sent * * @param event the event - * @param hint the hint, usually the source of the event + * @param hints the hints * @return the original event or the mutated event or null if event was dropped */ @Nullable - SentryEvent execute(@NotNull SentryEvent event, @Nullable Map hint); + SentryEvent execute(@NotNull SentryEvent event, @NotNull Hints hints); } /** The BeforeBreadcrumb callback */ @@ -1607,11 +1608,11 @@ public interface BeforeBreadcrumbCallback { * Mutates or drop a callback before being added * * @param breadcrumb the breadcrumb - * @param hint the hint, usually the source of the breadcrumb + * @param hints the hints, usually the source of the breadcrumb * @return the original breadcrumb or the mutated breadcrumb of null if breadcrumb was dropped */ @Nullable - Breadcrumb execute(@NotNull Breadcrumb breadcrumb, @Nullable Map hint); + Breadcrumb execute(@NotNull Breadcrumb breadcrumb, @NotNull Hints hints); } /** The traces sampler callback. */ diff --git a/sentry/src/main/java/io/sentry/SentryRuntimeEventProcessor.java b/sentry/src/main/java/io/sentry/SentryRuntimeEventProcessor.java index d031f0a61d..0daca97076 100644 --- a/sentry/src/main/java/io/sentry/SentryRuntimeEventProcessor.java +++ b/sentry/src/main/java/io/sentry/SentryRuntimeEventProcessor.java @@ -1,8 +1,8 @@ package io.sentry; +import io.sentry.hints.Hints; import io.sentry.protocol.SentryRuntime; import io.sentry.protocol.SentryTransaction; -import java.util.Map; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -23,13 +23,13 @@ public SentryRuntimeEventProcessor() { @Override public @NotNull SentryEvent process( - final @NotNull SentryEvent event, final @Nullable Map hint) { + final @NotNull SentryEvent event, final @Nullable Hints hints) { return process(event); } @Override public @NotNull SentryTransaction process( - final @NotNull SentryTransaction transaction, final @Nullable Map hint) { + final @NotNull SentryTransaction transaction, final @Nullable Hints hints) { return process(transaction); } diff --git a/sentry/src/main/java/io/sentry/TypeCheckHint.java b/sentry/src/main/java/io/sentry/TypeCheckHint.java index 417e848943..9bf5a79f14 100644 --- a/sentry/src/main/java/io/sentry/TypeCheckHint.java +++ b/sentry/src/main/java/io/sentry/TypeCheckHint.java @@ -2,6 +2,7 @@ import org.jetbrains.annotations.ApiStatus; +// TODO can this be an enum? /** Constants used for Type Check hints. */ public final class TypeCheckHint { diff --git a/sentry/src/main/java/io/sentry/UncaughtExceptionHandlerIntegration.java b/sentry/src/main/java/io/sentry/UncaughtExceptionHandlerIntegration.java index 08671dd61a..f7df56957e 100644 --- a/sentry/src/main/java/io/sentry/UncaughtExceptionHandlerIntegration.java +++ b/sentry/src/main/java/io/sentry/UncaughtExceptionHandlerIntegration.java @@ -1,17 +1,16 @@ package io.sentry; import static io.sentry.SentryLevel.ERROR; -import static io.sentry.TypeCheckHint.SENTRY_TYPE_CHECK_HINT; import io.sentry.exception.ExceptionMechanismException; import io.sentry.hints.DiskFlushNotification; import io.sentry.hints.Flushable; +import io.sentry.hints.Hints; import io.sentry.hints.SessionEnd; import io.sentry.protocol.Mechanism; +import io.sentry.util.HintUtils; import io.sentry.util.Objects; import java.io.Closeable; -import java.util.HashMap; -import java.util.Map; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import org.jetbrains.annotations.NotNull; @@ -97,10 +96,9 @@ public void uncaughtException(Thread thread, Throwable thrown) { final SentryEvent event = new SentryEvent(throwable); event.setLevel(SentryLevel.FATAL); - final Map hintMap = new HashMap<>(); - hintMap.put(SENTRY_TYPE_CHECK_HINT, hint); + final Hints hints = HintUtils.createWithTypeCheckHint(hint); - hub.captureEvent(event, hintMap); + hub.captureEvent(event, hints); // Block until the event is flushed to disk if (!hint.waitFlush()) { options diff --git a/sentry/src/main/java/io/sentry/cache/EnvelopeCache.java b/sentry/src/main/java/io/sentry/cache/EnvelopeCache.java index ad268702d5..87d697ff79 100644 --- a/sentry/src/main/java/io/sentry/cache/EnvelopeCache.java +++ b/sentry/src/main/java/io/sentry/cache/EnvelopeCache.java @@ -15,6 +15,7 @@ import io.sentry.SentryOptions; import io.sentry.Session; import io.sentry.hints.DiskFlushNotification; +import io.sentry.hints.Hints; import io.sentry.hints.SessionEnd; import io.sentry.hints.SessionStart; import io.sentry.transport.NoOpEnvelopeCache; @@ -78,22 +79,20 @@ private EnvelopeCache( } @Override - public void store( - final @NotNull SentryEnvelope envelope, final @Nullable Map hint) { + public void store(final @NotNull SentryEnvelope envelope, final @NotNull Hints hints) { Objects.requireNonNull(envelope, "Envelope is required."); rotateCacheIfNeeded(allEnvelopeFiles()); final File currentSessionFile = getCurrentSessionFile(); - Object sentrySdkHint = HintUtils.getSentrySdkHint(hint); - if (sentrySdkHint instanceof SessionEnd) { + if (HintUtils.hasType(hints, SessionEnd.class)) { if (!currentSessionFile.delete()) { options.getLogger().log(WARNING, "Current envelope doesn't exist."); } } - if (sentrySdkHint instanceof SessionStart) { + if (HintUtils.hasType(hints, SessionStart.class)) { boolean crashedLastRun = false; // TODO: should we move this to AppLifecycleIntegration? and do on SDK init? but it's too much @@ -201,7 +200,7 @@ public void store( writeEnvelopeToDisk(envelopeFile, envelope); // write file to the disk when its about to crash so crashedLastRun can be marked on restart - if (sentrySdkHint instanceof DiskFlushNotification) { + if (HintUtils.hasType(hints, DiskFlushNotification.class)) { writeCrashMarkerFile(); } } diff --git a/sentry/src/main/java/io/sentry/cache/IEnvelopeCache.java b/sentry/src/main/java/io/sentry/cache/IEnvelopeCache.java index 0ada72ea86..2d499fe49a 100644 --- a/sentry/src/main/java/io/sentry/cache/IEnvelopeCache.java +++ b/sentry/src/main/java/io/sentry/cache/IEnvelopeCache.java @@ -1,16 +1,15 @@ package io.sentry.cache; import io.sentry.SentryEnvelope; -import java.util.Map; +import io.sentry.hints.Hints; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; public interface IEnvelopeCache extends Iterable { - void store(@NotNull SentryEnvelope envelope, @Nullable Map hint); + void store(@NotNull SentryEnvelope envelope, @NotNull Hints hints); default void store(@NotNull SentryEnvelope envelope) { - store(envelope, null); + store(envelope, new Hints()); } void discard(@NotNull SentryEnvelope envelope); diff --git a/sentry/src/main/java/io/sentry/hints/Hints.java b/sentry/src/main/java/io/sentry/hints/Hints.java new file mode 100644 index 0000000000..51ea2b57ca --- /dev/null +++ b/sentry/src/main/java/io/sentry/hints/Hints.java @@ -0,0 +1,29 @@ +package io.sentry.hints; + +import java.util.HashMap; +import java.util.Map; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public final class Hints { + + private final @NotNull Map internalStorage = new HashMap(); + + public void set(@NotNull String hintType, @Nullable Object hint) { + internalStorage.put(hintType, hint); + } + + public @Nullable Object get(@NotNull String hintType) { + return internalStorage.get(hintType); + } + + // TODO maybe not public + public void remove(@NotNull String hintType) { + internalStorage.remove(hintType); + } + + // TODO addAttachment(one) + // TODO getAttachments(): List + // TODO setAttachments(list) + // TODO clearAttachments() +} diff --git a/sentry/src/main/java/io/sentry/transport/AsyncHttpTransport.java b/sentry/src/main/java/io/sentry/transport/AsyncHttpTransport.java index 32f5774813..d6ce0ec8b6 100644 --- a/sentry/src/main/java/io/sentry/transport/AsyncHttpTransport.java +++ b/sentry/src/main/java/io/sentry/transport/AsyncHttpTransport.java @@ -9,19 +9,18 @@ import io.sentry.clientreport.DiscardReason; import io.sentry.hints.Cached; import io.sentry.hints.DiskFlushNotification; +import io.sentry.hints.Hints; import io.sentry.hints.Retryable; import io.sentry.hints.SubmissionResult; import io.sentry.util.HintUtils; import io.sentry.util.LogUtils; import io.sentry.util.Objects; import java.io.IOException; -import java.util.Map; import java.util.concurrent.Future; import java.util.concurrent.RejectedExecutionHandler; import java.util.concurrent.ThreadFactory; import java.util.concurrent.TimeUnit; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; /** * {@link ITransport} implementation that executes request asynchronously in a blocking manner using @@ -66,19 +65,18 @@ public AsyncHttpTransport( } @Override - public void send(final @NotNull SentryEnvelope envelope, final @Nullable Map hint) + public void send(final @NotNull SentryEnvelope envelope, final @NotNull Hints hints) throws IOException { // For now no caching on envelopes IEnvelopeCache currentEnvelopeCache = envelopeCache; boolean cached = false; - Object sentrySdkHint = HintUtils.getSentrySdkHint(hint); - if (sentrySdkHint instanceof Cached) { + if (HintUtils.hasType(hints, Cached.class)) { currentEnvelopeCache = NoOpEnvelopeCache.getInstance(); cached = true; options.getLogger().log(SentryLevel.DEBUG, "Captured Envelope is already cached"); } - final SentryEnvelope filteredEnvelope = rateLimiter.filter(envelope, sentrySdkHint); + final SentryEnvelope filteredEnvelope = rateLimiter.filter(envelope, hints); if (filteredEnvelope == null) { if (cached) { @@ -86,7 +84,7 @@ public void send(final @NotNull SentryEnvelope envelope, final @Nullable Map future = executor.submit( - new EnvelopeSender(envelopeThatMayIncludeClientReport, hint, currentEnvelopeCache)); + new EnvelopeSender(envelopeThatMayIncludeClientReport, hints, currentEnvelopeCache)); if (future != null && future.isCancelled()) { options @@ -120,12 +118,11 @@ private static QueuedThreadPoolExecutor initExecutor( if (r instanceof EnvelopeSender) { final EnvelopeSender envelopeSender = (EnvelopeSender) r; - Object sentrySdkHint = HintUtils.getSentrySdkHint(envelopeSender.hint); - if (!(sentrySdkHint instanceof Cached)) { - envelopeCache.store(envelopeSender.envelope, envelopeSender.hint); + if (!HintUtils.hasType(envelopeSender.hints, Cached.class)) { + envelopeCache.store(envelopeSender.envelope, envelopeSender.hints); } - markHintWhenSendingFailed(sentrySdkHint, true); + markHintWhenSendingFailed(envelopeSender.hints, true); logger.log(SentryLevel.WARNING, "Envelope rejected"); } }; @@ -159,17 +156,12 @@ public void close() throws IOException { /** * It marks the hints when sending has failed, so it's not necessary to wait the timeout * - * @param sentrySdkHint the Hint + * @param hints the Hints * @param retry if event should be retried or not */ - private static void markHintWhenSendingFailed( - final @Nullable Object sentrySdkHint, final boolean retry) { - if (sentrySdkHint instanceof SubmissionResult) { - ((SubmissionResult) sentrySdkHint).setResult(false); - } - if (sentrySdkHint instanceof Retryable) { - ((Retryable) sentrySdkHint).setRetry(retry); - } + private static void markHintWhenSendingFailed(final @NotNull Hints hints, final boolean retry) { + HintUtils.runIfHasType(hints, SubmissionResult.class, result -> result.setResult(false)); + HintUtils.runIfHasType(hints, Retryable.class, retryable -> retryable.setRetry(retry)); } private static final class AsyncConnectionThreadFactory implements ThreadFactory { @@ -185,16 +177,16 @@ private static final class AsyncConnectionThreadFactory implements ThreadFactory private final class EnvelopeSender implements Runnable { private final @NotNull SentryEnvelope envelope; - private final @Nullable Map hint; + private final @NotNull Hints hints; private final @NotNull IEnvelopeCache envelopeCache; private final TransportResult failedResult = TransportResult.error(); EnvelopeSender( final @NotNull SentryEnvelope envelope, - final @Nullable Map hint, + final @NotNull Hints hints, final @NotNull IEnvelopeCache envelopeCache) { this.envelope = Objects.requireNonNull(envelope, "Envelope is required."); - this.hint = hint; + this.hints = hints; this.envelopeCache = Objects.requireNonNull(envelopeCache, "EnvelopeCache is required."); } @@ -208,26 +200,34 @@ public void run() { options.getLogger().log(SentryLevel.ERROR, e, "Envelope submission failed"); throw e; } finally { - Object sentrySdkHint = HintUtils.getSentrySdkHint(hint); - if (sentrySdkHint instanceof SubmissionResult) { - options - .getLogger() - .log(SentryLevel.DEBUG, "Marking envelope submission result: %s", result.isSuccess()); - ((SubmissionResult) sentrySdkHint).setResult(result.isSuccess()); - } + final TransportResult finalResult = result; + HintUtils.runIfHasType( + hints, + SubmissionResult.class, + (submissionResult) -> { + options + .getLogger() + .log( + SentryLevel.DEBUG, + "Marking envelope submission result: %s", + finalResult.isSuccess()); + submissionResult.setResult(finalResult.isSuccess()); + }); } } private @NotNull TransportResult flush() { TransportResult result = this.failedResult; - envelopeCache.store(envelope, hint); + envelopeCache.store(envelope, hints); - Object sentrySdkHint = HintUtils.getSentrySdkHint(hint); - if (sentrySdkHint instanceof DiskFlushNotification) { - ((DiskFlushNotification) sentrySdkHint).markFlushed(); - options.getLogger().log(SentryLevel.DEBUG, "Disk flush envelope fired"); - } + HintUtils.runIfHasType( + hints, + DiskFlushNotification.class, + (diskFlushNotification) -> { + diskFlushNotification.markFlushed(); + options.getLogger().log(SentryLevel.DEBUG, "Disk flush envelope fired"); + }); if (transportGate.isConnected()) { final SentryEnvelope envelopeWithClientReport = @@ -245,37 +245,48 @@ public void run() { // ignore e.g. 429 as we're not the ones actively dropping if (result.getResponseCode() >= 400 && result.getResponseCode() != 429) { - if (!(sentrySdkHint instanceof Retryable)) { - options - .getClientReportRecorder() - .recordLostEnvelope(DiscardReason.NETWORK_ERROR, envelopeWithClientReport); - } + HintUtils.runIfDoesNotHaveType( + hints, + Retryable.class, + (hint) -> { + options + .getClientReportRecorder() + .recordLostEnvelope(DiscardReason.NETWORK_ERROR, envelopeWithClientReport); + }); } throw new IllegalStateException(message); } } catch (IOException e) { // Failure due to IO is allowed to retry the event - if (sentrySdkHint instanceof Retryable) { - ((Retryable) sentrySdkHint).setRetry(true); - } else { - LogUtils.logIfNotRetryable(options.getLogger(), sentrySdkHint); - options - .getClientReportRecorder() - .recordLostEnvelope(DiscardReason.NETWORK_ERROR, envelopeWithClientReport); - } + HintUtils.runIfHasType( + hints, + Retryable.class, + (retryable) -> { + retryable.setRetry(true); + }, + (hint, clazz) -> { + LogUtils.logNotInstanceOf(clazz, hint, options.getLogger()); + options + .getClientReportRecorder() + .recordLostEnvelope(DiscardReason.NETWORK_ERROR, envelopeWithClientReport); + }); throw new IllegalStateException("Sending the event failed.", e); } } else { // If transportGate is blocking from sending, allowed to retry - if (sentrySdkHint instanceof Retryable) { - ((Retryable) sentrySdkHint).setRetry(true); - } else { - LogUtils.logIfNotRetryable(options.getLogger(), sentrySdkHint); - options - .getClientReportRecorder() - .recordLostEnvelope(DiscardReason.NETWORK_ERROR, envelope); - } + HintUtils.runIfHasType( + hints, + Retryable.class, + (retryable) -> { + retryable.setRetry(true); + }, + (hint, clazz) -> { + LogUtils.logNotInstanceOf(clazz, hint, options.getLogger()); + options + .getClientReportRecorder() + .recordLostEnvelope(DiscardReason.NETWORK_ERROR, envelope); + }); } return result; } diff --git a/sentry/src/main/java/io/sentry/transport/ITransport.java b/sentry/src/main/java/io/sentry/transport/ITransport.java index b528e575f3..96f3585bf4 100644 --- a/sentry/src/main/java/io/sentry/transport/ITransport.java +++ b/sentry/src/main/java/io/sentry/transport/ITransport.java @@ -1,19 +1,17 @@ package io.sentry.transport; import io.sentry.SentryEnvelope; +import io.sentry.hints.Hints; import java.io.Closeable; import java.io.IOException; -import java.util.Map; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; /** A transport is in charge of sending the event to the Sentry server. */ public interface ITransport extends Closeable { - void send(@NotNull SentryEnvelope envelope, @Nullable Map hint) - throws IOException; + void send(@NotNull SentryEnvelope envelope, @NotNull Hints hints) throws IOException; default void send(@NotNull SentryEnvelope envelope) throws IOException { - send(envelope, null); + send(envelope, new Hints()); } /** diff --git a/sentry/src/main/java/io/sentry/transport/NoOpEnvelopeCache.java b/sentry/src/main/java/io/sentry/transport/NoOpEnvelopeCache.java index 736cccb4af..5ca1f53d75 100644 --- a/sentry/src/main/java/io/sentry/transport/NoOpEnvelopeCache.java +++ b/sentry/src/main/java/io/sentry/transport/NoOpEnvelopeCache.java @@ -2,11 +2,10 @@ import io.sentry.SentryEnvelope; import io.sentry.cache.IEnvelopeCache; +import io.sentry.hints.Hints; import java.util.ArrayList; import java.util.Iterator; -import java.util.Map; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; public final class NoOpEnvelopeCache implements IEnvelopeCache { private static final NoOpEnvelopeCache instance = new NoOpEnvelopeCache(); @@ -16,7 +15,7 @@ public static NoOpEnvelopeCache getInstance() { } @Override - public void store(@NotNull SentryEnvelope envelope, @Nullable Map hint) {} + public void store(@NotNull SentryEnvelope envelope, @NotNull Hints hints) {} @Override public void discard(@NotNull SentryEnvelope envelope) {} diff --git a/sentry/src/main/java/io/sentry/transport/NoOpTransport.java b/sentry/src/main/java/io/sentry/transport/NoOpTransport.java index 435e0edd50..04040d8bf3 100644 --- a/sentry/src/main/java/io/sentry/transport/NoOpTransport.java +++ b/sentry/src/main/java/io/sentry/transport/NoOpTransport.java @@ -1,11 +1,10 @@ package io.sentry.transport; import io.sentry.SentryEnvelope; +import io.sentry.hints.Hints; import java.io.IOException; -import java.util.Map; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; @ApiStatus.Internal public final class NoOpTransport implements ITransport { @@ -19,7 +18,7 @@ public final class NoOpTransport implements ITransport { private NoOpTransport() {} @Override - public void send(final @NotNull SentryEnvelope envelope, final @Nullable Map hint) + public void send(final @NotNull SentryEnvelope envelope, final @NotNull Hints hints) throws IOException {} @Override diff --git a/sentry/src/main/java/io/sentry/transport/RateLimiter.java b/sentry/src/main/java/io/sentry/transport/RateLimiter.java index 57203b6197..56cc9253a6 100644 --- a/sentry/src/main/java/io/sentry/transport/RateLimiter.java +++ b/sentry/src/main/java/io/sentry/transport/RateLimiter.java @@ -9,8 +9,10 @@ import io.sentry.SentryLevel; import io.sentry.SentryOptions; import io.sentry.clientreport.DiscardReason; +import io.sentry.hints.Hints; import io.sentry.hints.Retryable; import io.sentry.hints.SubmissionResult; +import io.sentry.util.HintUtils; import io.sentry.util.StringUtils; import java.util.ArrayList; import java.util.Date; @@ -42,7 +44,7 @@ public RateLimiter(final @NotNull SentryOptions options) { } public @Nullable SentryEnvelope filter( - final @NotNull SentryEnvelope envelope, final @Nullable Object sentrySdkHint) { + final @NotNull SentryEnvelope envelope, final @NotNull Hints hints) { // Optimize for/No allocations if no items are under 429 List dropItems = null; for (SentryEnvelopeItem item : envelope.getItems()) { @@ -76,7 +78,7 @@ public RateLimiter(final @NotNull SentryOptions options) { if (toSend.isEmpty()) { options.getLogger().log(SentryLevel.INFO, "Envelope discarded due all items rate limited."); - markHintWhenSendingFailed(sentrySdkHint, false); + markHintWhenSendingFailed(hints, false); return null; } @@ -88,17 +90,12 @@ public RateLimiter(final @NotNull SentryOptions options) { /** * It marks the hints when sending has failed, so it's not necessary to wait the timeout * - * @param sentrySdkHint the Hint + * @param hints the Hints * @param retry if event should be retried or not */ - private static void markHintWhenSendingFailed( - final @Nullable Object sentrySdkHint, final boolean retry) { - if (sentrySdkHint instanceof SubmissionResult) { - ((SubmissionResult) sentrySdkHint).setResult(false); - } - if (sentrySdkHint instanceof Retryable) { - ((Retryable) sentrySdkHint).setRetry(retry); - } + private static void markHintWhenSendingFailed(final @NotNull Hints hints, final boolean retry) { + HintUtils.runIfHasType(hints, SubmissionResult.class, result -> result.setResult(false)); + HintUtils.runIfHasType(hints, Retryable.class, retryable -> retryable.setRetry(retry)); } /** diff --git a/sentry/src/main/java/io/sentry/transport/StdoutTransport.java b/sentry/src/main/java/io/sentry/transport/StdoutTransport.java index 2f3783f72b..676360ce54 100644 --- a/sentry/src/main/java/io/sentry/transport/StdoutTransport.java +++ b/sentry/src/main/java/io/sentry/transport/StdoutTransport.java @@ -2,11 +2,10 @@ import io.sentry.ISerializer; import io.sentry.SentryEnvelope; +import io.sentry.hints.Hints; import io.sentry.util.Objects; import java.io.IOException; -import java.util.Map; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; public final class StdoutTransport implements ITransport { @@ -17,7 +16,7 @@ public StdoutTransport(final @NotNull ISerializer serializer) { } @Override - public void send(final @NotNull SentryEnvelope envelope, final @Nullable Map hint) + public void send(final @NotNull SentryEnvelope envelope, final @NotNull Hints hints) throws IOException { Objects.requireNonNull(envelope, "SentryEnvelope is required"); diff --git a/sentry/src/main/java/io/sentry/util/HintUtils.java b/sentry/src/main/java/io/sentry/util/HintUtils.java index ce6c36632c..cf7bafb8fc 100644 --- a/sentry/src/main/java/io/sentry/util/HintUtils.java +++ b/sentry/src/main/java/io/sentry/util/HintUtils.java @@ -2,10 +2,12 @@ import static io.sentry.TypeCheckHint.SENTRY_TYPE_CHECK_HINT; +import io.sentry.ILogger; import io.sentry.hints.ApplyScopeData; import io.sentry.hints.Cached; -import java.util.Map; +import io.sentry.hints.Hints; import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; /** Util class for Applying or not scope's data to an event */ @@ -14,22 +16,97 @@ public final class HintUtils { private HintUtils() {} + @ApiStatus.Internal + public static Hints createWithTypeCheckHint(Object hint) { + Hints hints = new Hints(); + setTypeCheckHint(hints, hint); + return hints; + } + + @ApiStatus.Internal + public static void setTypeCheckHint(@NotNull Hints hints, Object hint) { + hints.set(SENTRY_TYPE_CHECK_HINT, hint); + } + + @ApiStatus.Internal + public static @Nullable Object getSentrySdkHint(@NotNull Hints hints) { + return hints.get(SENTRY_TYPE_CHECK_HINT); + } + + @ApiStatus.Internal + public static boolean hasType(@NotNull Hints hints, @NotNull Class clazz) { + final Object sentrySdkHint = getSentrySdkHint(hints); + return clazz.isInstance(sentrySdkHint); + } + + @ApiStatus.Internal + public static void runIfDoesNotHaveType( + @NotNull Hints hints, @NotNull Class clazz, SentryNullableConsumer lambda) { + runIfHasType( + hints, + clazz, + (ignored) -> {}, + (hint, clazz2) -> { + lambda.accept(hint); + }); + } + + @ApiStatus.Internal + public static void runIfHasType( + @NotNull Hints hints, @NotNull Class clazz, SentryConsumer lambda) { + runIfHasType(hints, clazz, lambda, (hint, clazz2) -> {}); + } + + @ApiStatus.Internal + public static void runIfHasTypeLogIfNot( + @NotNull Hints hints, @NotNull Class clazz, ILogger logger, SentryConsumer lambda) { + runIfHasType( + hints, + clazz, + lambda, + (sentrySdkHint, expectedClass) -> { + LogUtils.logNotInstanceOf(expectedClass, sentrySdkHint, logger); + }); + } + + @SuppressWarnings("unchecked") + @ApiStatus.Internal + public static void runIfHasType( + @NotNull Hints hints, + @NotNull Class clazz, + SentryConsumer lambda, + SentryFallbackConsumer fallbackLambda) { + Object sentrySdkHint = getSentrySdkHint(hints); + if (hasType(hints, clazz) && sentrySdkHint != null) { + lambda.accept((T) sentrySdkHint); + } else { + fallbackLambda.accept(sentrySdkHint, clazz); + } + } + /** * Scope's data should be applied if: Hint is of the type ApplyScopeData or Hint is not Cached * (this includes a null hint) * - * @param hint the hint * @return true if it should apply scope's data or false otherwise */ - public static boolean shouldApplyScopeData(final @Nullable Map hint) { - Object SentrySdkHint = getSentrySdkHint(hint); - return (!(SentrySdkHint instanceof Cached) || (SentrySdkHint instanceof ApplyScopeData)); + @ApiStatus.Internal + public static boolean shouldApplyScopeData(@NotNull Hints hints) { + return !hasType(hints, Cached.class) || hasType(hints, ApplyScopeData.class); } - public static @Nullable Object getSentrySdkHint(final @Nullable Map hint) { - if (hint == null) { - return null; - } - return hint.get(SENTRY_TYPE_CHECK_HINT); + @FunctionalInterface + public interface SentryConsumer { + void accept(@NotNull T t); + } + + @FunctionalInterface + public interface SentryNullableConsumer { + void accept(@Nullable T t); + } + + @FunctionalInterface + public interface SentryFallbackConsumer { + void accept(@Nullable Object sentrySdkHint, @NotNull Class clazz); } } diff --git a/sentry/src/main/java/io/sentry/util/LogUtils.java b/sentry/src/main/java/io/sentry/util/LogUtils.java index c594ec1d12..3c97a50e74 100644 --- a/sentry/src/main/java/io/sentry/util/LogUtils.java +++ b/sentry/src/main/java/io/sentry/util/LogUtils.java @@ -9,19 +9,30 @@ @ApiStatus.Internal public final class LogUtils { - public static void logIfNotFlushable( - final @NotNull ILogger logger, final @Nullable Object sentrySdkHint) { + public static void logNotInstanceOf( + final @NotNull Class expectedClass, + final @Nullable Object sentrySdkHint, + final @NotNull ILogger logger) { logger.log( SentryLevel.DEBUG, - "%s is not Flushable", - sentrySdkHint != null ? sentrySdkHint.getClass().getCanonicalName() : "Hint"); + "%s is not %s", + sentrySdkHint != null ? sentrySdkHint.getClass().getCanonicalName() : "Hint", + expectedClass.getCanonicalName()); } - public static void logIfNotRetryable( - final @NotNull ILogger logger, final @Nullable Object sentrySdkHint) { - logger.log( - SentryLevel.DEBUG, - "%s is not Retryable", - sentrySdkHint != null ? sentrySdkHint.getClass().getCanonicalName() : "Hint"); - } + // public static void logIfNotFlushable( + // final @NotNull ILogger logger, final @Nullable Object sentrySdkHint) { + // logger.log( + // SentryLevel.DEBUG, + // "%s is not Flushable", + // sentrySdkHint != null ? sentrySdkHint.getClass().getCanonicalName() : "Hint"); + // } + // + // public static void logIfNotRetryable( + // final @NotNull ILogger logger, final @Nullable Object sentrySdkHint) { + // logger.log( + // SentryLevel.DEBUG, + // "%s is not Retryable", + // sentrySdkHint != null ? sentrySdkHint.getClass().getCanonicalName() : "Hint"); + // } } diff --git a/sentry/src/test/java/io/sentry/CustomEventProcessor.kt b/sentry/src/test/java/io/sentry/CustomEventProcessor.kt index a519c9983f..b18ef86fcf 100644 --- a/sentry/src/test/java/io/sentry/CustomEventProcessor.kt +++ b/sentry/src/test/java/io/sentry/CustomEventProcessor.kt @@ -1,5 +1,7 @@ package io.sentry +import io.sentry.hints.Hints + class CustomEventProcessor : EventProcessor { - override fun process(event: SentryEvent, hint: Map?): SentryEvent? = null + override fun process(event: SentryEvent, hints: Hints): SentryEvent? = null } diff --git a/sentry/src/test/java/io/sentry/DirectoryProcessorTest.kt b/sentry/src/test/java/io/sentry/DirectoryProcessorTest.kt index 42783d5bfa..0f9fee4d37 100644 --- a/sentry/src/test/java/io/sentry/DirectoryProcessorTest.kt +++ b/sentry/src/test/java/io/sentry/DirectoryProcessorTest.kt @@ -9,6 +9,7 @@ import com.nhaarman.mockitokotlin2.verify import com.nhaarman.mockitokotlin2.whenever import io.sentry.hints.ApplyScopeData import io.sentry.protocol.User +import io.sentry.util.HintUtils import io.sentry.util.noFlushTimeout import java.io.File import java.nio.file.Files @@ -66,7 +67,7 @@ class DirectoryProcessorTest { whenever(fixture.serializer.deserialize(any(), eq(SentryEvent::class.java))).thenReturn(event) fixture.getSut().processDirectory(file) - verify(fixture.hub).captureEvent(any(), argWhere { it !is ApplyScopeData }) + verify(fixture.hub).captureEvent(any(), argWhere { !HintUtils.hasType(it, ApplyScopeData::class.java) }) } @Test diff --git a/sentry/src/test/java/io/sentry/DuplicateEventDetectionEventProcessorTest.kt b/sentry/src/test/java/io/sentry/DuplicateEventDetectionEventProcessorTest.kt index 22e569cc6a..5047983bac 100644 --- a/sentry/src/test/java/io/sentry/DuplicateEventDetectionEventProcessorTest.kt +++ b/sentry/src/test/java/io/sentry/DuplicateEventDetectionEventProcessorTest.kt @@ -1,6 +1,7 @@ package io.sentry import io.sentry.exception.ExceptionMechanismException +import io.sentry.hints.Hints import io.sentry.protocol.Mechanism import java.lang.RuntimeException import kotlin.test.Test @@ -25,9 +26,9 @@ class DuplicateEventDetectionEventProcessorTest { @Test fun `does not drop event if no previous event with same exception was processed`() { val processor = fixture.getSut() - processor.process(SentryEvent(), null) + processor.process(SentryEvent(), Hints()) - val result = processor.process(SentryEvent(RuntimeException()), null) + val result = processor.process(SentryEvent(RuntimeException()), Hints()) assertNotNull(result) } @@ -36,9 +37,9 @@ class DuplicateEventDetectionEventProcessorTest { fun `drops event with the same exception`() { val processor = fixture.getSut() val event = SentryEvent(RuntimeException()) - processor.process(event, null) + processor.process(event, Hints()) - val result = processor.process(event, null) + val result = processor.process(event, Hints()) assertNull(result) } @@ -46,9 +47,9 @@ class DuplicateEventDetectionEventProcessorTest { fun `drops event with mechanism exception having an exception that has already been processed`() { val processor = fixture.getSut() val event = SentryEvent(RuntimeException()) - processor.process(event, null) + processor.process(event, Hints()) - val result = processor.process(SentryEvent(ExceptionMechanismException(Mechanism(), event.throwable!!, Thread.currentThread())), null) + val result = processor.process(SentryEvent(ExceptionMechanismException(Mechanism(), event.throwable!!, Thread.currentThread())), Hints()) assertNull(result) } @@ -56,9 +57,9 @@ class DuplicateEventDetectionEventProcessorTest { fun `drops event with exception that has already been processed with event with mechanism exception`() { val processor = fixture.getSut() val sentryEvent = SentryEvent(ExceptionMechanismException(Mechanism(), RuntimeException(), Thread.currentThread())) - processor.process(sentryEvent, null) + processor.process(sentryEvent, Hints()) - val result = processor.process(SentryEvent((sentryEvent.throwable as ExceptionMechanismException).throwable), null) + val result = processor.process(SentryEvent((sentryEvent.throwable as ExceptionMechanismException).throwable), Hints()) assertNull(result) } @@ -67,9 +68,9 @@ class DuplicateEventDetectionEventProcessorTest { fun `drops event with the cause equal to exception in already processed event`() { val processor = fixture.getSut() val event = SentryEvent(RuntimeException()) - processor.process(event, null) + processor.process(event, Hints()) - val result = processor.process(SentryEvent(RuntimeException(event.throwable)), null) + val result = processor.process(SentryEvent(RuntimeException(event.throwable)), Hints()) assertNull(result) } @@ -78,9 +79,9 @@ class DuplicateEventDetectionEventProcessorTest { fun `drops event with any of the causes has been already processed`() { val processor = fixture.getSut() val event = SentryEvent(RuntimeException()) - processor.process(event, null) + processor.process(event, Hints()) - val result = processor.process(SentryEvent(RuntimeException(RuntimeException(event.throwable))), null) + val result = processor.process(SentryEvent(RuntimeException(RuntimeException(event.throwable))), Hints()) assertNull(result) } @@ -89,7 +90,7 @@ class DuplicateEventDetectionEventProcessorTest { fun `does not deduplicate is deduplication is disabled`() { val processor = fixture.getSut(enableDeduplication = false) val event = SentryEvent(RuntimeException()) - assertNotNull(processor.process(event, null)) - assertNotNull(processor.process(event, null)) + assertNotNull(processor.process(event, Hints())) + assertNotNull(processor.process(event, Hints())) } } diff --git a/sentry/src/test/java/io/sentry/EnvelopeSenderTest.kt b/sentry/src/test/java/io/sentry/EnvelopeSenderTest.kt index f9451945a7..91254d2447 100644 --- a/sentry/src/test/java/io/sentry/EnvelopeSenderTest.kt +++ b/sentry/src/test/java/io/sentry/EnvelopeSenderTest.kt @@ -7,9 +7,10 @@ import com.nhaarman.mockitokotlin2.mock import com.nhaarman.mockitokotlin2.verify import com.nhaarman.mockitokotlin2.verifyNoMoreInteractions import com.nhaarman.mockitokotlin2.whenever -import io.sentry.TypeCheckHint.SENTRY_TYPE_CHECK_HINT import io.sentry.cache.EnvelopeCache +import io.sentry.hints.Hints import io.sentry.hints.Retryable +import io.sentry.util.HintUtils import io.sentry.util.noFlushTimeout import java.io.File import java.nio.file.Files @@ -97,8 +98,8 @@ class EnvelopeSenderTest { val testFile = File(Files.createTempFile(tempDirectory, "send-cached-event-test", EnvelopeCache.SUFFIX_ENVELOPE_FILE).toUri()) testFile.deleteOnExit() - val hintsMap = mutableMapOf(SENTRY_TYPE_CHECK_HINT to mock()) - sut.processFile(testFile, hintsMap) + val hints = HintUtils.createWithTypeCheckHint(mock()) + sut.processFile(testFile, hints) verify(fixture.logger)!!.log(eq(SentryLevel.ERROR), eq(expected), eq("Failed to capture cached envelope %s"), eq(testFile.absolutePath)) verifyNoMoreInteractions(fixture.hub) assertFalse(testFile.exists()) @@ -111,7 +112,7 @@ class EnvelopeSenderTest { val sut = fixture.getSut() val testFile = File(Files.createTempFile(tempDirectory, "send-cached-event-test", EnvelopeCache.SUFFIX_ENVELOPE_FILE).toUri()) testFile.deleteOnExit() - sut.processFile(testFile, any()) + sut.processFile(testFile, Hints()) verify(fixture.logger)!!.log(eq(SentryLevel.ERROR), eq(expected), eq("Failed to capture cached envelope %s"), eq(testFile.absolutePath)) verifyNoMoreInteractions(fixture.hub) } diff --git a/sentry/src/test/java/io/sentry/HubTest.kt b/sentry/src/test/java/io/sentry/HubTest.kt index 1f8ff51759..eb1a31cd9e 100644 --- a/sentry/src/test/java/io/sentry/HubTest.kt +++ b/sentry/src/test/java/io/sentry/HubTest.kt @@ -14,11 +14,11 @@ import com.nhaarman.mockitokotlin2.times import com.nhaarman.mockitokotlin2.verify import com.nhaarman.mockitokotlin2.verifyNoMoreInteractions import com.nhaarman.mockitokotlin2.whenever -import io.sentry.TypeCheckHint.SENTRY_TYPE_CHECK_HINT import io.sentry.cache.EnvelopeCache import io.sentry.clientreport.ClientReportTestHelper.Companion.assertClientReport import io.sentry.clientreport.DiscardReason import io.sentry.clientreport.DiscardedEvent +import io.sentry.hints.Hints import io.sentry.hints.SessionEndHint import io.sentry.hints.SessionStartHint import io.sentry.protocol.SentryId @@ -265,7 +265,7 @@ class HubTest { sut.close() sut.captureEvent(SentryEvent()) - verify(mockClient, never()).captureEvent(any(), any>()) + verify(mockClient, never()).captureEvent(any(), any()) } @Test @@ -273,9 +273,9 @@ class HubTest { val (sut, mockClient) = getEnabledHub() val event = SentryEvent() - val hintsMap = mutableMapOf(SENTRY_TYPE_CHECK_HINT to { }) - sut.captureEvent(event, hintsMap) - verify(mockClient).captureEvent(eq(event), any(), eq(hintsMap)) + val hints = HintUtils.createWithTypeCheckHint({}) + sut.captureEvent(event, hints) + verify(mockClient).captureEvent(eq(event), any(), eq(hints)) } @Test @@ -283,11 +283,11 @@ class HubTest { val (sut, mockClient) = getEnabledHub() whenever(mockClient.captureEvent(any(), any(), anyOrNull())).thenReturn(SentryId(UUID.randomUUID())) val event = SentryEvent() - val hintsMap = mutableMapOf(SENTRY_TYPE_CHECK_HINT to { }) - sut.captureEvent(event, hintsMap) + val hints = HintUtils.createWithTypeCheckHint({}) + sut.captureEvent(event, hints) val lastEventId = sut.lastEventId sut.close() - sut.captureEvent(event, hintsMap) + sut.captureEvent(event, hints) assertEquals(lastEventId, sut.lastEventId) } @@ -296,9 +296,9 @@ class HubTest { val (sut, mockClient) = getEnabledHub() val event = SentryEvent() - val hintsMap = mutableMapOf(SENTRY_TYPE_CHECK_HINT to { }) - sut.captureEvent(event, hintsMap) - verify(mockClient).captureEvent(eq(event), any(), eq(hintsMap)) + val hints = HintUtils.createWithTypeCheckHint({}) + sut.captureEvent(event, hints) + verify(mockClient).captureEvent(eq(event), any(), eq(hints)) verify(mockClient, never()).captureSession(any(), any()) } @@ -307,9 +307,9 @@ class HubTest { val (sut, mockClient) = getEnabledHub() val event = SentryEvent() - val hintsMap = mutableMapOf(SENTRY_TYPE_CHECK_HINT to { }) - sut.captureEvent(event, hintsMap) - verify(mockClient).captureEvent(eq(event), any(), eq(hintsMap)) + val hints = HintUtils.createWithTypeCheckHint({}) + sut.captureEvent(event, hints) + verify(mockClient).captureEvent(eq(event), any(), eq(hints)) verify(mockClient, never()).captureSession(any(), any()) } @@ -323,10 +323,10 @@ class HubTest { val event = SentryEvent(exception) - val hintsMap = mutableMapOf(SENTRY_TYPE_CHECK_HINT to { }) - sut.captureEvent(event, hintsMap) + val hints = HintUtils.createWithTypeCheckHint({}) + sut.captureEvent(event, hints) assertEquals(span.spanContext, event.contexts.trace) - verify(mockClient).captureEvent(eq(event), any(), eq(hintsMap)) + verify(mockClient).captureEvent(eq(event), any(), eq(hints)) } @Test @@ -339,10 +339,10 @@ class HubTest { val event = SentryEvent(RuntimeException(rootCause)) - val hintsMap = mutableMapOf(SENTRY_TYPE_CHECK_HINT to { }) - sut.captureEvent(event, hintsMap) + val hints = HintUtils.createWithTypeCheckHint({}) + sut.captureEvent(event, hints) assertEquals(span.spanContext, event.contexts.trace) - verify(mockClient).captureEvent(eq(event), any(), eq(hintsMap)) + verify(mockClient).captureEvent(eq(event), any(), eq(hints)) } @Test @@ -356,10 +356,10 @@ class HubTest { val event = SentryEvent(RuntimeException(exceptionAssignedToSpan)) - val hintsMap = mutableMapOf(SENTRY_TYPE_CHECK_HINT to { }) - sut.captureEvent(event, hintsMap) + val hints = HintUtils.createWithTypeCheckHint({}) + sut.captureEvent(event, hints) assertEquals(span.spanContext, event.contexts.trace) - verify(mockClient).captureEvent(eq(event), any(), eq(hintsMap)) + verify(mockClient).captureEvent(eq(event), any(), eq(hints)) } @Test @@ -374,10 +374,10 @@ class HubTest { val originalSpanContext = SpanContext("op") event.contexts.trace = originalSpanContext - val hintsMap = mutableMapOf(SENTRY_TYPE_CHECK_HINT to { }) - sut.captureEvent(event, hintsMap) + val hints = HintUtils.createWithTypeCheckHint({}) + sut.captureEvent(event, hints) assertEquals(originalSpanContext, event.contexts.trace) - verify(mockClient).captureEvent(eq(event), any(), eq(hintsMap)) + verify(mockClient).captureEvent(eq(event), any(), eq(hints)) } @Test @@ -386,10 +386,10 @@ class HubTest { val event = SentryEvent(RuntimeException()) - val hintsMap = mutableMapOf(SENTRY_TYPE_CHECK_HINT to { }) - sut.captureEvent(event, hintsMap) + val hints = HintUtils.createWithTypeCheckHint({}) + sut.captureEvent(event, hints) assertNull(event.contexts.trace) - verify(mockClient).captureEvent(eq(event), any(), eq(hintsMap)) + verify(mockClient).captureEvent(eq(event), any(), eq(hints)) } //endregion @@ -455,8 +455,8 @@ class HubTest { fun `when captureException is called with a valid argument and hint, captureEvent on the client should be called`() { val (sut, mockClient) = getEnabledHub() - val hintsMap = mutableMapOf(SENTRY_TYPE_CHECK_HINT to Object()) - sut.captureException(Throwable(), hintsMap) + val hints = HintUtils.createWithTypeCheckHint({}) + sut.captureException(Throwable(), hints) verify(mockClient).captureEvent(any(), any(), any()) } @@ -973,7 +973,7 @@ class HubTest { sut.bindClient(mockClient) sut.startSession() - verify(mockClient).captureSession(any(), argWhere { HintUtils.getSentrySdkHint(it) is SessionStartHint }) + verify(mockClient).captureSession(any(), argWhere { HintUtils.hasType(it, SessionStartHint::class.java) }) } @Test @@ -989,8 +989,8 @@ class HubTest { sut.startSession() sut.startSession() - verify(mockClient).captureSession(any(), argWhere { HintUtils.getSentrySdkHint(it) is SessionEndHint }) - verify(mockClient, times(2)).captureSession(any(), argWhere { HintUtils.getSentrySdkHint(it) is SessionStartHint }) + verify(mockClient).captureSession(any(), argWhere { HintUtils.hasType(it, SessionEndHint::class.java) }) + verify(mockClient, times(2)).captureSession(any(), argWhere { HintUtils.hasType(it, SessionStartHint::class.java) }) } //endregion @@ -1039,8 +1039,8 @@ class HubTest { sut.startSession() sut.endSession() - verify(mockClient).captureSession(any(), argWhere { HintUtils.getSentrySdkHint(it) is SessionStartHint }) - verify(mockClient).captureSession(any(), argWhere { HintUtils.getSentrySdkHint(it) is SessionEndHint }) + verify(mockClient).captureSession(any(), argWhere { HintUtils.hasType(it, SessionStartHint::class.java) }) + verify(mockClient).captureSession(any(), argWhere { HintUtils.hasType(it, SessionEndHint::class.java) }) } @Test diff --git a/sentry/src/test/java/io/sentry/MainEventProcessorTest.kt b/sentry/src/test/java/io/sentry/MainEventProcessorTest.kt index 8ad57d829e..cd20824588 100644 --- a/sentry/src/test/java/io/sentry/MainEventProcessorTest.kt +++ b/sentry/src/test/java/io/sentry/MainEventProcessorTest.kt @@ -5,12 +5,13 @@ import com.nhaarman.mockitokotlin2.reset import com.nhaarman.mockitokotlin2.times import com.nhaarman.mockitokotlin2.verify import com.nhaarman.mockitokotlin2.whenever -import io.sentry.TypeCheckHint.SENTRY_TYPE_CHECK_HINT import io.sentry.hints.ApplyScopeData +import io.sentry.hints.Hints import io.sentry.protocol.DebugMeta import io.sentry.protocol.SdkVersion import io.sentry.protocol.SentryTransaction import io.sentry.protocol.User +import io.sentry.util.HintUtils import org.awaitility.kotlin.await import java.lang.RuntimeException import java.net.InetAddress @@ -64,7 +65,7 @@ class MainEventProcessorTest { val crashedThread = Thread.currentThread() var event = generateCrashedEvent(crashedThread) - event = sut.process(event, null) + event = sut.process(event, Hints()) assertNotNull(event.exceptions) { assertSame(crashedThread.id, it.first().threadId) @@ -85,7 +86,7 @@ class MainEventProcessorTest { val crashedThread = Thread() var event = generateCrashedEvent(crashedThread) - event = sut.process(event, null) + event = sut.process(event, Hints()) assertNotNull(event.threads) { threads -> assertTrue(threads.any { it.isCrashed == true }) @@ -97,7 +98,7 @@ class MainEventProcessorTest { val sut = fixture.getSut() val crashedThread = Thread.currentThread() var event = generateCrashedEvent(crashedThread) - event = sut.process(event, null) + event = sut.process(event, Hints()) assertEquals("release", event.release) assertEquals("environment", event.environment) @@ -113,8 +114,8 @@ class MainEventProcessorTest { val sut = fixture.getSut() val crashedThread = Thread.currentThread() var event = generateCrashedEvent(crashedThread) - val hintsMap = mutableMapOf(SENTRY_TYPE_CHECK_HINT to mock()) - event = sut.process(event, hintsMap) + val hints = HintUtils.createWithTypeCheckHint(mock()) + event = sut.process(event, hints) assertEquals("release", event.release) assertEquals("environment", event.environment) @@ -134,7 +135,7 @@ class MainEventProcessorTest { event.release = "eventRelease" event.serverName = "eventServerName" - event = sut.process(event, null) + event = sut.process(event, Hints()) assertEquals("eventRelease", event.release) assertEquals("eventEnvironment", event.environment) @@ -148,8 +149,8 @@ class MainEventProcessorTest { val crashedThread = Thread.currentThread() var event = generateCrashedEvent(crashedThread) - val hintsMap = mutableMapOf(SENTRY_TYPE_CHECK_HINT to CachedEvent()) - event = sut.process(event, hintsMap) + val hints = HintUtils.createWithTypeCheckHint(CachedEvent()) + event = sut.process(event, hints) assertNull(event.release) assertNull(event.environment) @@ -164,8 +165,8 @@ class MainEventProcessorTest { val crashedThread = Thread.currentThread() var event = generateCrashedEvent(crashedThread) - val hintsMap = mutableMapOf(SENTRY_TYPE_CHECK_HINT to CustomCachedApplyScopeDataHint()) - event = sut.process(event, hintsMap) + val hints = HintUtils.createWithTypeCheckHint(CustomCachedApplyScopeDataHint()) + event = sut.process(event, hints) assertEquals("release", event.release) assertEquals("environment", event.environment) @@ -181,7 +182,7 @@ class MainEventProcessorTest { val sut = fixture.getSut(attachThreads = false, attachStackTrace = false) var event = SentryEvent() - event = sut.process(event, null) + event = sut.process(event, Hints()) assertNull(event.threads) } @@ -191,7 +192,7 @@ class MainEventProcessorTest { val sut = fixture.getSut() var event = SentryEvent() - event = sut.process(event, null) + event = sut.process(event, Hints()) assertNotNull(event.threads) } @@ -201,7 +202,7 @@ class MainEventProcessorTest { val sut = fixture.getSut(attachThreads = false, attachStackTrace = true) var event = SentryEvent() - event = sut.process(event, null) + event = sut.process(event, Hints()) assertNotNull(event.threads) { assertEquals(1, it.count()) @@ -213,7 +214,7 @@ class MainEventProcessorTest { val sut = fixture.getSut(attachThreads = false, attachStackTrace = true) var event = SentryEvent(RuntimeException("error")) - event = sut.process(event, null) + event = sut.process(event, Hints()) assertNull(event.threads) } @@ -222,7 +223,7 @@ class MainEventProcessorTest { fun `sets sdkVersion in the event`() { val sut = fixture.getSut() val event = SentryEvent() - sut.process(event, null) + sut.process(event, Hints()) assertNotNull(event.sdk) { assertEquals(it.name, "test") assertEquals(it.version, "1.2.3") @@ -233,7 +234,7 @@ class MainEventProcessorTest { fun `when event and SentryOptions do not have environment set, sets production as environment`() { val sut = fixture.getSut(environment = null) val event = SentryEvent() - sut.process(event, null) + sut.process(event, Hints()) assertEquals("production", event.environment) } @@ -241,7 +242,7 @@ class MainEventProcessorTest { fun `when event does not have ip address set and sendDefaultPii is set to true, sets {{auto}} as the ip address`() { val sut = fixture.getSut(sendDefaultPii = true) val event = SentryEvent() - sut.process(event, null) + sut.process(event, Hints()) assertNotNull(event.user) { assertEquals("{{auto}}", it.ipAddress) } @@ -254,7 +255,7 @@ class MainEventProcessorTest { event.user = User().apply { ipAddress = "192.168.0.1" } - sut.process(event, null) + sut.process(event, Hints()) assertNotNull(event.user) { assertEquals("192.168.0.1", it.ipAddress) } @@ -265,7 +266,7 @@ class MainEventProcessorTest { val sut = fixture.getSut(sendDefaultPii = false) val event = SentryEvent() event.user = User() - sut.process(event, null) + sut.process(event, Hints()) assertNotNull(event.user) { assertNull(it.ipAddress) } @@ -276,7 +277,7 @@ class MainEventProcessorTest { val sut = fixture.getSut(environment = null) val event = SentryEvent() event.environment = "staging" - sut.process(event, null) + sut.process(event, Hints()) assertEquals("staging", event.environment) } @@ -284,7 +285,7 @@ class MainEventProcessorTest { fun `when event does not have environment set and SentryOptions have environment set, uses environment from SentryOptions`() { val sut = fixture.getSut(environment = "custom") val event = SentryEvent() - sut.process(event, null) + sut.process(event, Hints()) assertEquals("custom", event.environment) } @@ -292,7 +293,7 @@ class MainEventProcessorTest { fun `sets tags from SentryOptions`() { val sut = fixture.getSut(tags = mapOf("tag1" to "value1", "tag2" to "value2")) val event = SentryEvent() - sut.process(event, null) + sut.process(event, Hints()) assertNotNull(event.tags) { assertEquals("value1", it["tag1"]) assertEquals("value2", it["tag2"]) @@ -304,7 +305,7 @@ class MainEventProcessorTest { val sut = fixture.getSut(tags = mapOf("tag1" to "value1", "tag2" to "value2")) val event = SentryEvent() event.setTag("tag2", "event-tag-value") - sut.process(event, null) + sut.process(event, Hints()) assertNotNull(event.tags) { assertEquals("value1", it["tag1"]) assertEquals("event-tag-value", it["tag2"]) @@ -315,7 +316,7 @@ class MainEventProcessorTest { fun `sets servername retrieved from the local address`() { val processor = fixture.getSut(serverName = null, host = "aHost") val event = SentryEvent() - processor.process(event, null) + processor.process(event, Hints()) assertEquals("aHost", event.serverName) } @@ -323,7 +324,7 @@ class MainEventProcessorTest { fun `sets servername to null if retrieving takes longer time`() { val processor = fixture.getSut(serverName = null, host = "aHost", resolveHostDelay = 2000) val event = SentryEvent() - processor.process(event, null) + processor.process(event, Hints()) assertNull(event.serverName) } @@ -331,10 +332,10 @@ class MainEventProcessorTest { fun `uses cache to retrieve servername for subsequent events`() { val processor = fixture.getSut(serverName = null, host = "aHost", hostnameCacheDuration = 1000) val firstEvent = SentryEvent() - processor.process(firstEvent, null) + processor.process(firstEvent, Hints()) assertEquals("aHost", firstEvent.serverName) val secondEvent = SentryEvent() - processor.process(secondEvent, null) + processor.process(secondEvent, Hints()) assertEquals("aHost", secondEvent.serverName) verify(fixture.getLocalhost, times(1)).canonicalHostName } @@ -343,7 +344,7 @@ class MainEventProcessorTest { fun `when cache expires, retrieves new host name from the local address`() { val processor = fixture.getSut(serverName = null, host = "aHost") val firstEvent = SentryEvent() - processor.process(firstEvent, null) + processor.process(firstEvent, Hints()) assertEquals("aHost", firstEvent.serverName) reset(fixture.getLocalhost) @@ -351,7 +352,7 @@ class MainEventProcessorTest { await.untilAsserted { val secondEvent = SentryEvent() - processor.process(secondEvent, null) + processor.process(secondEvent, Hints()) assertEquals("newHost", secondEvent.serverName) } } @@ -361,7 +362,7 @@ class MainEventProcessorTest { val processor = fixture.getSut(serverName = null, host = "aHost") val event = SentryEvent() event.serverName = "eventHost" - processor.process(event, null) + processor.process(event, Hints()) assertEquals("eventHost", event.serverName) } @@ -369,7 +370,7 @@ class MainEventProcessorTest { fun `does not set serverName on events if serverName is set on SentryOptions`() { val processor = fixture.getSut(serverName = "optionsHost", host = "aHost") val event = SentryEvent() - processor.process(event, null) + processor.process(event, Hints()) assertEquals("optionsHost", event.serverName) } @@ -378,7 +379,7 @@ class MainEventProcessorTest { val processor = fixture.getSut(serverName = "optionsHost") var transaction = SentryTransaction(fixture.sentryTracer) - transaction = processor.process(transaction, null) + transaction = processor.process(transaction, Hints()) assertEquals("optionsHost", transaction.serverName) } @@ -388,7 +389,7 @@ class MainEventProcessorTest { val processor = fixture.getSut() var transaction = SentryTransaction(fixture.sentryTracer) - transaction = processor.process(transaction, null) + transaction = processor.process(transaction, Hints()) assertEquals("dist", transaction.dist) } @@ -398,7 +399,7 @@ class MainEventProcessorTest { val processor = fixture.getSut(sendDefaultPii = true) var transaction = SentryTransaction(fixture.sentryTracer) - transaction = processor.process(transaction, null) + transaction = processor.process(transaction, Hints()) assertNotNull(transaction.user) } @@ -409,8 +410,8 @@ class MainEventProcessorTest { var event = SentryEvent() - val hintsMap = mutableMapOf(SENTRY_TYPE_CHECK_HINT to CustomCachedApplyScopeDataHint()) - event = sut.process(event, hintsMap) + val hints = HintUtils.createWithTypeCheckHint(CustomCachedApplyScopeDataHint()) + event = sut.process(event, hints) assertNull(event.threads) } @@ -420,7 +421,7 @@ class MainEventProcessorTest { val sut = fixture.getSut(proguardUuid = "id1") var event = SentryEvent() - event = sut.process(event, null) + event = sut.process(event, Hints()) assertNotNull(event.debugMeta) { assertNotNull(it.images) { images -> @@ -436,7 +437,7 @@ class MainEventProcessorTest { var event = SentryEvent() event.debugMeta = DebugMeta() - event = sut.process(event, null) + event = sut.process(event, Hints()) assertNotNull(event.debugMeta) { assertNotNull(it.images) { images -> diff --git a/sentry/src/test/java/io/sentry/NoOpHubTest.kt b/sentry/src/test/java/io/sentry/NoOpHubTest.kt index 75529bd173..5f6e2ad749 100644 --- a/sentry/src/test/java/io/sentry/NoOpHubTest.kt +++ b/sentry/src/test/java/io/sentry/NoOpHubTest.kt @@ -1,6 +1,7 @@ package io.sentry import com.nhaarman.mockitokotlin2.mock +import io.sentry.hints.Hints import io.sentry.protocol.SentryId import kotlin.test.Test import kotlin.test.assertEquals @@ -29,7 +30,7 @@ class NoOpHubTest { @Test fun `captureTransaction returns empty SentryId`() = - assertEquals(SentryId.EMPTY_ID, sut.captureTransaction(mock(), mock>())) + assertEquals(SentryId.EMPTY_ID, sut.captureTransaction(mock(), mock())) @Test fun `captureException returns empty SentryId`() = diff --git a/sentry/src/test/java/io/sentry/OutboxSenderTest.kt b/sentry/src/test/java/io/sentry/OutboxSenderTest.kt index 00a91e66bf..acc5ccce53 100644 --- a/sentry/src/test/java/io/sentry/OutboxSenderTest.kt +++ b/sentry/src/test/java/io/sentry/OutboxSenderTest.kt @@ -9,11 +9,11 @@ import com.nhaarman.mockitokotlin2.never import com.nhaarman.mockitokotlin2.spy import com.nhaarman.mockitokotlin2.verify import com.nhaarman.mockitokotlin2.whenever -import io.sentry.TypeCheckHint.SENTRY_TYPE_CHECK_HINT import io.sentry.cache.EnvelopeCache import io.sentry.hints.Retryable import io.sentry.protocol.SentryId import io.sentry.protocol.SentryTransaction +import io.sentry.util.HintUtils import java.io.File import java.io.FileNotFoundException import java.nio.file.Files @@ -62,8 +62,8 @@ class OutboxSenderTest { val path = getTempEnvelope() assertTrue(File(path).exists()) // sanity check - val hintsMap = mutableMapOf(SENTRY_TYPE_CHECK_HINT to mock()) - sut.processEnvelopeFile(path, hintsMap) + val hints = HintUtils.createWithTypeCheckHint(mock()) + sut.processEnvelopeFile(path, hints) assertFalse(File(path).exists()) // Additionally make sure we have a error logged verify(fixture.logger).log(eq(SentryLevel.ERROR), any(), any()) @@ -78,8 +78,8 @@ class OutboxSenderTest { val path = getTempEnvelope() assertTrue(File(path).exists()) // sanity check - val hintsMap = mutableMapOf(SENTRY_TYPE_CHECK_HINT to mock()) - sut.processEnvelopeFile(path, hintsMap) + val hints = HintUtils.createWithTypeCheckHint(mock()) + sut.processEnvelopeFile(path, hints) verify(fixture.hub).captureEvent(eq(expected), any()) assertFalse(File(path).exists()) @@ -115,8 +115,8 @@ class OutboxSenderTest { val path = getTempEnvelope(fileName = "envelope-transaction.txt") assertTrue(File(path).exists()) - val hintsMap = mutableMapOf(SENTRY_TYPE_CHECK_HINT to mock()) - sut.processEnvelopeFile(path, hintsMap) + val hints = HintUtils.createWithTypeCheckHint(mock()) + sut.processEnvelopeFile(path, hints) verify(fixture.hub).captureTransaction( check { @@ -144,8 +144,8 @@ class OutboxSenderTest { val path = getTempEnvelope() assertTrue(File(path).exists()) // sanity check - val hintsMap = mutableMapOf(SENTRY_TYPE_CHECK_HINT to mock()) - sut.processEnvelopeFile(path, hintsMap) + val hints = HintUtils.createWithTypeCheckHint(mock()) + sut.processEnvelopeFile(path, hints) verify(fixture.hub).captureEvent(any(), any()) assertFalse(File(path).exists()) @@ -162,8 +162,8 @@ class OutboxSenderTest { val path = getTempEnvelope(fileName = "envelope_attachment.txt") assertTrue(File(path).exists()) // sanity check - val hintsMap = mutableMapOf(SENTRY_TYPE_CHECK_HINT to mock()) - sut.processEnvelopeFile(path, hintsMap) + val hints = HintUtils.createWithTypeCheckHint(mock()) + sut.processEnvelopeFile(path, hints) verify(fixture.hub).captureEnvelope(any(), any()) assertFalse(File(path).exists()) @@ -180,8 +180,8 @@ class OutboxSenderTest { val path = getTempEnvelope() assertTrue(File(path).exists()) // sanity check - val hintsMap = mutableMapOf(SENTRY_TYPE_CHECK_HINT to mock()) - sut.processEnvelopeFile(path, hintsMap) + val hints = HintUtils.createWithTypeCheckHint(mock()) + sut.processEnvelopeFile(path, hints) // Additionally make sure we have no errors logged verify(fixture.logger).log(eq(SentryLevel.ERROR), any(), any()) @@ -198,8 +198,8 @@ class OutboxSenderTest { val path = getTempEnvelope() assertTrue(File(path).exists()) // sanity check - val hintsMap = mutableMapOf(SENTRY_TYPE_CHECK_HINT to mock()) - sut.processEnvelopeFile(path, hintsMap) + val hints = HintUtils.createWithTypeCheckHint(mock()) + sut.processEnvelopeFile(path, hints) // Additionally make sure we have no errors logged verify(fixture.logger).log(eq(SentryLevel.ERROR), any(), any()) @@ -211,8 +211,8 @@ class OutboxSenderTest { fun `when processEnvelopeFile is called with a invalid path, logs error`() { val sut = fixture.getSut() - val hintsMap = mutableMapOf(SENTRY_TYPE_CHECK_HINT to mock()) - sut.processEnvelopeFile(File.separator + "i-hope-it-doesnt-exist" + File.separator + "file.txt", hintsMap) + val hints = HintUtils.createWithTypeCheckHint(mock()) + sut.processEnvelopeFile(File.separator + "i-hope-it-doesnt-exist" + File.separator + "file.txt", hints) verify(fixture.logger).log(eq(SentryLevel.ERROR), any(), argWhere { it is FileNotFoundException }) } diff --git a/sentry/src/test/java/io/sentry/ScopeTest.kt b/sentry/src/test/java/io/sentry/ScopeTest.kt index 3b65bb065d..3e67d0fb36 100644 --- a/sentry/src/test/java/io/sentry/ScopeTest.kt +++ b/sentry/src/test/java/io/sentry/ScopeTest.kt @@ -5,6 +5,7 @@ import com.nhaarman.mockitokotlin2.eq import com.nhaarman.mockitokotlin2.mock import com.nhaarman.mockitokotlin2.never import com.nhaarman.mockitokotlin2.verify +import io.sentry.hints.Hints import io.sentry.protocol.Request import io.sentry.protocol.User import io.sentry.test.callMethod @@ -858,7 +859,7 @@ class ScopeTest { private fun eventProcessor(): EventProcessor { return object : EventProcessor { - override fun process(event: SentryEvent, hint: MutableMap?): SentryEvent? { + override fun process(event: SentryEvent, hints: Hints): SentryEvent? { return event } } diff --git a/sentry/src/test/java/io/sentry/SentryClientTest.kt b/sentry/src/test/java/io/sentry/SentryClientTest.kt index 853f4de4b7..0429f583c7 100644 --- a/sentry/src/test/java/io/sentry/SentryClientTest.kt +++ b/sentry/src/test/java/io/sentry/SentryClientTest.kt @@ -15,7 +15,6 @@ import com.nhaarman.mockitokotlin2.verify import com.nhaarman.mockitokotlin2.verifyNoMoreInteractions import com.nhaarman.mockitokotlin2.whenever import io.sentry.TypeCheckHint.SENTRY_SCREENSHOT -import io.sentry.TypeCheckHint.SENTRY_TYPE_CHECK_HINT import io.sentry.clientreport.ClientReportTestHelper.Companion.assertClientReport import io.sentry.clientreport.DiscardReason import io.sentry.clientreport.DiscardedEvent @@ -24,6 +23,7 @@ import io.sentry.exception.SentryEnvelopeException import io.sentry.hints.ApplyScopeData import io.sentry.hints.Cached import io.sentry.hints.DiskFlushNotification +import io.sentry.hints.Hints import io.sentry.protocol.Mechanism import io.sentry.protocol.Request import io.sentry.protocol.SdkVersion @@ -34,6 +34,7 @@ import io.sentry.protocol.User import io.sentry.test.callMethod import io.sentry.transport.ITransport import io.sentry.transport.ITransportGate +import io.sentry.util.HintUtils import org.junit.Assert.assertArrayEquals import java.io.ByteArrayInputStream import java.io.ByteArrayOutputStream @@ -212,9 +213,9 @@ class SentryClientTest { fixture.sentryOptions.environment = "not to be applied" val sut = fixture.getSut() - val hintsMap = mutableMapOf(SENTRY_TYPE_CHECK_HINT to Object()) - sut.captureEvent(event, hintsMap) - verify(fixture.transport).send(any(), eq(hintsMap)) + val hints = HintUtils.createWithTypeCheckHint(Object()) + sut.captureEvent(event, hints) + verify(fixture.transport).send(any(), eq(hints)) } @Test @@ -531,8 +532,8 @@ class SentryClientTest { val scope = Scope(SentryOptions()) scope.level = SentryLevel.FATAL - val hintsMap = mutableMapOf(SENTRY_TYPE_CHECK_HINT to mock()) - sut.captureEvent(event, scope, hintsMap) + val hints = HintUtils.createWithTypeCheckHint(mock()) + sut.captureEvent(event, scope, hints) assertNotEquals(scope.level, event.level) } @@ -545,8 +546,8 @@ class SentryClientTest { val scope = Scope(SentryOptions()) scope.level = SentryLevel.FATAL - val hintsMap = mutableMapOf(SENTRY_TYPE_CHECK_HINT to Object()) - sut.captureEvent(event, scope, hintsMap) + val hints = HintUtils.createWithTypeCheckHint(Object()) + sut.captureEvent(event, scope, hints) assertEquals(scope.level, event.level) } @@ -559,8 +560,8 @@ class SentryClientTest { val scope = Scope(SentryOptions()) scope.level = SentryLevel.FATAL - val hintsMap = mutableMapOf(SENTRY_TYPE_CHECK_HINT to mock()) - sut.captureEvent(event, scope, hintsMap) + val hints = HintUtils.createWithTypeCheckHint(mock()) + sut.captureEvent(event, scope, hints) assertEquals(scope.level, event.level) } @@ -573,8 +574,8 @@ class SentryClientTest { val scope = Scope(SentryOptions()) scope.level = SentryLevel.FATAL - val hintsMap = mutableMapOf(SENTRY_TYPE_CHECK_HINT to CustomCachedApplyScopeDataHint()) - sut.captureEvent(event, scope, hintsMap) + val hints = HintUtils.createWithTypeCheckHint(CustomCachedApplyScopeDataHint()) + sut.captureEvent(event, scope, hints) assertEquals(scope.level, event.level) } @@ -786,7 +787,7 @@ class SentryClientTest { val event = SentryEvent().apply { exceptions = createNonHandledException() } - fixture.getSut().updateSessionData(event, null, scope) + fixture.getSut().updateSessionData(event, Hints(), scope) scope.withSession { assertEquals(Session.State.Crashed, it!!.status) } @@ -800,7 +801,7 @@ class SentryClientTest { val session = it.current val level = session.status val event = SentryEvent() - fixture.getSut().updateSessionData(event, null, scope) + fixture.getSut().updateSessionData(event, Hints(), scope) assertEquals(level, session.status) } } @@ -812,7 +813,7 @@ class SentryClientTest { val event = SentryEvent().apply { exceptions = createNonHandledException() } - fixture.getSut().updateSessionData(event, null, scope) + fixture.getSut().updateSessionData(event, Hints(), scope) scope.withSession { assertEquals(1, it!!.errorCount()) } @@ -827,7 +828,7 @@ class SentryClientTest { val event = SentryEvent().apply { setExceptions(exceptions) } - fixture.getSut().updateSessionData(event, null, scope) + fixture.getSut().updateSessionData(event, Hints(), scope) scope.withSession { assertEquals(1, it!!.errorCount()) } @@ -841,7 +842,7 @@ class SentryClientTest { val session = it.current val errorCount = session.errorCount() val event = SentryEvent() - fixture.getSut().updateSessionData(event, null, scope) + fixture.getSut().updateSessionData(event, Hints(), scope) assertEquals(errorCount, session.errorCount()) } } @@ -856,7 +857,7 @@ class SentryClientTest { headers = mutableMapOf("user-agent" to "jamesBond") } } - fixture.getSut().updateSessionData(event, null, scope) + fixture.getSut().updateSessionData(event, Hints(), scope) scope.withSession { assertEquals("jamesBond", it!!.userAgent) } @@ -875,7 +876,7 @@ class SentryClientTest { headers = mutableMapOf() } } - fixture.getSut().updateSessionData(event, null, scope) + fixture.getSut().updateSessionData(event, Hints(), scope) assertEquals(userAgent, session.userAgent) } } @@ -884,7 +885,7 @@ class SentryClientTest { fun `When capture an event and there's no session, do nothing`() { val scope = Scope(fixture.sentryOptions) val event = SentryEvent() - fixture.getSut().updateSessionData(event, null, scope) + fixture.getSut().updateSessionData(event, Hints(), scope) scope.withSession { assertNull(it) } @@ -1281,7 +1282,7 @@ class SentryClientTest { fun `screenshot is added to the envelope from the hint`() { val sut = fixture.getSut() val attachment = Attachment.fromScreenshot(byteArrayOf()) - val hints = mapOf(SENTRY_SCREENSHOT to attachment) + val hints = Hints().also { it.set(SENTRY_SCREENSHOT, attachment) } sut.captureEvent(SentryEvent(), hints) @@ -1301,7 +1302,7 @@ class SentryClientTest { fixture.sentryOptions.beforeSend = CustomBeforeSendCallback() val sut = fixture.getSut() val attachment = Attachment.fromScreenshot(byteArrayOf()) - val hints = mutableMapOf(SENTRY_SCREENSHOT to attachment) + val hints = Hints().also { it.set(SENTRY_SCREENSHOT, attachment) } sut.captureEvent(SentryEvent(), hints) @@ -1639,8 +1640,8 @@ class SentryClientTest { } class CustomBeforeSendCallback : SentryOptions.BeforeSendCallback { - override fun execute(event: SentryEvent, hint: MutableMap?): SentryEvent? { - hint?.remove(SENTRY_SCREENSHOT) + override fun execute(event: SentryEvent, hints: Hints): SentryEvent? { + hints.remove(SENTRY_SCREENSHOT) return event } @@ -1802,7 +1803,7 @@ class SentryClientTest { private fun eventProcessorThrows(): EventProcessor { return object : EventProcessor { - override fun process(event: SentryEvent, hint: Map?): SentryEvent? { + override fun process(event: SentryEvent, hints: Hints): SentryEvent? { throw Throwable() } } diff --git a/sentry/src/test/java/io/sentry/cache/EnvelopeCacheTest.kt b/sentry/src/test/java/io/sentry/cache/EnvelopeCacheTest.kt index 76400ef545..9c8d95b785 100644 --- a/sentry/src/test/java/io/sentry/cache/EnvelopeCacheTest.kt +++ b/sentry/src/test/java/io/sentry/cache/EnvelopeCacheTest.kt @@ -13,13 +13,13 @@ import io.sentry.SentryEvent import io.sentry.SentryLevel import io.sentry.SentryOptions import io.sentry.Session -import io.sentry.TypeCheckHint.SENTRY_TYPE_CHECK_HINT import io.sentry.cache.EnvelopeCache.PREFIX_CURRENT_SESSION_FILE import io.sentry.cache.EnvelopeCache.SUFFIX_CURRENT_SESSION_FILE import io.sentry.hints.DiskFlushNotification import io.sentry.hints.SessionEndHint import io.sentry.hints.SessionStartHint import io.sentry.protocol.User +import io.sentry.util.HintUtils import java.io.File import java.nio.file.Files import java.nio.file.Path @@ -92,8 +92,8 @@ class EnvelopeCacheTest { val envelope = SentryEnvelope.from(fixture.serializer, createSession(), null) - val hintsMap = mutableMapOf(SENTRY_TYPE_CHECK_HINT to SessionStartHint()) - cache.store(envelope, hintsMap) + val hints = HintUtils.createWithTypeCheckHint(SessionStartHint()) + cache.store(envelope, hints) val currentFile = File(fixture.options.cacheDirPath!!, "$PREFIX_CURRENT_SESSION_FILE$SUFFIX_CURRENT_SESSION_FILE") assertTrue(currentFile.exists()) @@ -109,14 +109,14 @@ class EnvelopeCacheTest { val envelope = SentryEnvelope.from(fixture.serializer, createSession(), null) - val hintsMap = mutableMapOf(SENTRY_TYPE_CHECK_HINT to SessionStartHint()) - cache.store(envelope, hintsMap) + val hints = HintUtils.createWithTypeCheckHint(SessionStartHint()) + cache.store(envelope, hints) val currentFile = File(fixture.options.cacheDirPath!!, "$PREFIX_CURRENT_SESSION_FILE$SUFFIX_CURRENT_SESSION_FILE") assertTrue(currentFile.exists()) - hintsMap[SENTRY_TYPE_CHECK_HINT] = SessionEndHint() - cache.store(envelope, hintsMap) + HintUtils.setTypeCheckHint(hints, SessionEndHint()) + cache.store(envelope, hints) assertFalse(currentFile.exists()) file.deleteRecursively() @@ -130,8 +130,8 @@ class EnvelopeCacheTest { val envelope = SentryEnvelope.from(fixture.serializer, createSession(), null) - val hintsMap = mutableMapOf(SENTRY_TYPE_CHECK_HINT to SessionStartHint()) - cache.store(envelope, hintsMap) + val hints = HintUtils.createWithTypeCheckHint(SessionStartHint()) + cache.store(envelope, hints) val currentFile = File(fixture.options.cacheDirPath!!, "$PREFIX_CURRENT_SESSION_FILE$SUFFIX_CURRENT_SESSION_FILE") assertTrue(currentFile.exists()) @@ -150,12 +150,12 @@ class EnvelopeCacheTest { val envelope = SentryEnvelope.from(fixture.serializer, createSession(), null) - val hintsMap = mutableMapOf(SENTRY_TYPE_CHECK_HINT to SessionStartHint()) - cache.store(envelope, hintsMap) + val hints = HintUtils.createWithTypeCheckHint(SessionStartHint()) + cache.store(envelope, hints) val newEnvelope = SentryEnvelope.from(fixture.serializer, createSession(), null) - cache.store(newEnvelope, hintsMap) + cache.store(newEnvelope, hints) verify(fixture.logger).log(eq(SentryLevel.WARNING), eq("Current session is not ended, we'd need to end it.")) } @@ -170,12 +170,12 @@ class EnvelopeCacheTest { val envelope = SentryEnvelope.from(fixture.serializer, createSession(), null) - val hintsMap = mutableMapOf(SENTRY_TYPE_CHECK_HINT to SessionStartHint()) - cache.store(envelope, hintsMap) + val hints = HintUtils.createWithTypeCheckHint(SessionStartHint()) + cache.store(envelope, hints) val newEnvelope = SentryEnvelope.from(fixture.serializer, createSession(), null) - cache.store(newEnvelope, hintsMap) + cache.store(newEnvelope, hints) verify(fixture.logger).log(eq(SentryLevel.INFO), eq("Crash marker file exists, last Session is gonna be Crashed.")) assertFalse(markerFile.exists()) file.deleteRecursively() @@ -192,12 +192,12 @@ class EnvelopeCacheTest { markerFile.writeText(charset = Charsets.UTF_8, text = date) val envelope = SentryEnvelope.from(fixture.serializer, createSession(), null) - val hintsMap = mutableMapOf(SENTRY_TYPE_CHECK_HINT to SessionStartHint()) - cache.store(envelope, hintsMap) + val hints = HintUtils.createWithTypeCheckHint(SessionStartHint()) + cache.store(envelope, hints) val newEnvelope = SentryEnvelope.from(fixture.serializer, createSession(), null) - cache.store(newEnvelope, hintsMap) + cache.store(newEnvelope, hints) assertFalse(markerFile.exists()) file.deleteRecursively() File(fixture.options.cacheDirPath!!).deleteRecursively() @@ -214,15 +214,15 @@ class EnvelopeCacheTest { val envelope = SentryEnvelope.from(fixture.serializer, createSession(), null) - val hintsMap = mutableMapOf(SENTRY_TYPE_CHECK_HINT to SessionStartHint()) - cache.store(envelope, hintsMap) + val hints = HintUtils.createWithTypeCheckHint(SessionStartHint()) + cache.store(envelope, hints) val newEnvelope = SentryEnvelope.from(fixture.serializer, createSession(), null) // since the first store call would set as readCrashedLastRun=true SentryCrashLastRunState.getInstance().reset() - cache.store(newEnvelope, hintsMap) + cache.store(newEnvelope, hints) verify(fixture.logger).log(eq(SentryLevel.INFO), eq("Crash marker file exists, last Session is gonna be Crashed.")) assertFalse(markerFile.exists()) file.deleteRecursively() @@ -241,8 +241,8 @@ class EnvelopeCacheTest { val envelope = SentryEnvelope.from(fixture.serializer, createSession(), null) - val hintsMap = mutableMapOf(SENTRY_TYPE_CHECK_HINT to SessionStartHint()) - cache.store(envelope, hintsMap) + val hints = HintUtils.createWithTypeCheckHint(SessionStartHint()) + cache.store(envelope, hints) // passing empty string since readCrashedLastRun is already set assertTrue(SentryCrashLastRunState.getInstance().isCrashedLastRun("", false)!!) @@ -258,8 +258,8 @@ class EnvelopeCacheTest { val envelope = SentryEnvelope.from(fixture.serializer, SentryEvent(), null) - val hintsMap = mutableMapOf(SENTRY_TYPE_CHECK_HINT to DiskFlushHint()) - cache.store(envelope, hintsMap) + val hints = HintUtils.createWithTypeCheckHint(DiskFlushHint()) + cache.store(envelope, hints) assertTrue(markerFile.exists()) } diff --git a/sentry/src/test/java/io/sentry/clientreport/ClientReportTest.kt b/sentry/src/test/java/io/sentry/clientreport/ClientReportTest.kt index 96c7fdedd7..adae6a946c 100644 --- a/sentry/src/test/java/io/sentry/clientreport/ClientReportTest.kt +++ b/sentry/src/test/java/io/sentry/clientreport/ClientReportTest.kt @@ -11,14 +11,15 @@ import io.sentry.SentryEnvelopeItem import io.sentry.SentryEvent import io.sentry.SentryOptions import io.sentry.Session -import io.sentry.TypeCheckHint import io.sentry.UserFeedback import io.sentry.dsnString import io.sentry.hints.DiskFlushNotification +import io.sentry.hints.Hints import io.sentry.hints.Retryable import io.sentry.protocol.SentryId import io.sentry.protocol.SentryTransaction import io.sentry.protocol.User +import io.sentry.util.HintUtils import java.time.LocalDateTime import java.time.ZoneId import java.time.temporal.ChronoUnit @@ -149,13 +150,13 @@ class ClientReportTest { class DropEverythingEventProcessor : EventProcessor { - override fun process(event: SentryEvent, hint: MutableMap?): SentryEvent? { + override fun process(event: SentryEvent, hints: Hints): SentryEvent? { return null } override fun process( transaction: SentryTransaction, - hint: MutableMap? + hints: Hints ): SentryTransaction? { return null } @@ -193,9 +194,9 @@ class ClientReportTestHelper(val options: SentryOptions) { } companion object { - fun retryableHint() = mutableMapOf(TypeCheckHint.SENTRY_TYPE_CHECK_HINT to TestRetryable()) - fun diskFlushNotificationHint() = mutableMapOf(TypeCheckHint.SENTRY_TYPE_CHECK_HINT to TestDiskFlushNotification()) - fun retryableDiskFlushNotificationHint() = mutableMapOf(TypeCheckHint.SENTRY_TYPE_CHECK_HINT to TestRetryableDiskFlushNotification()) + fun retryableHint() = HintUtils.createWithTypeCheckHint(TestRetryable()) + fun diskFlushNotificationHint() = HintUtils.createWithTypeCheckHint(TestDiskFlushNotification()) + fun retryableDiskFlushNotificationHint() = HintUtils.createWithTypeCheckHint(TestRetryableDiskFlushNotification()) fun assertClientReport(clientReportRecorder: IClientReportRecorder, expectedEvents: List) { val recorder = clientReportRecorder as ClientReportRecorder diff --git a/sentry/src/test/java/io/sentry/transport/AsyncHttpTransportTest.kt b/sentry/src/test/java/io/sentry/transport/AsyncHttpTransportTest.kt index 31ed3f6287..1af9cac6ed 100644 --- a/sentry/src/test/java/io/sentry/transport/AsyncHttpTransportTest.kt +++ b/sentry/src/test/java/io/sentry/transport/AsyncHttpTransportTest.kt @@ -17,10 +17,10 @@ import io.sentry.SentryEvent import io.sentry.SentryOptions import io.sentry.SentryOptionsManipulator import io.sentry.Session -import io.sentry.TypeCheckHint.SENTRY_TYPE_CHECK_HINT import io.sentry.clientreport.NoOpClientReportRecorder import io.sentry.dsnString import io.sentry.protocol.User +import io.sentry.util.HintUtils import java.io.IOException import kotlin.test.Test import kotlin.test.assertEquals @@ -184,8 +184,8 @@ class AsyncHttpTransportTest { whenever(fixture.rateLimiter.filter(any(), anyOrNull())).thenReturn(null) // when - val hintsMap = mutableMapOf(SENTRY_TYPE_CHECK_HINT to CachedEvent()) - fixture.getSUT().send(envelope, hintsMap) + val hints = HintUtils.createWithTypeCheckHint(CachedEvent()) + fixture.getSUT().send(envelope, hints) // then verify(fixture.sentryOptions.envelopeDiskCache).discard(any()) @@ -242,8 +242,8 @@ class AsyncHttpTransportTest { val envelope = SentryEnvelope.from(fixture.sentryOptions.serializer, ev, null) // when - val hintsMap = mutableMapOf(SENTRY_TYPE_CHECK_HINT to CachedEvent()) - fixture.getSUT().send(envelope, hintsMap) + val hints = HintUtils.createWithTypeCheckHint(CachedEvent()) + fixture.getSUT().send(envelope, hints) // then verify(fixture.sentryOptions.envelopeDiskCache).discard(any()) diff --git a/sentry/src/test/java/io/sentry/transport/RateLimiterTest.kt b/sentry/src/test/java/io/sentry/transport/RateLimiterTest.kt index c75cc08dd8..59006bf2ef 100644 --- a/sentry/src/test/java/io/sentry/transport/RateLimiterTest.kt +++ b/sentry/src/test/java/io/sentry/transport/RateLimiterTest.kt @@ -22,6 +22,7 @@ import io.sentry.TransactionContext import io.sentry.UserFeedback import io.sentry.clientreport.DiscardReason import io.sentry.clientreport.IClientReportRecorder +import io.sentry.hints.Hints import io.sentry.protocol.SentryId import io.sentry.protocol.SentryTransaction import io.sentry.protocol.User @@ -63,7 +64,7 @@ class RateLimiterTest { rateLimiter.updateRetryAfterLimits("50:transaction:key, 1:default;error;security:organization", null, 1) - val result = rateLimiter.filter(envelope, null) + val result = rateLimiter.filter(envelope, Hints()) assertNotNull(result) assertEquals(1, result.items.count()) } @@ -79,7 +80,7 @@ class RateLimiterTest { rateLimiter.updateRetryAfterLimits("50:transaction:key, 2700:default;error;security:organization", null, 1) - val result = rateLimiter.filter(envelope, null) + val result = rateLimiter.filter(envelope, Hints()) assertNull(result) } @@ -94,7 +95,7 @@ class RateLimiterTest { rateLimiter.updateRetryAfterLimits("1:transaction:key, 1:default;error;security:organization", null, 1) - val result = rateLimiter.filter(envelope, null) + val result = rateLimiter.filter(envelope, Hints()) assertNotNull(result) assertEquals(2, result.items.count()) } @@ -108,7 +109,7 @@ class RateLimiterTest { rateLimiter.updateRetryAfterLimits("50::key", null, 1) - val result = rateLimiter.filter(envelope, null) + val result = rateLimiter.filter(envelope, Hints()) assertNull(result) } @@ -121,7 +122,7 @@ class RateLimiterTest { rateLimiter.updateRetryAfterLimits("1::key, 60:default;error;security:organization", null, 1) - val result = rateLimiter.filter(envelope, null) + val result = rateLimiter.filter(envelope, Hints()) assertNull(result) } @@ -134,7 +135,7 @@ class RateLimiterTest { rateLimiter.updateRetryAfterLimits("60:error:key, 1:error:organization", null, 1) - val result = rateLimiter.filter(envelope, null) + val result = rateLimiter.filter(envelope, Hints()) assertNull(result) } @@ -147,7 +148,7 @@ class RateLimiterTest { rateLimiter.updateRetryAfterLimits("1:error:key, 5:error:organization", null, 1) - val result = rateLimiter.filter(envelope, null) + val result = rateLimiter.filter(envelope, Hints()) assertNull(result) } @@ -160,7 +161,7 @@ class RateLimiterTest { rateLimiter.updateRetryAfterLimits(null, null, 429) - val result = rateLimiter.filter(envelope, null) + val result = rateLimiter.filter(envelope, Hints()) assertNull(result) } @@ -185,7 +186,7 @@ class RateLimiterTest { val envelope = SentryEnvelope(SentryEnvelopeHeader(), arrayListOf(eventItem, userFeedbackItem, sessionItem, attachmentItem)) rateLimiter.updateRetryAfterLimits(null, null, 429) - val result = rateLimiter.filter(envelope, null) + val result = rateLimiter.filter(envelope, Hints()) assertNull(result) @@ -217,7 +218,7 @@ class RateLimiterTest { val envelope = SentryEnvelope(SentryEnvelopeHeader(), arrayListOf(eventItem, userFeedbackItem, sessionItem, attachmentItem)) rateLimiter.updateRetryAfterLimits("60:error:key, 1:error:organization", null, 1) - val result = rateLimiter.filter(envelope, null) + val result = rateLimiter.filter(envelope, Hints()) assertNotNull(result) assertEquals(3, result.items.toList().size) diff --git a/sentry/src/test/java/io/sentry/util/HintUtilsTest.kt b/sentry/src/test/java/io/sentry/util/HintUtilsTest.kt index 9e8db6c300..425eb31a0d 100644 --- a/sentry/src/test/java/io/sentry/util/HintUtilsTest.kt +++ b/sentry/src/test/java/io/sentry/util/HintUtilsTest.kt @@ -2,9 +2,9 @@ package io.sentry.util import com.nhaarman.mockitokotlin2.mock import io.sentry.CustomCachedApplyScopeDataHint -import io.sentry.TypeCheckHint.SENTRY_TYPE_CHECK_HINT import io.sentry.hints.ApplyScopeData import io.sentry.hints.Cached +import io.sentry.hints.Hints import kotlin.test.Test import kotlin.test.assertFalse import kotlin.test.assertTrue @@ -13,24 +13,24 @@ class HintUtilsTest { @Test fun `if event is Cached, it should not apply scopes data`() { - val hintsMap = mutableMapOf(SENTRY_TYPE_CHECK_HINT to mock()) - assertFalse(HintUtils.shouldApplyScopeData(hintsMap)) + val hints = HintUtils.createWithTypeCheckHint(mock()) + assertFalse(HintUtils.shouldApplyScopeData(hints)) } @Test fun `if event is not Cached, it should apply scopes data`() { - assertTrue(HintUtils.shouldApplyScopeData(null)) + assertTrue(HintUtils.shouldApplyScopeData(Hints())) } @Test fun `if event is ApplyScopeData, it should apply scopes data`() { - val hintsMap = mutableMapOf(SENTRY_TYPE_CHECK_HINT to mock()) - assertTrue(HintUtils.shouldApplyScopeData(hintsMap)) + val hints = HintUtils.createWithTypeCheckHint(mock()) + assertTrue(HintUtils.shouldApplyScopeData(hints)) } @Test fun `if event is Cached but also ApplyScopeData, it should apply scopes data`() { - val hintsMap = mutableMapOf(SENTRY_TYPE_CHECK_HINT to CustomCachedApplyScopeDataHint()) - assertTrue(HintUtils.shouldApplyScopeData(hintsMap)) + val hints = HintUtils.createWithTypeCheckHint(CustomCachedApplyScopeDataHint()) + assertTrue(HintUtils.shouldApplyScopeData(hints)) } } From 48d1726bcddc22688da57fe119c6f8abe30b6c20 Mon Sep 17 00:00:00 2001 From: Alexander Dinauer Date: Fri, 13 May 2022 08:03:29 +0200 Subject: [PATCH 2/9] Add changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b931ceb68..5522dbd6f5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - Allow setting SDK info (name & version) in manifest ([#2016](https://github.com/getsentry/sentry-java/pull/2016)) - Allow setting native Android SDK name during build ([#2035](https://github.com/getsentry/sentry-java/pull/2035)) +- Hints are now used via aHints object and passed into beforeSend and EventProcessor as @NotNull Hints object ([#2045]https://github.com/getsentry/sentry-java/pull/2045) ## 6.0.0-beta.3 From 76696a1e6b2676a18eb727fea4aa910b196d2e9b Mon Sep 17 00:00:00 2001 From: Alexander Dinauer Date: Fri, 13 May 2022 08:09:59 +0200 Subject: [PATCH 3/9] Fix typo in changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5522dbd6f5..8a55a494b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ - Allow setting SDK info (name & version) in manifest ([#2016](https://github.com/getsentry/sentry-java/pull/2016)) - Allow setting native Android SDK name during build ([#2035](https://github.com/getsentry/sentry-java/pull/2035)) -- Hints are now used via aHints object and passed into beforeSend and EventProcessor as @NotNull Hints object ([#2045]https://github.com/getsentry/sentry-java/pull/2045) +- Hints are now used via a Hints object and passed into beforeSend and EventProcessor as @NotNull Hints object ([#2045]https://github.com/getsentry/sentry-java/pull/2045) ## 6.0.0-beta.3 From b0903ae36a78f512d70e8eab1e2acfce30e762f7 Mon Sep 17 00:00:00 2001 From: Alexander Dinauer Date: Fri, 13 May 2022 08:12:22 +0200 Subject: [PATCH 4/9] Fix link in changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8a55a494b5..3509b35f6e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ - Allow setting SDK info (name & version) in manifest ([#2016](https://github.com/getsentry/sentry-java/pull/2016)) - Allow setting native Android SDK name during build ([#2035](https://github.com/getsentry/sentry-java/pull/2035)) -- Hints are now used via a Hints object and passed into beforeSend and EventProcessor as @NotNull Hints object ([#2045]https://github.com/getsentry/sentry-java/pull/2045) +- Hints are now used via a Hints object and passed into beforeSend and EventProcessor as @NotNull Hints object ([#2045](https://github.com/getsentry/sentry-java/pull/2045)) ## 6.0.0-beta.3 From ac1e895589677b27cb1fb4b8ffaef9d830ad6d13 Mon Sep 17 00:00:00 2001 From: Alexander Dinauer Date: Fri, 20 May 2022 07:32:50 +0200 Subject: [PATCH 5/9] Attachments can be manipulated via hints (#2046) * Store attachments in hints and allow manipulation in beforeSend and eventProcessor * Add changelog * Add tests for breadcrumbs and attachments via hints * Update CHANGELOG.md Co-authored-by: Philipp Hofmann * Rename AttachmentContainer to Attachments * Use long for test * Move attachments into Hints * Fix kotlin/java interop for Hints * Convert screenshot from map entry to property * Rename hint name param * Rename clear to clearAttachments * Use kotlin short version access for getScreenshot * Move AttachmentsTest into HintsTest; add param names * Make primitiveMapping table static * Use ArrayList as there should not be a synchronization issue for hints Co-authored-by: Philipp Hofmann --- CHANGELOG.md | 1 + .../core/ScreenshotEventProcessor.java | 5 +- .../core/ScreenshotEventProcessorTest.kt | 15 +- sentry/api/sentry.api | 11 +- .../src/main/java/io/sentry/SentryClient.java | 40 +-- .../main/java/io/sentry/TypeCheckHint.java | 2 - .../src/main/java/io/sentry/hints/Hints.java | 101 +++++++- .../main/java/io/sentry/util/HintUtils.java | 2 +- .../test/java/io/sentry/SentryClientTest.kt | 241 +++++++++++++++++- .../test/java/io/sentry/hints/HintsTest.kt | 202 +++++++++++++++ 10 files changed, 570 insertions(+), 50 deletions(-) create mode 100644 sentry/src/test/java/io/sentry/hints/HintsTest.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 3509b35f6e..a9c04ac5c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - Allow setting SDK info (name & version) in manifest ([#2016](https://github.com/getsentry/sentry-java/pull/2016)) - Allow setting native Android SDK name during build ([#2035](https://github.com/getsentry/sentry-java/pull/2035)) - Hints are now used via a Hints object and passed into beforeSend and EventProcessor as @NotNull Hints object ([#2045](https://github.com/getsentry/sentry-java/pull/2045)) +- Attachments can be manipulated via hints ([#2046](https://github.com/getsentry/sentry-java/pull/2046)) ## 6.0.0-beta.3 diff --git a/sentry-android-core/src/main/java/io/sentry/android/core/ScreenshotEventProcessor.java b/sentry-android-core/src/main/java/io/sentry/android/core/ScreenshotEventProcessor.java index 6fed7fcf3b..4630e6a7bd 100644 --- a/sentry-android-core/src/main/java/io/sentry/android/core/ScreenshotEventProcessor.java +++ b/sentry-android-core/src/main/java/io/sentry/android/core/ScreenshotEventProcessor.java @@ -1,7 +1,6 @@ package io.sentry.android.core; import static io.sentry.TypeCheckHint.ANDROID_ACTIVITY; -import static io.sentry.TypeCheckHint.SENTRY_SCREENSHOT; import android.annotation.SuppressLint; import android.app.Activity; @@ -93,9 +92,7 @@ public ScreenshotEventProcessor( if (byteArrayOutputStream.size() > 0) { // screenshot png is around ~100-150 kb - hints.set( - SENTRY_SCREENSHOT, - Attachment.fromScreenshot(byteArrayOutputStream.toByteArray())); + hints.setScreenshot(Attachment.fromScreenshot(byteArrayOutputStream.toByteArray())); hints.set(ANDROID_ACTIVITY, activity); } else { this.options diff --git a/sentry-android-core/src/test/java/io/sentry/android/core/ScreenshotEventProcessorTest.kt b/sentry-android-core/src/test/java/io/sentry/android/core/ScreenshotEventProcessorTest.kt index 2e8ef405e7..0db193574a 100644 --- a/sentry-android-core/src/test/java/io/sentry/android/core/ScreenshotEventProcessorTest.kt +++ b/sentry-android-core/src/test/java/io/sentry/android/core/ScreenshotEventProcessorTest.kt @@ -14,7 +14,6 @@ import io.sentry.Attachment import io.sentry.MainEventProcessor import io.sentry.SentryEvent import io.sentry.TypeCheckHint.ANDROID_ACTIVITY -import io.sentry.TypeCheckHint.SENTRY_SCREENSHOT import io.sentry.hints.Hints import org.junit.runner.RunWith import kotlin.test.BeforeTest @@ -103,7 +102,7 @@ class ScreenshotEventProcessorTest { val event = fixture.mainProcessor.process(getEvent(), hints) sut.process(event, hints) - assertNull(hints[SENTRY_SCREENSHOT]) + assertNull(hints.screenshot) } @Test @@ -116,7 +115,7 @@ class ScreenshotEventProcessorTest { val event = fixture.mainProcessor.process(SentryEvent(), hints) sut.process(event, hints) - assertNull(hints[SENTRY_SCREENSHOT]) + assertNull(hints.screenshot) } @Test @@ -127,7 +126,7 @@ class ScreenshotEventProcessorTest { val event = fixture.mainProcessor.process(getEvent(), hints) sut.process(event, hints) - assertNull(hints[SENTRY_SCREENSHOT]) + assertNull(hints.screenshot) } @Test @@ -141,7 +140,7 @@ class ScreenshotEventProcessorTest { val event = fixture.mainProcessor.process(getEvent(), hints) sut.process(event, hints) - assertNull(hints[SENTRY_SCREENSHOT]) + assertNull(hints.screenshot) } @Test @@ -156,7 +155,7 @@ class ScreenshotEventProcessorTest { val event = fixture.mainProcessor.process(getEvent(), hints) sut.process(event, hints) - assertNull(hints[SENTRY_SCREENSHOT]) + assertNull(hints.screenshot) } @Test @@ -169,7 +168,7 @@ class ScreenshotEventProcessorTest { val event = fixture.mainProcessor.process(getEvent(), hints) sut.process(event, hints) - val screenshot = hints[SENTRY_SCREENSHOT] + val screenshot = hints.screenshot assertTrue(screenshot is Attachment) assertEquals("screenshot.png", screenshot.filename) assertEquals("image/png", screenshot.contentType) @@ -188,7 +187,7 @@ class ScreenshotEventProcessorTest { val event = fixture.mainProcessor.process(getEvent(), hints) sut.process(event, hints) - assertNull(hints[SENTRY_SCREENSHOT]) + assertNull(hints.screenshot) } private fun getEvent(): SentryEvent = SentryEvent(Throwable("Throwable")) diff --git a/sentry/api/sentry.api b/sentry/api/sentry.api index 2489f2d3bb..b2195ad59b 100644 --- a/sentry/api/sentry.api +++ b/sentry/api/sentry.api @@ -1638,7 +1638,6 @@ public final class io/sentry/TypeCheckHint { public static final field OKHTTP_RESPONSE Ljava/lang/String; public static final field OPEN_FEIGN_REQUEST Ljava/lang/String; public static final field OPEN_FEIGN_RESPONSE Ljava/lang/String; - public static final field SENTRY_SCREENSHOT Ljava/lang/String; public static final field SENTRY_SYNTHETIC_EXCEPTION Ljava/lang/String; public static final field SENTRY_TYPE_CHECK_HINT Ljava/lang/String; public static final field SERVLET_REQUEST Ljava/lang/String; @@ -1848,9 +1847,19 @@ public abstract interface class io/sentry/hints/Flushable { public final class io/sentry/hints/Hints { public fun ()V + public fun addAttachment (Lio/sentry/Attachment;)V + public fun addAttachments (Ljava/util/List;)V + public fun clearAttachments ()V public fun get (Ljava/lang/String;)Ljava/lang/Object; + public fun getAs (Ljava/lang/String;Ljava/lang/Class;)Ljava/lang/Object; + public fun getAttachments ()Ljava/util/List; + public fun getScreenshot ()Lio/sentry/Attachment; public fun remove (Ljava/lang/String;)V + public fun replaceAttachments (Ljava/util/List;)V public fun set (Ljava/lang/String;Ljava/lang/Object;)V + public fun setScreenshot (Lio/sentry/Attachment;)V + public static fun withAttachment (Lio/sentry/Attachment;)Lio/sentry/hints/Hints; + public static fun withAttachments (Ljava/util/List;)Lio/sentry/hints/Hints; } public abstract interface class io/sentry/hints/Resettable { diff --git a/sentry/src/main/java/io/sentry/SentryClient.java b/sentry/src/main/java/io/sentry/SentryClient.java index 790434e6c9..5fd62f9b27 100644 --- a/sentry/src/main/java/io/sentry/SentryClient.java +++ b/sentry/src/main/java/io/sentry/SentryClient.java @@ -1,7 +1,5 @@ package io.sentry; -import static io.sentry.TypeCheckHint.SENTRY_SCREENSHOT; - import io.sentry.clientreport.DiscardReason; import io.sentry.exception.SentryEnvelopeException; import io.sentry.hints.DiskFlushNotification; @@ -80,6 +78,11 @@ private boolean shouldApplyScopeData( hints = new Hints(); } + // TODO what does cached etc mean for devs manipulating hints in beforeSend and eventProcessor? + if (shouldApplyScopeData(event, hints)) { + addScopeAttachmentsToHints(scope, hints); + } + options.getLogger().log(SentryLevel.DEBUG, "Capturing event: %s", event.getEventId()); if (event != null) { @@ -173,7 +176,7 @@ private boolean shouldApplyScopeData( ? scope.getTransaction().traceState() : null; final boolean shouldSendAttachments = event != null; - List attachments = shouldSendAttachments ? getAttachments(scope, hints) : null; + List attachments = shouldSendAttachments ? getAttachments(hints) : null; final SentryEnvelope envelope = buildEnvelope(event, attachments, session, traceState, null); if (envelope != null) { @@ -189,6 +192,12 @@ private boolean shouldApplyScopeData( return sentryId; } + private void addScopeAttachmentsToHints(@Nullable Scope scope, @NotNull Hints hints) { + if (scope != null) { + hints.addAttachments(scope.getAttachments()); + } + } + private boolean shouldSendSessionUpdateForDroppedEvent( @Nullable Session sessionBeforeUpdate, @Nullable Session sessionAfterUpdate) { if (sessionAfterUpdate == null) { @@ -215,21 +224,12 @@ private boolean shouldSendSessionUpdateForDroppedEvent( return false; } - private @Nullable List getAttachments( - final @Nullable Scope scope, final @NotNull Hints hints) { - List attachments = null; - if (scope != null) { - attachments = scope.getAttachments(); - } - - final Object screenshotAttachment = hints.get(SENTRY_SCREENSHOT); - if (screenshotAttachment instanceof Attachment) { - - if (attachments == null) { - attachments = new ArrayList<>(); - } + private @Nullable List getAttachments(final @NotNull Hints hints) { + @NotNull final List attachments = hints.getAttachments(); - attachments.add((Attachment) screenshotAttachment); + @Nullable final Attachment screenshot = hints.getScreenshot(); + if (screenshot != null) { + attachments.add(screenshot); } return attachments; @@ -506,6 +506,10 @@ public void captureSession(final @NotNull Session session, final @Nullable Hints hints = new Hints(); } + if (shouldApplyScopeData(transaction, hints)) { + addScopeAttachmentsToHints(scope, hints); + } + options .getLogger() .log(SentryLevel.DEBUG, "Capturing transaction: %s", transaction.getEventId()); @@ -540,7 +544,7 @@ public void captureSession(final @NotNull Session session, final @Nullable Hints final SentryEnvelope envelope = buildEnvelope( transaction, - filterForTransaction(getAttachments(scope, hints)), + filterForTransaction(getAttachments(hints)), null, traceState, profilingTraceData); diff --git a/sentry/src/main/java/io/sentry/TypeCheckHint.java b/sentry/src/main/java/io/sentry/TypeCheckHint.java index 9bf5a79f14..cc50b40c37 100644 --- a/sentry/src/main/java/io/sentry/TypeCheckHint.java +++ b/sentry/src/main/java/io/sentry/TypeCheckHint.java @@ -25,8 +25,6 @@ public final class TypeCheckHint { public static final String ANDROID_VIEW = "android:view"; /** Used for Fragment breadcrumbs. */ public static final String ANDROID_FRAGMENT = "android:fragment"; - /** Used for screenshots. */ - public static final String SENTRY_SCREENSHOT = "sentry:screenshot"; /** Used for OkHttp response breadcrumbs. */ public static final String OKHTTP_RESPONSE = "okHttp:response"; diff --git a/sentry/src/main/java/io/sentry/hints/Hints.java b/sentry/src/main/java/io/sentry/hints/Hints.java index 51ea2b57ca..0475df60cf 100644 --- a/sentry/src/main/java/io/sentry/hints/Hints.java +++ b/sentry/src/main/java/io/sentry/hints/Hints.java @@ -1,29 +1,108 @@ package io.sentry.hints; +import io.sentry.Attachment; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; public final class Hints { + private static final @NotNull Map> PRIMITIVE_MAPPINGS; + + static { + PRIMITIVE_MAPPINGS = new HashMap<>(); + PRIMITIVE_MAPPINGS.put("boolean", Boolean.class); + PRIMITIVE_MAPPINGS.put("char", Character.class); + PRIMITIVE_MAPPINGS.put("byte", Byte.class); + PRIMITIVE_MAPPINGS.put("short", Short.class); + PRIMITIVE_MAPPINGS.put("int", Integer.class); + PRIMITIVE_MAPPINGS.put("long", Long.class); + PRIMITIVE_MAPPINGS.put("float", Float.class); + PRIMITIVE_MAPPINGS.put("double", Double.class); + } + private final @NotNull Map internalStorage = new HashMap(); + private final @NotNull List attachments = new ArrayList<>(); + private @Nullable Attachment screenshot = null; - public void set(@NotNull String hintType, @Nullable Object hint) { - internalStorage.put(hintType, hint); + public static @NotNull Hints withAttachment(@Nullable Attachment attachment) { + @NotNull final Hints hints = new Hints(); + hints.addAttachment(attachment); + return hints; } - public @Nullable Object get(@NotNull String hintType) { - return internalStorage.get(hintType); + public static @NotNull Hints withAttachments(@Nullable List attachments) { + @NotNull final Hints hints = new Hints(); + hints.addAttachments(attachments); + return hints; } - // TODO maybe not public - public void remove(@NotNull String hintType) { - internalStorage.remove(hintType); + public void set(@NotNull String name, @Nullable Object hint) { + internalStorage.put(name, hint); } - // TODO addAttachment(one) - // TODO getAttachments(): List - // TODO setAttachments(list) - // TODO clearAttachments() + public @Nullable Object get(@NotNull String name) { + return internalStorage.get(name); + } + + @SuppressWarnings("unchecked") + public @Nullable T getAs(@NotNull String name, @NotNull Class clazz) { + Object hintValue = internalStorage.get(name); + + if (clazz.isInstance(hintValue)) { + return (T) hintValue; + } else if (isCastablePrimitive(hintValue, clazz)) { + return (T) hintValue; + } else { + return null; + } + } + + public void remove(@NotNull String name) { + internalStorage.remove(name); + } + + public void addAttachment(@Nullable Attachment attachment) { + if (attachment != null) { + attachments.add(attachment); + } + } + + public void addAttachments(@Nullable List attachments) { + if (attachments != null) { + this.attachments.addAll(attachments); + } + } + + public @NotNull List getAttachments() { + return new ArrayList<>(attachments); + } + + public void replaceAttachments(@Nullable List attachments) { + clearAttachments(); + addAttachments(attachments); + } + + public void clearAttachments() { + attachments.clear(); + } + + public void setScreenshot(@Nullable Attachment screenshot) { + this.screenshot = screenshot; + } + + public @Nullable Attachment getScreenshot() { + return screenshot; + } + + private boolean isCastablePrimitive(@Nullable Object hintValue, @NotNull Class clazz) { + Class nonPrimitiveClass = PRIMITIVE_MAPPINGS.get(clazz.getCanonicalName()); + return hintValue != null + && clazz.isPrimitive() + && nonPrimitiveClass != null + && nonPrimitiveClass.isInstance(hintValue); + } } diff --git a/sentry/src/main/java/io/sentry/util/HintUtils.java b/sentry/src/main/java/io/sentry/util/HintUtils.java index cf7bafb8fc..78e802076a 100644 --- a/sentry/src/main/java/io/sentry/util/HintUtils.java +++ b/sentry/src/main/java/io/sentry/util/HintUtils.java @@ -10,7 +10,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -/** Util class for Applying or not scope's data to an event */ +/** Util class dealing with Hints as not to pollute the Hints API with internal functionality */ @ApiStatus.Internal public final class HintUtils { diff --git a/sentry/src/test/java/io/sentry/SentryClientTest.kt b/sentry/src/test/java/io/sentry/SentryClientTest.kt index 0429f583c7..b3672b04c1 100644 --- a/sentry/src/test/java/io/sentry/SentryClientTest.kt +++ b/sentry/src/test/java/io/sentry/SentryClientTest.kt @@ -14,7 +14,6 @@ import com.nhaarman.mockitokotlin2.times import com.nhaarman.mockitokotlin2.verify import com.nhaarman.mockitokotlin2.verifyNoMoreInteractions import com.nhaarman.mockitokotlin2.whenever -import io.sentry.TypeCheckHint.SENTRY_SCREENSHOT import io.sentry.clientreport.ClientReportTestHelper.Companion.assertClientReport import io.sentry.clientreport.DiscardReason import io.sentry.clientreport.DiscardedEvent @@ -84,6 +83,8 @@ class SentryClientTest { } var attachment = Attachment("hello".toByteArray(), "hello.txt", "text/plain", true) + var attachment2 = Attachment("hello2".toByteArray(), "hello2.txt", "text/plain", true) + var attachment3 = Attachment("hello3".toByteArray(), "hello3.txt", "text/plain", true) val profilingTraceFile = Files.createTempFile("trace", ".trace").toFile() var profilingTraceData = ProfilingTraceData(profilingTraceFile, sentryTracer) var profilingNonExistingTraceData = ProfilingTraceData(File("non_existent.trace"), sentryTracer) @@ -1282,7 +1283,7 @@ class SentryClientTest { fun `screenshot is added to the envelope from the hint`() { val sut = fixture.getSut() val attachment = Attachment.fromScreenshot(byteArrayOf()) - val hints = Hints().also { it.set(SENTRY_SCREENSHOT, attachment) } + val hints = Hints().also { it.screenshot = attachment } sut.captureEvent(SentryEvent(), hints) @@ -1302,7 +1303,7 @@ class SentryClientTest { fixture.sentryOptions.beforeSend = CustomBeforeSendCallback() val sut = fixture.getSut() val attachment = Attachment.fromScreenshot(byteArrayOf()) - val hints = Hints().also { it.set(SENTRY_SCREENSHOT, attachment) } + val hints = Hints().also { it.screenshot = attachment } sut.captureEvent(SentryEvent(), hints) @@ -1592,6 +1593,234 @@ class SentryClientTest { ) } + @Test + fun `can pass an attachment via hints`() { + val sut = fixture.getSut() + + sut.captureException(IllegalStateException(), Hints.withAttachment(fixture.attachment)) + + thenEnvelopeIsSentWith(eventCount = 1, sessionCount = 0, attachmentCount = 1) + } + + @Test + fun `an attachment passed via hint is used with scope attachments`() { + val sut = fixture.getSut() + + val scope = givenScopeWithStartedSession() + scope.addAttachment(fixture.attachment2) + sut.captureException(IllegalStateException(), scope, Hints.withAttachment(fixture.attachment)) + + thenEnvelopeIsSentWith(eventCount = 1, sessionCount = 1, attachmentCount = 2) + } + + @Test + fun `can add to attachments in beforeSend`() { + val sut = fixture.getSut { options -> + options.setBeforeSend { event, hints -> + assertEquals(listOf(fixture.attachment, fixture.attachment2), hints.attachments) + hints.addAttachment(fixture.attachment3) + event + } + } + + val scope = givenScopeWithStartedSession() + scope.addAttachment(fixture.attachment2) + sut.captureException(IllegalStateException(), scope, Hints.withAttachment(fixture.attachment)) + + thenEnvelopeIsSentWith(eventCount = 1, sessionCount = 1, attachmentCount = 3) + } + + @Test + fun `can replace attachments in beforeSend`() { + val sut = fixture.getSut { options -> + options.setBeforeSend { event, hints -> + hints.replaceAttachments(listOf(fixture.attachment)) + event + } + } + + val scope = givenScopeWithStartedSession() + scope.addAttachment(fixture.attachment2) + sut.captureException(IllegalStateException(), scope, Hints.withAttachment(fixture.attachment)) + + thenEnvelopeIsSentWith(eventCount = 1, sessionCount = 1, attachmentCount = 1) + } + + @Test + fun `can add to attachments in eventProcessor`() { + val sut = fixture.getSut { options -> + options.addEventProcessor(object : EventProcessor { + override fun process(event: SentryEvent, hints: Hints): SentryEvent? { + assertEquals(listOf(fixture.attachment, fixture.attachment2), hints.attachments) + hints.addAttachment(fixture.attachment3) + return event + } + + override fun process( + transaction: SentryTransaction, + hints: Hints + ): SentryTransaction? { + return transaction + } + }) + } + + val scope = givenScopeWithStartedSession() + scope.addAttachment(fixture.attachment2) + sut.captureException(IllegalStateException(), scope, Hints.withAttachment(fixture.attachment)) + + thenEnvelopeIsSentWith(eventCount = 1, sessionCount = 1, attachmentCount = 3) + } + + @Test + fun `can replace attachments in eventProcessor`() { + val sut = fixture.getSut { options -> + options.addEventProcessor(object : EventProcessor { + override fun process(event: SentryEvent, hints: Hints): SentryEvent? { + hints.replaceAttachments(listOf(fixture.attachment)) + return event + } + + override fun process( + transaction: SentryTransaction, + hints: Hints + ): SentryTransaction? { + return transaction + } + }) + } + + val scope = givenScopeWithStartedSession() + scope.addAttachment(fixture.attachment2) + sut.captureException(IllegalStateException(), scope, Hints.withAttachment(fixture.attachment)) + + thenEnvelopeIsSentWith(eventCount = 1, sessionCount = 1, attachmentCount = 1) + } + + @Test + fun `can pass an attachment via hints for transactions`() { + val sut = fixture.getSut() + val scope = createScope() + + sut.captureTransaction( + SentryTransaction(fixture.sentryTracer), + scope, + Hints.withAttachment(fixture.attachment) + ) + + thenEnvelopeIsSentWith(eventCount = 0, sessionCount = 0, attachmentCount = 1, transactionCount = 1) + } + + @Test + fun `an attachment passed via hint is used with scope attachments for transactions`() { + val sut = fixture.getSut() + + val scope = givenScopeWithStartedSession() + scope.addAttachment(fixture.attachment2) + + sut.captureTransaction( + SentryTransaction(fixture.sentryTracer), + scope, + Hints.withAttachment(fixture.attachment) + ) + + thenEnvelopeIsSentWith(eventCount = 0, sessionCount = 0, attachmentCount = 2, transactionCount = 1) + } + + @Test + fun `can add to attachments in eventProcessor for transactions`() { + val sut = fixture.getSut { options -> + options.addEventProcessor(object : EventProcessor { + override fun process(event: SentryEvent, hints: Hints): SentryEvent? { + return event + } + + override fun process( + transaction: SentryTransaction, + hints: Hints + ): SentryTransaction? { + assertEquals(listOf(fixture.attachment, fixture.attachment2), hints.attachments) + hints.addAttachment(fixture.attachment3) + return transaction + } + }) + } + + val scope = givenScopeWithStartedSession() + scope.addAttachment(fixture.attachment2) + + sut.captureTransaction( + SentryTransaction(fixture.sentryTracer), + scope, + Hints.withAttachment(fixture.attachment) + ) + + thenEnvelopeIsSentWith(eventCount = 0, sessionCount = 0, attachmentCount = 3, transactionCount = 1) + } + + @Test + fun `can replace attachments in eventProcessor for transactions`() { + val sut = fixture.getSut { options -> + options.addEventProcessor(object : EventProcessor { + override fun process(event: SentryEvent, hints: Hints): SentryEvent? { + return event + } + + override fun process( + transaction: SentryTransaction, + hints: Hints + ): SentryTransaction? { + hints.replaceAttachments(listOf(fixture.attachment)) + return transaction + } + }) + } + + val scope = givenScopeWithStartedSession() + scope.addAttachment(fixture.attachment2) + + sut.captureTransaction( + SentryTransaction(fixture.sentryTracer), + scope, + Hints.withAttachment(fixture.attachment) + ) + + thenEnvelopeIsSentWith(eventCount = 0, sessionCount = 0, attachmentCount = 1, transactionCount = 1) + } + + @Test + fun `passing attachments via hint into breadcrumb ignores them`() { + val sut = fixture.getSut { options -> + options.setBeforeBreadcrumb { breadcrumb, hints -> + breadcrumb + } + } + + val scope = givenScopeWithStartedSession() + scope.addBreadcrumb(Breadcrumb.info("hello from breadcrumb"), Hints.withAttachment(fixture.attachment)) + + sut.captureException(IllegalStateException(), scope) + + thenEnvelopeIsSentWith(eventCount = 1, sessionCount = 1, attachmentCount = 0) + } + + @Test + fun `adding attachments in beforeBreadcrumb ignores them`() { + val sut = fixture.getSut { options -> + options.setBeforeBreadcrumb { breadcrumb, hints -> + hints.addAttachment(fixture.attachment) + breadcrumb + } + } + + val scope = givenScopeWithStartedSession() + scope.addBreadcrumb(Breadcrumb.info("hello from breadcrumb")) + + sut.captureException(IllegalStateException(), scope) + + thenEnvelopeIsSentWith(eventCount = 1, sessionCount = 1, attachmentCount = 0) + } + private fun givenScopeWithStartedSession(errored: Boolean = false, crashed: Boolean = false): Scope { val scope = createScope(fixture.sentryOptions) scope.startSession() @@ -1611,7 +1840,7 @@ class SentryClientTest { verify(fixture.transport, never()).send(anyOrNull(), anyOrNull()) } - private fun thenEnvelopeIsSentWith(eventCount: Int, sessionCount: Int) { + private fun thenEnvelopeIsSentWith(eventCount: Int, sessionCount: Int, attachmentCount: Int = 0, transactionCount: Int = 0) { val argumentCaptor = argumentCaptor() verify(fixture.transport, times(1)).send(argumentCaptor.capture(), anyOrNull()) @@ -1619,6 +1848,8 @@ class SentryClientTest { val envelopeItemTypes = envelope.items.map { it.header.type } assertEquals(eventCount, envelopeItemTypes.count { it == SentryItemType.Event }) assertEquals(sessionCount, envelopeItemTypes.count { it == SentryItemType.Session }) + assertEquals(attachmentCount, envelopeItemTypes.count { it == SentryItemType.Attachment }) + assertEquals(transactionCount, envelopeItemTypes.count { it == SentryItemType.Transaction }) } private fun thenSessionIsStillOK(scope: Scope) { @@ -1641,7 +1872,7 @@ class SentryClientTest { class CustomBeforeSendCallback : SentryOptions.BeforeSendCallback { override fun execute(event: SentryEvent, hints: Hints): SentryEvent? { - hints.remove(SENTRY_SCREENSHOT) + hints.screenshot = null return event } diff --git a/sentry/src/test/java/io/sentry/hints/HintsTest.kt b/sentry/src/test/java/io/sentry/hints/HintsTest.kt new file mode 100644 index 0000000000..92e6d302cd --- /dev/null +++ b/sentry/src/test/java/io/sentry/hints/HintsTest.kt @@ -0,0 +1,202 @@ +package io.sentry.hints + +import io.sentry.Attachment +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertNotNull +import kotlin.test.assertNull + +class HintsTest { + @Test + fun `getting as wrong class returns null`() { + val hints = Hints() + hints.set("hint1", "not a number") + + assertNull(hints.getAs("hint1", Int::class.java)) + } + + @Test + fun `getting as correct class returns it`() { + val hints = Hints() + hints.set("hint1", "some string") + + assertEquals("some string", hints.getAs("hint1", String::class.java)) + } + + @Test + fun `getting casted returns null if not contained`() { + val hints = Hints() + assertNull(hints.getAs("hint-does-not-exist", Int::class.java)) + } + + @Test + fun `getting returns null if not contained`() { + val hints = Hints() + assertNull(hints.get("hint-does-not-exist")) + } + + @Test + fun `kotlin java interop for primitives works for float`() { + val hints = Hints() + hints.set("hint1", 1.3f) + assertEquals(1.3f, hints.getAs("hint1", Float::class.java)) + } + + @Test + fun `kotlin java interop for primitives works for double`() { + val hints = Hints() + hints.set("hint1", 1.4) + assertEquals(1.4, hints.getAs("hint1", Double::class.java)) + } + + @Test + fun `kotlin java interop for primitives works for long`() { + val hints = Hints() + hints.set("hint1", 1718L) + assertEquals(1718L, hints.getAs("hint1", Long::class.java)) + } + + @Test + fun `kotlin java interop for primitives works for int`() { + val hints = Hints() + hints.set("hint1", 123) + assertEquals(123, hints.getAs("hint1", Int::class.java)) + } + + @Test + fun `kotlin java interop for primitives works for short`() { + val hints = Hints() + val s: Short = 123 + hints.set("hint1", s) + assertEquals(s, hints.getAs("hint1", Short::class.java)) + } + + @Test + fun `kotlin java interop for primitives works for byte`() { + val hints = Hints() + val b: Byte = 1 + hints.set("hint1", b) + assertEquals(b, hints.getAs("hint1", Byte::class.java)) + } + + @Test + fun `kotlin java interop for primitives works for char`() { + val hints = Hints() + hints.set("hint1", 'a') + assertEquals('a', hints.getAs("hint1", Char::class.java)) + } + + @Test + fun `kotlin java interop for primitives works for boolean`() { + val hints = Hints() + hints.set("hint1", true) + assertEquals(true, hints.getAs("hint1", Boolean::class.java)) + } + + @Test + fun `setting twice only keeps second value`() { + val hints = Hints() + + hints.set("hint1", "some string") + hints.set("hint1", "a different string") + + assertEquals("a different string", hints.getAs("hint1", String::class.java)) + } + + @Test + fun `after removing the value is gone`() { + val hints = Hints() + + hints.set("hint1", "some string") + assertEquals("some string", hints.getAs("hint1", String::class.java)) + + hints.remove("hint1") + assertNull(hints.get("hint1")) + } + + @Test + fun `removing leaves other values`() { + val hints = Hints() + + hints.set("hint1", "some string") + assertEquals("some string", hints.getAs("hint1", String::class.java)) + hints.set("hint2", "another string") + + hints.remove("hint1") + assertNull(hints.get("hint1")) + assertEquals("another string", hints.getAs("hint2", String::class.java)) + } + + @Test + fun `can retrieve Attachments`() { + val hints = Hints() + assertNotNull(hints.attachments) + } + + @Test + fun `can create hints with attachment`() { + val attachment = newAttachment("test1") + val hints = Hints.withAttachment(attachment) + assertEquals(listOf(attachment), hints.attachments) + } + + @Test + fun `can create hints with attachments`() { + val attachment1 = newAttachment("test1") + val attachment2 = newAttachment("test1") + val hints = Hints.withAttachments(listOf(attachment1, attachment2)) + assertEquals(listOf(attachment1, attachment2), hints.attachments) + } + + @Test + fun `can add an attachment`() { + val hints = Hints() + val attachment = newAttachment("test1") + hints.addAttachment(attachment) + + assertEquals(listOf(attachment), hints.attachments) + } + + @Test + fun `can add multiple attachments`() { + val hints = Hints() + val attachment1 = newAttachment("test1") + val attachment2 = newAttachment("test2") + hints.addAttachment(attachment1) + hints.addAttachment(attachment2) + + assertEquals(listOf(attachment1, attachment2), hints.attachments) + } + + @Test + fun `after reset list is empty`() { + val hints = Hints() + val attachment1 = newAttachment("test1") + val attachment2 = newAttachment("test2") + hints.addAttachment(attachment1) + hints.addAttachment(attachment2) + + hints.clearAttachments() + + assertEquals(emptyList(), hints.attachments) + } + + @Test + fun `after replace list contains only new item`() { + val hints = Hints() + val attachment1 = newAttachment("test1") + val attachment2 = newAttachment("test2") + val attachment3 = newAttachment("test2") + val attachment4 = newAttachment("test2") + hints.addAttachment(attachment1) + hints.addAttachment(attachment2) + + hints.replaceAttachments(listOf(attachment3, attachment4)) + + assertEquals(listOf(attachment3, attachment4), hints.attachments) + } + + companion object { + fun newAttachment(content: String) = Attachment(content.toByteArray(), "$content.txt") + } +} From 7c936031ba70dd4ba483c554f01e0d2a07ee2d58 Mon Sep 17 00:00:00 2001 From: Alexander Dinauer Date: Fri, 20 May 2022 10:24:56 +0200 Subject: [PATCH 6/9] Rename Hints to Hint --- CHANGELOG.md | 4 +- .../api/sentry-android-core.api | 2 +- .../core/ActivityLifecycleIntegration.java | 8 +- .../AppComponentsBreadcrumbsIntegration.java | 8 +- .../core/DefaultAndroidEventProcessor.java | 15 +- .../android/core/EnvelopeFileObserver.java | 8 +- .../PerformanceAndroidEventProcessor.java | 8 +- .../core/ScreenshotEventProcessor.java | 8 +- .../SystemEventsBreadcrumbsIntegration.java | 8 +- .../TempSensorBreadcrumbsIntegration.java | 8 +- .../gestures/SentryGestureListener.java | 10 +- .../core/DefaultAndroidEventProcessorTest.kt | 54 +++-- .../PerformanceAndroidEventProcessorTest.kt | 22 +- .../core/ScreenshotEventProcessorTest.kt | 60 +++--- .../SentryFragmentLifecycleCallbacks.kt | 7 +- .../android/okhttp/SentryOkHttpInterceptor.kt | 9 +- .../api/sentry-apache-http-client-5.api | 2 +- .../apache/ApacheHttpClientTransport.java | 14 +- .../sentry/apollo/SentryApolloInterceptor.kt | 6 +- .../SentryDataFetcherExceptionHandler.java | 8 +- .../java/io/sentry/jul/SentryHandler.java | 14 +- .../java/io/sentry/log4j2/SentryAppender.java | 14 +- .../io/sentry/logback/SentryAppender.java | 14 +- .../sentry/openfeign/SentryFeignClient.java | 10 +- .../java/io/sentry/samples/console/Main.java | 10 +- .../spring/boot/CustomEventProcessor.java | 4 +- ...tryRequestHttpServletRequestProcessor.java | 4 +- .../jakarta/SentryServletRequestListener.java | 8 +- ...yRequestHttpServletRequestProcessorTest.kt | 10 +- ...tryRequestHttpServletRequestProcessor.java | 4 +- .../servlet/SentryServletRequestListener.java | 8 +- ...yRequestHttpServletRequestProcessorTest.kt | 10 +- .../boot/SentryAutoConfigurationTest.kt | 8 +- sentry-spring/api/sentry-spring.api | 2 +- .../spring/SentryExceptionResolver.java | 10 +- ...tryRequestHttpServletRequestProcessor.java | 5 +- .../io/sentry/spring/SentrySpringFilter.java | 12 +- ...entrySpanClientHttpRequestInterceptor.java | 12 +- .../SentrySpanClientWebRequestFilter.java | 10 +- .../webflux/SentryWebExceptionHandler.java | 10 +- .../spring/webflux/SentryWebFilter.java | 10 +- ...yRequestHttpServletRequestProcessorTest.kt | 6 +- sentry/api/sentry.api | 138 ++++++------ .../java/io/sentry/DirectoryProcessor.java | 11 +- ...DuplicateEventDetectionEventProcessor.java | 5 +- .../main/java/io/sentry/EnvelopeSender.java | 16 +- .../main/java/io/sentry/EventProcessor.java | 10 +- sentry/src/main/java/io/sentry/Hub.java | 34 +-- .../src/main/java/io/sentry/HubAdapter.java | 23 +- .../main/java/io/sentry/IEnvelopeSender.java | 4 +- sentry/src/main/java/io/sentry/IHub.java | 37 ++-- .../main/java/io/sentry/ISentryClient.java | 48 ++--- .../java/io/sentry/MainEventProcessor.java | 27 ++- sentry/src/main/java/io/sentry/NoOpHub.java | 13 +- .../main/java/io/sentry/NoOpSentryClient.java | 10 +- .../src/main/java/io/sentry/OutboxSender.java | 34 +-- sentry/src/main/java/io/sentry/Scope.java | 18 +- sentry/src/main/java/io/sentry/Sentry.java | 20 +- .../src/main/java/io/sentry/SentryClient.java | 97 +++++---- .../main/java/io/sentry/SentryOptions.java | 10 +- .../sentry/SentryRuntimeEventProcessor.java | 7 +- .../UncaughtExceptionHandlerIntegration.java | 10 +- .../java/io/sentry/cache/EnvelopeCache.java | 10 +- .../java/io/sentry/cache/IEnvelopeCache.java | 6 +- .../io/sentry/hints/{Hints.java => Hint.java} | 18 +- .../sentry/transport/AsyncHttpTransport.java | 44 ++-- .../java/io/sentry/transport/ITransport.java | 6 +- .../sentry/transport/NoOpEnvelopeCache.java | 4 +- .../io/sentry/transport/NoOpTransport.java | 4 +- .../java/io/sentry/transport/RateLimiter.java | 16 +- .../io/sentry/transport/StdoutTransport.java | 4 +- .../main/java/io/sentry/util/HintUtils.java | 50 ++--- .../java/io/sentry/CustomEventProcessor.kt | 4 +- ...plicateEventDetectionEventProcessorTest.kt | 45 ++-- .../test/java/io/sentry/EnvelopeSenderTest.kt | 4 +- sentry/src/test/java/io/sentry/HubTest.kt | 4 +- .../java/io/sentry/MainEventProcessorTest.kt | 62 +++--- sentry/src/test/java/io/sentry/NoOpHubTest.kt | 4 +- sentry/src/test/java/io/sentry/ScopeTest.kt | 4 +- .../test/java/io/sentry/SentryClientTest.kt | 94 ++++---- .../sentry/clientreport/ClientReportTest.kt | 6 +- .../src/test/java/io/sentry/hints/HintTest.kt | 202 ++++++++++++++++++ .../test/java/io/sentry/hints/HintsTest.kt | 202 ------------------ .../io/sentry/transport/RateLimiterTest.kt | 22 +- .../test/java/io/sentry/util/HintUtilsTest.kt | 4 +- 85 files changed, 948 insertions(+), 907 deletions(-) rename sentry/src/main/java/io/sentry/hints/{Hints.java => Hint.java} (87%) create mode 100644 sentry/src/test/java/io/sentry/hints/HintTest.kt delete mode 100644 sentry/src/test/java/io/sentry/hints/HintsTest.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index a9c04ac5c2..d21ca6a8c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,8 +6,8 @@ - Allow setting SDK info (name & version) in manifest ([#2016](https://github.com/getsentry/sentry-java/pull/2016)) - Allow setting native Android SDK name during build ([#2035](https://github.com/getsentry/sentry-java/pull/2035)) -- Hints are now used via a Hints object and passed into beforeSend and EventProcessor as @NotNull Hints object ([#2045](https://github.com/getsentry/sentry-java/pull/2045)) -- Attachments can be manipulated via hints ([#2046](https://github.com/getsentry/sentry-java/pull/2046)) +- Hints are now used via a Hint object and passed into beforeSend and EventProcessor as @NotNull Hint object ([#2045](https://github.com/getsentry/sentry-java/pull/2045)) +- Attachments can be manipulated via hint ([#2046](https://github.com/getsentry/sentry-java/pull/2046)) ## 6.0.0-beta.3 diff --git a/sentry-android-core/api/sentry-android-core.api b/sentry-android-core/api/sentry-android-core.api index 1117339a3d..790255ecf5 100644 --- a/sentry-android-core/api/sentry-android-core.api +++ b/sentry-android-core/api/sentry-android-core.api @@ -110,7 +110,7 @@ public final class io/sentry/android/core/ScreenshotEventProcessor : android/app public fun onActivitySaveInstanceState (Landroid/app/Activity;Landroid/os/Bundle;)V public fun onActivityStarted (Landroid/app/Activity;)V public fun onActivityStopped (Landroid/app/Activity;)V - public fun process (Lio/sentry/SentryEvent;Lio/sentry/hints/Hints;)Lio/sentry/SentryEvent; + public fun process (Lio/sentry/SentryEvent;Lio/sentry/hints/Hint;)Lio/sentry/SentryEvent; } public final class io/sentry/android/core/SentryAndroid { diff --git a/sentry-android-core/src/main/java/io/sentry/android/core/ActivityLifecycleIntegration.java b/sentry-android-core/src/main/java/io/sentry/android/core/ActivityLifecycleIntegration.java index a8a1201adc..e381bead99 100644 --- a/sentry-android-core/src/main/java/io/sentry/android/core/ActivityLifecycleIntegration.java +++ b/sentry-android-core/src/main/java/io/sentry/android/core/ActivityLifecycleIntegration.java @@ -19,7 +19,7 @@ import io.sentry.SentryLevel; import io.sentry.SentryOptions; import io.sentry.SpanStatus; -import io.sentry.hints.Hints; +import io.sentry.hints.Hint; import io.sentry.util.Objects; import java.io.Closeable; import java.io.IOException; @@ -126,10 +126,10 @@ private void addBreadcrumb(final @NotNull Activity activity, final @NotNull Stri breadcrumb.setCategory("ui.lifecycle"); breadcrumb.setLevel(SentryLevel.INFO); - final Hints hints = new Hints(); - hints.set(ANDROID_ACTIVITY, activity); + final Hint hint = new Hint(); + hint.set(ANDROID_ACTIVITY, activity); - hub.addBreadcrumb(breadcrumb, hints); + hub.addBreadcrumb(breadcrumb, hint); } } diff --git a/sentry-android-core/src/main/java/io/sentry/android/core/AppComponentsBreadcrumbsIntegration.java b/sentry-android-core/src/main/java/io/sentry/android/core/AppComponentsBreadcrumbsIntegration.java index b062220037..5c1b186b4e 100644 --- a/sentry-android-core/src/main/java/io/sentry/android/core/AppComponentsBreadcrumbsIntegration.java +++ b/sentry-android-core/src/main/java/io/sentry/android/core/AppComponentsBreadcrumbsIntegration.java @@ -11,7 +11,7 @@ import io.sentry.SentryLevel; import io.sentry.SentryOptions; import io.sentry.android.core.internal.util.DeviceOrientations; -import io.sentry.hints.Hints; +import io.sentry.hints.Hint; import io.sentry.protocol.Device; import io.sentry.util.Objects; import java.io.Closeable; @@ -99,10 +99,10 @@ public void onConfigurationChanged(@NotNull Configuration newConfig) { breadcrumb.setData("position", orientation); breadcrumb.setLevel(SentryLevel.INFO); - final Hints hints = new Hints(); - hints.set(ANDROID_CONFIGURATION, newConfig); + final Hint hint = new Hint(); + hint.set(ANDROID_CONFIGURATION, newConfig); - hub.addBreadcrumb(breadcrumb, hints); + hub.addBreadcrumb(breadcrumb, hint); } } diff --git a/sentry-android-core/src/main/java/io/sentry/android/core/DefaultAndroidEventProcessor.java b/sentry-android-core/src/main/java/io/sentry/android/core/DefaultAndroidEventProcessor.java index d9947a42ae..d7a3d6f384 100644 --- a/sentry-android-core/src/main/java/io/sentry/android/core/DefaultAndroidEventProcessor.java +++ b/sentry-android-core/src/main/java/io/sentry/android/core/DefaultAndroidEventProcessor.java @@ -28,7 +28,7 @@ import io.sentry.android.core.internal.util.DeviceOrientations; import io.sentry.android.core.internal.util.MainThreadChecker; import io.sentry.android.core.internal.util.RootChecker; -import io.sentry.hints.Hints; +import io.sentry.hints.Hint; import io.sentry.protocol.App; import io.sentry.protocol.Device; import io.sentry.protocol.OperatingSystem; @@ -117,9 +117,8 @@ public DefaultAndroidEventProcessor( } @Override - public @NotNull SentryEvent process( - final @NotNull SentryEvent event, final @NotNull Hints hints) { - final boolean applyScopeData = shouldApplyScopeData(event, hints); + public @NotNull SentryEvent process(final @NotNull SentryEvent event, final @NotNull Hint hint) { + final boolean applyScopeData = shouldApplyScopeData(event, hint); if (applyScopeData) { // we only set memory data if it's not a hard crash, when it's a hard crash the event is // enriched on restart, so non static data might be wrong, eg lowMemory or availMem will @@ -144,8 +143,8 @@ private void setCommons( } private boolean shouldApplyScopeData( - final @NotNull SentryBaseEvent event, final @NotNull Hints hints) { - if (HintUtils.shouldApplyScopeData(hints)) { + final @NotNull SentryBaseEvent event, final @NotNull Hint hint) { + if (HintUtils.shouldApplyScopeData(hint)) { return true; } else { logger.log( @@ -858,8 +857,8 @@ private void setSideLoadedInfo(final @NotNull SentryBaseEvent event) { @Override public @NotNull SentryTransaction process( - final @NotNull SentryTransaction transaction, final @NotNull Hints hints) { - final boolean applyScopeData = shouldApplyScopeData(transaction, hints); + final @NotNull SentryTransaction transaction, final @NotNull Hint hint) { + final boolean applyScopeData = shouldApplyScopeData(transaction, hint); if (applyScopeData) { processNonCachedEvent(transaction); diff --git a/sentry-android-core/src/main/java/io/sentry/android/core/EnvelopeFileObserver.java b/sentry-android-core/src/main/java/io/sentry/android/core/EnvelopeFileObserver.java index 5442e015a1..2723b798db 100644 --- a/sentry-android-core/src/main/java/io/sentry/android/core/EnvelopeFileObserver.java +++ b/sentry-android-core/src/main/java/io/sentry/android/core/EnvelopeFileObserver.java @@ -9,7 +9,7 @@ import io.sentry.hints.ApplyScopeData; import io.sentry.hints.Cached; import io.sentry.hints.Flushable; -import io.sentry.hints.Hints; +import io.sentry.hints.Hint; import io.sentry.hints.Resettable; import io.sentry.hints.Retryable; import io.sentry.hints.SubmissionResult; @@ -57,11 +57,11 @@ public void onEvent(int eventType, @Nullable String relativePath) { // TODO: Only some event types should be pass through? - final CachedEnvelopeHint hint = new CachedEnvelopeHint(flushTimeoutMillis, logger); + final CachedEnvelopeHint cachedHint = new CachedEnvelopeHint(flushTimeoutMillis, logger); - final Hints hints = HintUtils.createWithTypeCheckHint(hint); + final Hint hint = HintUtils.createWithTypeCheckHint(cachedHint); - envelopeSender.processEnvelopeFile(this.rootPath + File.separator + relativePath, hints); + envelopeSender.processEnvelopeFile(this.rootPath + File.separator + relativePath, hint); } private static final class CachedEnvelopeHint diff --git a/sentry-android-core/src/main/java/io/sentry/android/core/PerformanceAndroidEventProcessor.java b/sentry-android-core/src/main/java/io/sentry/android/core/PerformanceAndroidEventProcessor.java index 5c7f5cbb5e..ae2dffc3b0 100644 --- a/sentry-android-core/src/main/java/io/sentry/android/core/PerformanceAndroidEventProcessor.java +++ b/sentry-android-core/src/main/java/io/sentry/android/core/PerformanceAndroidEventProcessor.java @@ -7,7 +7,7 @@ import io.sentry.EventProcessor; import io.sentry.SentryEvent; import io.sentry.SpanContext; -import io.sentry.hints.Hints; +import io.sentry.hints.Hint; import io.sentry.protocol.MeasurementValue; import io.sentry.protocol.SentryId; import io.sentry.protocol.SentrySpan; @@ -38,12 +38,12 @@ final class PerformanceAndroidEventProcessor implements EventProcessor { * Returns the event itself * * @param event the SentryEvent the SentryEvent - * @param hints the Hint the Hint + * @param hint the Hint the Hint * @return returns the event itself */ @Override @Nullable - public SentryEvent process(@NotNull SentryEvent event, @NotNull Hints hints) { + public SentryEvent process(@NotNull SentryEvent event, @NotNull Hint hint) { // that's only necessary because on newer versions of Unity, if not overriding this method, it's // throwing 'java.lang.AbstractMethodError: abstract method' and the reason is probably // compilation mismatch. @@ -53,7 +53,7 @@ public SentryEvent process(@NotNull SentryEvent event, @NotNull Hints hints) { @SuppressWarnings("NullAway") @Override public synchronized @NotNull SentryTransaction process( - @NotNull SentryTransaction transaction, @NotNull Hints hints) { + @NotNull SentryTransaction transaction, @NotNull Hint hint) { if (!options.isTracingEnabled()) { return transaction; diff --git a/sentry-android-core/src/main/java/io/sentry/android/core/ScreenshotEventProcessor.java b/sentry-android-core/src/main/java/io/sentry/android/core/ScreenshotEventProcessor.java index 4630e6a7bd..0583235a4a 100644 --- a/sentry-android-core/src/main/java/io/sentry/android/core/ScreenshotEventProcessor.java +++ b/sentry-android-core/src/main/java/io/sentry/android/core/ScreenshotEventProcessor.java @@ -16,7 +16,7 @@ import io.sentry.EventProcessor; import io.sentry.SentryEvent; import io.sentry.SentryLevel; -import io.sentry.hints.Hints; +import io.sentry.hints.Hint; import io.sentry.util.Objects; import java.io.ByteArrayOutputStream; import java.io.Closeable; @@ -66,7 +66,7 @@ public ScreenshotEventProcessor( @SuppressWarnings("NullAway") @Override - public @NotNull SentryEvent process(final @NotNull SentryEvent event, @NotNull Hints hints) { + public @NotNull SentryEvent process(final @NotNull SentryEvent event, @NotNull Hint hint) { if (options.isAttachScreenshot() && event.isErrored() && currentActivity != null) { final Activity activity = currentActivity.get(); if (isActivityValid(activity) @@ -92,8 +92,8 @@ public ScreenshotEventProcessor( if (byteArrayOutputStream.size() > 0) { // screenshot png is around ~100-150 kb - hints.setScreenshot(Attachment.fromScreenshot(byteArrayOutputStream.toByteArray())); - hints.set(ANDROID_ACTIVITY, activity); + hint.setScreenshot(Attachment.fromScreenshot(byteArrayOutputStream.toByteArray())); + hint.set(ANDROID_ACTIVITY, activity); } else { this.options .getLogger() diff --git a/sentry-android-core/src/main/java/io/sentry/android/core/SystemEventsBreadcrumbsIntegration.java b/sentry-android-core/src/main/java/io/sentry/android/core/SystemEventsBreadcrumbsIntegration.java index b39bcb7e30..36b38b8266 100644 --- a/sentry-android-core/src/main/java/io/sentry/android/core/SystemEventsBreadcrumbsIntegration.java +++ b/sentry-android-core/src/main/java/io/sentry/android/core/SystemEventsBreadcrumbsIntegration.java @@ -43,7 +43,7 @@ import io.sentry.Integration; import io.sentry.SentryLevel; import io.sentry.SentryOptions; -import io.sentry.hints.Hints; +import io.sentry.hints.Hint; import io.sentry.util.Objects; import io.sentry.util.StringUtils; import java.io.Closeable; @@ -216,10 +216,10 @@ public void onReceive(Context context, Intent intent) { } breadcrumb.setLevel(SentryLevel.INFO); - final Hints hints = new Hints(); - hints.set(ANDROID_INTENT, intent); + final Hint hint = new Hint(); + hint.set(ANDROID_INTENT, intent); - hub.addBreadcrumb(breadcrumb, hints); + hub.addBreadcrumb(breadcrumb, hint); } } } diff --git a/sentry-android-core/src/main/java/io/sentry/android/core/TempSensorBreadcrumbsIntegration.java b/sentry-android-core/src/main/java/io/sentry/android/core/TempSensorBreadcrumbsIntegration.java index 7ce2a80f74..edf8183abd 100644 --- a/sentry-android-core/src/main/java/io/sentry/android/core/TempSensorBreadcrumbsIntegration.java +++ b/sentry-android-core/src/main/java/io/sentry/android/core/TempSensorBreadcrumbsIntegration.java @@ -13,7 +13,7 @@ import io.sentry.Integration; import io.sentry.SentryLevel; import io.sentry.SentryOptions; -import io.sentry.hints.Hints; +import io.sentry.hints.Hint; import io.sentry.util.Objects; import java.io.Closeable; import java.io.IOException; @@ -106,10 +106,10 @@ public void onSensorChanged(final @NotNull SensorEvent event) { breadcrumb.setLevel(SentryLevel.INFO); breadcrumb.setData("degree", event.values[0]); // Celsius - final Hints hints = new Hints(); - hints.set(ANDROID_SENSOR_EVENT, event); + final Hint hint = new Hint(); + hint.set(ANDROID_SENSOR_EVENT, event); - hub.addBreadcrumb(breadcrumb, hints); + hub.addBreadcrumb(breadcrumb, hint); } } diff --git a/sentry-android-core/src/main/java/io/sentry/android/core/internal/gestures/SentryGestureListener.java b/sentry-android-core/src/main/java/io/sentry/android/core/internal/gestures/SentryGestureListener.java index 0a50967ec8..e2ef92f78b 100644 --- a/sentry-android-core/src/main/java/io/sentry/android/core/internal/gestures/SentryGestureListener.java +++ b/sentry-android-core/src/main/java/io/sentry/android/core/internal/gestures/SentryGestureListener.java @@ -11,7 +11,7 @@ import io.sentry.IHub; import io.sentry.SentryLevel; import io.sentry.android.core.SentryAndroidOptions; -import io.sentry.hints.Hints; +import io.sentry.hints.Hint; import java.lang.ref.WeakReference; import java.util.Collections; import java.util.Map; @@ -172,14 +172,14 @@ private void addBreadcrumb( className = target.getClass().getSimpleName(); } - final Hints hints = new Hints(); - hints.set(ANDROID_MOTION_EVENT, motionEvent); - hints.set(ANDROID_VIEW, target); + final Hint hint = new Hint(); + hint.set(ANDROID_MOTION_EVENT, motionEvent); + hint.set(ANDROID_VIEW, target); hub.addBreadcrumb( Breadcrumb.userInteraction( eventType, ViewUtils.getResourceId(target), className, additionalData), - hints); + hint); } private @Nullable View ensureWindowDecorView(final @NotNull String caller) { diff --git a/sentry-android-core/src/test/java/io/sentry/android/core/DefaultAndroidEventProcessorTest.kt b/sentry-android-core/src/test/java/io/sentry/android/core/DefaultAndroidEventProcessorTest.kt index 14d901d3a9..a862860415 100644 --- a/sentry-android-core/src/test/java/io/sentry/android/core/DefaultAndroidEventProcessorTest.kt +++ b/sentry-android-core/src/test/java/io/sentry/android/core/DefaultAndroidEventProcessorTest.kt @@ -20,7 +20,7 @@ import io.sentry.android.core.DefaultAndroidEventProcessor.EMULATOR import io.sentry.android.core.DefaultAndroidEventProcessor.KERNEL_VERSION import io.sentry.android.core.DefaultAndroidEventProcessor.ROOTED import io.sentry.android.core.DefaultAndroidEventProcessor.SIDE_LOADED -import io.sentry.hints.Hints +import io.sentry.hints.Hint import io.sentry.protocol.OperatingSystem import io.sentry.protocol.SdkVersion import io.sentry.protocol.SentryThread @@ -107,7 +107,7 @@ class DefaultAndroidEventProcessorTest { fun `When Event and hint is not Cached, data should be applied`() { val sut = fixture.getSut(context) - assertNotNull(sut.process(SentryEvent(), Hints())) { + assertNotNull(sut.process(SentryEvent(), Hint())) { assertNotNull(it.contexts.app) assertNotNull(it.dist) } @@ -117,7 +117,12 @@ class DefaultAndroidEventProcessorTest { fun `When Transaction and hint is not Cached, data should be applied`() { val sut = fixture.getSut(context) - assertNotNull(sut.process(SentryTransaction(fixture.sentryTracer), Hints())) { + assertNotNull( + sut.process( + SentryTransaction(fixture.sentryTracer), + Hint() + ) + ) { assertNotNull(it.contexts.app) assertNotNull(it.dist) } @@ -134,7 +139,7 @@ class DefaultAndroidEventProcessorTest { threads = mutableListOf(sentryThread) } - assertNotNull(sut.process(event, Hints())) { + assertNotNull(sut.process(event, Hint())) { assertNotNull(it.threads) { threads -> assertTrue(threads.first().isCurrent == true) } @@ -153,7 +158,7 @@ class DefaultAndroidEventProcessorTest { ) } - assertNotNull(sut.process(event, Hints())) { + assertNotNull(sut.process(event, Hint())) { assertNotNull(it.threads) { threads -> assertFalse(threads.first().isCurrent == true) } @@ -213,7 +218,7 @@ class DefaultAndroidEventProcessorTest { setUser(user) } - assertNotNull(sut.process(event, Hints())) { + assertNotNull(sut.process(event, Hint())) { assertNotNull(it.user) assertSame(user, it.user) } @@ -227,7 +232,7 @@ class DefaultAndroidEventProcessorTest { user = User() } - assertNotNull(sut.process(event, Hints())) { + assertNotNull(sut.process(event, Hint())) { assertNotNull(it.user) assertNotNull(it.user!!.id) } @@ -250,7 +255,7 @@ class DefaultAndroidEventProcessorTest { fun `Processor won't throw exception`() { val sut = fixture.getSut(context) - sut.process(SentryEvent(), Hints()) + sut.process(SentryEvent(), Hint()) verify((fixture.options.logger as DiagnosticLogger).logger, never())!!.log(eq(SentryLevel.ERROR), any(), any()) } @@ -269,7 +274,7 @@ class DefaultAndroidEventProcessorTest { fun `When event is processed, sideLoaded info should be set`() { val sut = fixture.getSut(context) - assertNotNull(sut.process(SentryEvent(), Hints())) { + assertNotNull(sut.process(SentryEvent(), Hint())) { assertNotNull(it.getTag("isSideLoaded")) } } @@ -285,7 +290,7 @@ class DefaultAndroidEventProcessorTest { contexts.setOperatingSystem(osLinux) } - assertNotNull(sut.process(event, Hints())) { + assertNotNull(sut.process(event, Hint())) { assertSame(osLinux, (it.contexts["os_linux"] as OperatingSystem)) assertEquals("Android", it.contexts.operatingSystem!!.name) } @@ -302,7 +307,7 @@ class DefaultAndroidEventProcessorTest { contexts.setOperatingSystem(osNoName) } - assertNotNull(sut.process(event, Hints())) { + assertNotNull(sut.process(event, Hint())) { assertSame(osNoName, (it.contexts["os_1"] as OperatingSystem)) assertEquals("Android", it.contexts.operatingSystem!!.name) } @@ -323,7 +328,7 @@ class DefaultAndroidEventProcessorTest { fun `When hint is not Cached, memory data should be applied`() { val sut = fixture.getSut(context) - assertNotNull(sut.process(SentryEvent(), Hints())) { + assertNotNull(sut.process(SentryEvent(), Hint())) { assertNotNull(it.contexts.device!!.freeMemory) assertNotNull(it.contexts.device!!.isLowMemory) } @@ -333,7 +338,12 @@ class DefaultAndroidEventProcessorTest { fun `Device's context is set on transactions`() { val sut = fixture.getSut(context) - assertNotNull(sut.process(SentryTransaction(fixture.sentryTracer), Hints())) { + assertNotNull( + sut.process( + SentryTransaction(fixture.sentryTracer), + Hint() + ) + ) { assertNotNull(it.contexts.device) } } @@ -342,7 +352,12 @@ class DefaultAndroidEventProcessorTest { fun `Device's OS is set on transactions`() { val sut = fixture.getSut(context) - assertNotNull(sut.process(SentryTransaction(fixture.sentryTracer), Hints())) { + assertNotNull( + sut.process( + SentryTransaction(fixture.sentryTracer), + Hint() + ) + ) { assertNotNull(it.contexts.operatingSystem) } } @@ -351,7 +366,12 @@ class DefaultAndroidEventProcessorTest { fun `Transaction do not set device's context that requires heavy work`() { val sut = fixture.getSut(context) - assertNotNull(sut.process(SentryTransaction(fixture.sentryTracer), Hints())) { + assertNotNull( + sut.process( + SentryTransaction(fixture.sentryTracer), + Hint() + ) + ) { val device = it.contexts.device!! assertNull(device.batteryLevel) assertNull(device.isCharging) @@ -371,7 +391,7 @@ class DefaultAndroidEventProcessorTest { fun `Event sets device's context that requires heavy work`() { val sut = fixture.getSut(context) - assertNotNull(sut.process(SentryEvent(), Hints())) { + assertNotNull(sut.process(SentryEvent(), Hint())) { val device = it.contexts.device!! assertNotNull(device.freeMemory) assertNotNull(device.isLowMemory) @@ -393,7 +413,7 @@ class DefaultAndroidEventProcessorTest { fun `Event sets language and locale`() { val sut = fixture.getSut(context) - assertNotNull(sut.process(SentryEvent(), Hints())) { + assertNotNull(sut.process(SentryEvent(), Hint())) { val device = it.contexts.device!! assertEquals("en", device.language) assertEquals("en_US", device.locale) diff --git a/sentry-android-core/src/test/java/io/sentry/android/core/PerformanceAndroidEventProcessorTest.kt b/sentry-android-core/src/test/java/io/sentry/android/core/PerformanceAndroidEventProcessorTest.kt index fe1446cf95..fda61660d1 100644 --- a/sentry-android-core/src/test/java/io/sentry/android/core/PerformanceAndroidEventProcessorTest.kt +++ b/sentry-android-core/src/test/java/io/sentry/android/core/PerformanceAndroidEventProcessorTest.kt @@ -7,7 +7,7 @@ import io.sentry.IHub import io.sentry.SentryTracer import io.sentry.TransactionContext import io.sentry.android.core.ActivityLifecycleIntegration.UI_LOAD_OP -import io.sentry.hints.Hints +import io.sentry.hints.Hint import io.sentry.protocol.MeasurementValue import io.sentry.protocol.SentryTransaction import java.util.Date @@ -46,7 +46,7 @@ class PerformanceAndroidEventProcessorTest { var tr = getTransaction() setAppStart() - tr = sut.process(tr, Hints()) + tr = sut.process(tr, Hint()) assertTrue(tr.measurements.containsKey("app_start_cold")) } @@ -58,7 +58,7 @@ class PerformanceAndroidEventProcessorTest { var tr = getTransaction("app.start.warm") setAppStart(false) - tr = sut.process(tr, Hints()) + tr = sut.process(tr, Hint()) assertTrue(tr.measurements.containsKey("app_start_warm")) } @@ -70,10 +70,10 @@ class PerformanceAndroidEventProcessorTest { var tr1 = getTransaction() setAppStart(false) - tr1 = sut.process(tr1, Hints()) + tr1 = sut.process(tr1, Hint()) var tr2 = getTransaction() - tr2 = sut.process(tr2, Hints()) + tr2 = sut.process(tr2, Hint()) assertTrue(tr1.measurements.containsKey("app_start_warm")) assertTrue(tr2.measurements.isEmpty()) @@ -85,7 +85,7 @@ class PerformanceAndroidEventProcessorTest { var tr = getTransaction() - tr = sut.process(tr, Hints()) + tr = sut.process(tr, Hint()) assertTrue(tr.measurements.isEmpty()) } @@ -96,7 +96,7 @@ class PerformanceAndroidEventProcessorTest { var tr = getTransaction() - tr = sut.process(tr, Hints()) + tr = sut.process(tr, Hint()) assertTrue(tr.measurements.isEmpty()) } @@ -107,7 +107,7 @@ class PerformanceAndroidEventProcessorTest { var tr = getTransaction("task") - tr = sut.process(tr, Hints()) + tr = sut.process(tr, Hint()) assertTrue(tr.measurements.isEmpty()) } @@ -117,7 +117,7 @@ class PerformanceAndroidEventProcessorTest { val sut = fixture.getSut() var tr = getTransaction("task") - tr = sut.process(tr, Hints()) + tr = sut.process(tr, Hint()) assertTrue(tr.measurements.isEmpty()) } @@ -127,7 +127,7 @@ class PerformanceAndroidEventProcessorTest { val sut = fixture.getSut(null) var tr = getTransaction("task") - tr = sut.process(tr, Hints()) + tr = sut.process(tr, Hint()) assertTrue(tr.measurements.isEmpty()) } @@ -142,7 +142,7 @@ class PerformanceAndroidEventProcessorTest { val metrics = mapOf("frames_total" to MeasurementValue(1f)) whenever(fixture.activityFramesTracker.takeMetrics(any())).thenReturn(metrics) - tr = sut.process(tr, Hints()) + tr = sut.process(tr, Hint()) assertTrue(tr.measurements.containsKey("frames_total")) } diff --git a/sentry-android-core/src/test/java/io/sentry/android/core/ScreenshotEventProcessorTest.kt b/sentry-android-core/src/test/java/io/sentry/android/core/ScreenshotEventProcessorTest.kt index 0db193574a..4665eacf0f 100644 --- a/sentry-android-core/src/test/java/io/sentry/android/core/ScreenshotEventProcessorTest.kt +++ b/sentry-android-core/src/test/java/io/sentry/android/core/ScreenshotEventProcessorTest.kt @@ -14,7 +14,7 @@ import io.sentry.Attachment import io.sentry.MainEventProcessor import io.sentry.SentryEvent import io.sentry.TypeCheckHint.ANDROID_ACTIVITY -import io.sentry.hints.Hints +import io.sentry.hints.Hint import org.junit.runner.RunWith import kotlin.test.BeforeTest import kotlin.test.Test @@ -95,99 +95,99 @@ class ScreenshotEventProcessorTest { @Test fun `when process is called and attachScreenshot is disabled, does nothing`() { val sut = fixture.getSut(false) - val hints = Hints() + val hint = Hint() sut.onActivityCreated(fixture.activity, null) - val event = fixture.mainProcessor.process(getEvent(), hints) - sut.process(event, hints) + val event = fixture.mainProcessor.process(getEvent(), hint) + sut.process(event, hint) - assertNull(hints.screenshot) + assertNull(hint.screenshot) } @Test fun `when event is not errored, does nothing`() { val sut = fixture.getSut(true) - val hints = Hints() + val hint = Hint() sut.onActivityCreated(fixture.activity, null) - val event = fixture.mainProcessor.process(SentryEvent(), hints) - sut.process(event, hints) + val event = fixture.mainProcessor.process(SentryEvent(), hint) + sut.process(event, hint) - assertNull(hints.screenshot) + assertNull(hint.screenshot) } @Test fun `when there is not activity, does nothing`() { val sut = fixture.getSut(true) - val hints = Hints() + val hint = Hint() - val event = fixture.mainProcessor.process(getEvent(), hints) - sut.process(event, hints) + val event = fixture.mainProcessor.process(getEvent(), hint) + sut.process(event, hint) - assertNull(hints.screenshot) + assertNull(hint.screenshot) } @Test fun `when activity is finishing, does nothing`() { val sut = fixture.getSut(true) - val hints = Hints() + val hint = Hint() whenever(fixture.activity.isFinishing).thenReturn(true) sut.onActivityCreated(fixture.activity, null) - val event = fixture.mainProcessor.process(getEvent(), hints) - sut.process(event, hints) + val event = fixture.mainProcessor.process(getEvent(), hint) + sut.process(event, hint) - assertNull(hints.screenshot) + assertNull(hint.screenshot) } @Test fun `when view is zeroed, does nothing`() { val sut = fixture.getSut(true) - val hints = Hints() + val hint = Hint() whenever(fixture.rootView.width).thenReturn(0) whenever(fixture.rootView.height).thenReturn(0) sut.onActivityCreated(fixture.activity, null) - val event = fixture.mainProcessor.process(getEvent(), hints) - sut.process(event, hints) + val event = fixture.mainProcessor.process(getEvent(), hint) + sut.process(event, hint) - assertNull(hints.screenshot) + assertNull(hint.screenshot) } @Test fun `when process is called and attachScreenshot is enabled, add attachment to hints`() { val sut = fixture.getSut(true) - val hints = Hints() + val hint = Hint() sut.onActivityCreated(fixture.activity, null) - val event = fixture.mainProcessor.process(getEvent(), hints) - sut.process(event, hints) + val event = fixture.mainProcessor.process(getEvent(), hint) + sut.process(event, hint) - val screenshot = hints.screenshot + val screenshot = hint.screenshot assertTrue(screenshot is Attachment) assertEquals("screenshot.png", screenshot.filename) assertEquals("image/png", screenshot.contentType) - assertSame(fixture.activity, hints[ANDROID_ACTIVITY]) + assertSame(fixture.activity, hint[ANDROID_ACTIVITY]) } @Test fun `when activity is destroyed, does nothing`() { val sut = fixture.getSut(true) - val hints = Hints() + val hint = Hint() sut.onActivityCreated(fixture.activity, null) sut.onActivityDestroyed(fixture.activity) - val event = fixture.mainProcessor.process(getEvent(), hints) - sut.process(event, hints) + val event = fixture.mainProcessor.process(getEvent(), hint) + sut.process(event, hint) - assertNull(hints.screenshot) + assertNull(hint.screenshot) } private fun getEvent(): SentryEvent = SentryEvent(Throwable("Throwable")) diff --git a/sentry-android-fragment/src/main/java/io/sentry/android/fragment/SentryFragmentLifecycleCallbacks.kt b/sentry-android-fragment/src/main/java/io/sentry/android/fragment/SentryFragmentLifecycleCallbacks.kt index d66036f366..edd4e29e61 100644 --- a/sentry-android-fragment/src/main/java/io/sentry/android/fragment/SentryFragmentLifecycleCallbacks.kt +++ b/sentry-android-fragment/src/main/java/io/sentry/android/fragment/SentryFragmentLifecycleCallbacks.kt @@ -13,7 +13,7 @@ import io.sentry.ISpan import io.sentry.SentryLevel.INFO import io.sentry.SpanStatus import io.sentry.TypeCheckHint.ANDROID_FRAGMENT -import io.sentry.hints.Hints +import io.sentry.hints.Hint import java.util.WeakHashMap @Suppress("TooManyFunctions") @@ -119,9 +119,10 @@ class SentryFragmentLifecycleCallbacks( level = INFO } - val hints = Hints().also { it.set(ANDROID_FRAGMENT, fragment) } + val hint = Hint() + .also { it.set(ANDROID_FRAGMENT, fragment) } - hub.addBreadcrumb(breadcrumb, hints) + hub.addBreadcrumb(breadcrumb, hint) } private fun getFragmentName(fragment: Fragment): String { diff --git a/sentry-android-okhttp/src/main/java/io/sentry/android/okhttp/SentryOkHttpInterceptor.kt b/sentry-android-okhttp/src/main/java/io/sentry/android/okhttp/SentryOkHttpInterceptor.kt index b50f2c8381..10c7f4b2bb 100644 --- a/sentry-android-okhttp/src/main/java/io/sentry/android/okhttp/SentryOkHttpInterceptor.kt +++ b/sentry-android-okhttp/src/main/java/io/sentry/android/okhttp/SentryOkHttpInterceptor.kt @@ -8,7 +8,7 @@ import io.sentry.SpanStatus import io.sentry.TracingOrigins import io.sentry.TypeCheckHint.OKHTTP_REQUEST import io.sentry.TypeCheckHint.OKHTTP_RESPONSE -import io.sentry.hints.Hints +import io.sentry.hints.Hint import okhttp3.Interceptor import okhttp3.Request import okhttp3.Response @@ -63,16 +63,17 @@ class SentryOkHttpInterceptor( breadcrumb.setData("request_body_size", it) } - val hints = Hints().also { it.set(OKHTTP_REQUEST, request) } + val hint = Hint() + .also { it.set(OKHTTP_REQUEST, request) } response?.let { it.body?.contentLength().ifHasValidLength { responseBodySize -> breadcrumb.setData("response_body_size", responseBodySize) } - hints[OKHTTP_RESPONSE] = it + hint[OKHTTP_RESPONSE] = it } - hub.addBreadcrumb(breadcrumb, hints) + hub.addBreadcrumb(breadcrumb, hint) } } diff --git a/sentry-apache-http-client-5/api/sentry-apache-http-client-5.api b/sentry-apache-http-client-5/api/sentry-apache-http-client-5.api index df1a42131e..b7ec1ca4a7 100644 --- a/sentry-apache-http-client-5/api/sentry-apache-http-client-5.api +++ b/sentry-apache-http-client-5/api/sentry-apache-http-client-5.api @@ -2,7 +2,7 @@ public final class io/sentry/transport/apache/ApacheHttpClientTransport : io/sen public fun (Lio/sentry/SentryOptions;Lio/sentry/RequestDetails;Lorg/apache/hc/client5/http/impl/async/CloseableHttpAsyncClient;Lio/sentry/transport/RateLimiter;)V public fun close ()V public fun flush (J)V - public fun send (Lio/sentry/SentryEnvelope;Lio/sentry/hints/Hints;)V + public fun send (Lio/sentry/SentryEnvelope;Lio/sentry/hints/Hint;)V } public final class io/sentry/transport/apache/ApacheHttpClientTransportFactory : io/sentry/ITransportFactory { diff --git a/sentry-apache-http-client-5/src/main/java/io/sentry/transport/apache/ApacheHttpClientTransport.java b/sentry-apache-http-client-5/src/main/java/io/sentry/transport/apache/ApacheHttpClientTransport.java index 36abe7769f..0dee7688ed 100644 --- a/sentry-apache-http-client-5/src/main/java/io/sentry/transport/apache/ApacheHttpClientTransport.java +++ b/sentry-apache-http-client-5/src/main/java/io/sentry/transport/apache/ApacheHttpClientTransport.java @@ -7,7 +7,7 @@ import io.sentry.SentryLevel; import io.sentry.SentryOptions; import io.sentry.clientreport.DiscardReason; -import io.sentry.hints.Hints; +import io.sentry.hints.Hint; import io.sentry.hints.Retryable; import io.sentry.transport.ITransport; import io.sentry.transport.RateLimiter; @@ -66,10 +66,10 @@ public ApacheHttpClientTransport( @Override @SuppressWarnings("FutureReturnValueIgnored") - public void send(final @NotNull SentryEnvelope envelope, final @NotNull Hints hints) + public void send(final @NotNull SentryEnvelope envelope, final @NotNull Hint hint) throws IOException { if (isSchedulingAllowed()) { - final SentryEnvelope filteredEnvelope = rateLimiter.filter(envelope, hints); + final SentryEnvelope filteredEnvelope = rateLimiter.filter(envelope, hint); if (filteredEnvelope != null) { final SentryEnvelope envelopeWithClientReport = @@ -110,7 +110,7 @@ public void completed(SimpleHttpResponse response) { .log(ERROR, "Request failed, API returned %s", response.getCode()); if (response.getCode() >= 400 && response.getCode() != 429) { - if (!HintUtils.hasType(hints, Retryable.class)) { + if (!HintUtils.hasType(hint, Retryable.class)) { options .getClientReportRecorder() .recordLostEnvelope( @@ -132,7 +132,7 @@ public void completed(SimpleHttpResponse response) { @Override public void failed(Exception ex) { options.getLogger().log(ERROR, "Error while sending an envelope", ex); - if (!HintUtils.hasType(hints, Retryable.class)) { + if (!HintUtils.hasType(hint, Retryable.class)) { options .getClientReportRecorder() .recordLostEnvelope( @@ -144,7 +144,7 @@ public void failed(Exception ex) { @Override public void cancelled() { options.getLogger().log(WARNING, "Request cancelled"); - if (!HintUtils.hasType(hints, Retryable.class)) { + if (!HintUtils.hasType(hint, Retryable.class)) { options .getClientReportRecorder() .recordLostEnvelope( @@ -155,7 +155,7 @@ public void cancelled() { }); } catch (Throwable e) { options.getLogger().log(ERROR, "Error when sending envelope", e); - if (!HintUtils.hasType(hints, Retryable.class)) { + if (!HintUtils.hasType(hint, Retryable.class)) { options .getClientReportRecorder() .recordLostEnvelope(DiscardReason.NETWORK_ERROR, envelopeWithClientReport); diff --git a/sentry-apollo/src/main/java/io/sentry/apollo/SentryApolloInterceptor.kt b/sentry-apollo/src/main/java/io/sentry/apollo/SentryApolloInterceptor.kt index aa17e8b06b..63ef1209dc 100644 --- a/sentry-apollo/src/main/java/io/sentry/apollo/SentryApolloInterceptor.kt +++ b/sentry-apollo/src/main/java/io/sentry/apollo/SentryApolloInterceptor.kt @@ -19,7 +19,7 @@ import io.sentry.SentryLevel import io.sentry.SpanStatus import io.sentry.TypeCheckHint.APOLLO_REQUEST import io.sentry.TypeCheckHint.APOLLO_RESPONSE -import io.sentry.hints.Hints +import io.sentry.hints.Hint import java.util.concurrent.Executor class SentryApolloInterceptor( @@ -116,11 +116,11 @@ class SentryApolloInterceptor( breadcrumb.setData("response_body_size", contentLength) } - val hints = Hints().also { + val hint = Hint().also { it.set(APOLLO_REQUEST, httpRequest) it.set(APOLLO_RESPONSE, httpResponse) } - hub.addBreadcrumb(breadcrumb, hints) + hub.addBreadcrumb(breadcrumb, hint) } } } diff --git a/sentry-graphql/src/main/java/io/sentry/graphql/SentryDataFetcherExceptionHandler.java b/sentry-graphql/src/main/java/io/sentry/graphql/SentryDataFetcherExceptionHandler.java index d64cc9719f..b9526a3a63 100644 --- a/sentry-graphql/src/main/java/io/sentry/graphql/SentryDataFetcherExceptionHandler.java +++ b/sentry-graphql/src/main/java/io/sentry/graphql/SentryDataFetcherExceptionHandler.java @@ -7,7 +7,7 @@ import graphql.execution.DataFetcherExceptionHandlerResult; import io.sentry.HubAdapter; import io.sentry.IHub; -import io.sentry.hints.Hints; +import io.sentry.hints.Hint; import io.sentry.util.Objects; import org.jetbrains.annotations.NotNull; @@ -33,10 +33,10 @@ public SentryDataFetcherExceptionHandler(final @NotNull DataFetcherExceptionHand @SuppressWarnings("deprecation") public DataFetcherExceptionHandlerResult onException( final @NotNull DataFetcherExceptionHandlerParameters handlerParameters) { - final Hints hints = new Hints(); - hints.set(GRAPHQL_HANDLER_PARAMETERS, handlerParameters); + final Hint hint = new Hint(); + hint.set(GRAPHQL_HANDLER_PARAMETERS, handlerParameters); - hub.captureException(handlerParameters.getException(), hints); + hub.captureException(handlerParameters.getException(), hint); return delegate.onException(handlerParameters); } } diff --git a/sentry-jul/src/main/java/io/sentry/jul/SentryHandler.java b/sentry-jul/src/main/java/io/sentry/jul/SentryHandler.java index 40ecee562e..b4cbc23483 100644 --- a/sentry-jul/src/main/java/io/sentry/jul/SentryHandler.java +++ b/sentry-jul/src/main/java/io/sentry/jul/SentryHandler.java @@ -9,7 +9,7 @@ import io.sentry.SentryEvent; import io.sentry.SentryLevel; import io.sentry.SentryOptions; -import io.sentry.hints.Hints; +import io.sentry.hints.Hint; import io.sentry.protocol.Message; import io.sentry.protocol.SdkVersion; import io.sentry.util.CollectionUtils; @@ -81,16 +81,16 @@ public void publish(final @NotNull LogRecord record) { } try { if (record.getLevel().intValue() >= minimumEventLevel.intValue()) { - final Hints hints = new Hints(); - hints.set(SENTRY_SYNTHETIC_EXCEPTION, record); + final Hint hint = new Hint(); + hint.set(SENTRY_SYNTHETIC_EXCEPTION, record); - Sentry.captureEvent(createEvent(record), hints); + Sentry.captureEvent(createEvent(record), hint); } if (record.getLevel().intValue() >= minimumBreadcrumbLevel.intValue()) { - final Hints hints = new Hints(); - hints.set(JUL_LOG_RECORD, record); + final Hint hint = new Hint(); + hint.set(JUL_LOG_RECORD, record); - Sentry.addBreadcrumb(createBreadcrumb(record), hints); + Sentry.addBreadcrumb(createBreadcrumb(record), hint); } } catch (RuntimeException e) { reportError( diff --git a/sentry-log4j2/src/main/java/io/sentry/log4j2/SentryAppender.java b/sentry-log4j2/src/main/java/io/sentry/log4j2/SentryAppender.java index bb95d19531..93ede9f59e 100644 --- a/sentry-log4j2/src/main/java/io/sentry/log4j2/SentryAppender.java +++ b/sentry-log4j2/src/main/java/io/sentry/log4j2/SentryAppender.java @@ -13,7 +13,7 @@ import io.sentry.SentryEvent; import io.sentry.SentryLevel; import io.sentry.SentryOptions; -import io.sentry.hints.Hints; +import io.sentry.hints.Hint; import io.sentry.protocol.Message; import io.sentry.protocol.SdkVersion; import io.sentry.util.CollectionUtils; @@ -139,16 +139,16 @@ public void start() { @Override public void append(final @NotNull LogEvent eventObject) { if (eventObject.getLevel().isMoreSpecificThan(minimumEventLevel)) { - final Hints hints = new Hints(); - hints.set(SENTRY_SYNTHETIC_EXCEPTION, eventObject); + final Hint hint = new Hint(); + hint.set(SENTRY_SYNTHETIC_EXCEPTION, eventObject); - hub.captureEvent(createEvent(eventObject), hints); + hub.captureEvent(createEvent(eventObject), hint); } if (eventObject.getLevel().isMoreSpecificThan(minimumBreadcrumbLevel)) { - final Hints hints = new Hints(); - hints.set(LOG4J_LOG_EVENT, eventObject); + final Hint hint = new Hint(); + hint.set(LOG4J_LOG_EVENT, eventObject); - hub.addBreadcrumb(createBreadcrumb(eventObject), hints); + hub.addBreadcrumb(createBreadcrumb(eventObject), hint); } } diff --git a/sentry-logback/src/main/java/io/sentry/logback/SentryAppender.java b/sentry-logback/src/main/java/io/sentry/logback/SentryAppender.java index 87fc1f91d7..941f139aa9 100644 --- a/sentry-logback/src/main/java/io/sentry/logback/SentryAppender.java +++ b/sentry-logback/src/main/java/io/sentry/logback/SentryAppender.java @@ -15,7 +15,7 @@ import io.sentry.SentryEvent; import io.sentry.SentryLevel; import io.sentry.SentryOptions; -import io.sentry.hints.Hints; +import io.sentry.hints.Hint; import io.sentry.protocol.Message; import io.sentry.protocol.SdkVersion; import io.sentry.util.CollectionUtils; @@ -63,16 +63,16 @@ public void start() { @Override protected void append(@NotNull ILoggingEvent eventObject) { if (eventObject.getLevel().isGreaterOrEqual(minimumEventLevel)) { - final Hints hints = new Hints(); - hints.set(SENTRY_SYNTHETIC_EXCEPTION, eventObject); + final Hint hint = new Hint(); + hint.set(SENTRY_SYNTHETIC_EXCEPTION, eventObject); - Sentry.captureEvent(createEvent(eventObject), hints); + Sentry.captureEvent(createEvent(eventObject), hint); } if (eventObject.getLevel().isGreaterOrEqual(minimumBreadcrumbLevel)) { - final Hints hints = new Hints(); - hints.set(LOGBACK_LOGGING_EVENT, eventObject); + final Hint hint = new Hint(); + hint.set(LOGBACK_LOGGING_EVENT, eventObject); - Sentry.addBreadcrumb(createBreadcrumb(eventObject), hints); + Sentry.addBreadcrumb(createBreadcrumb(eventObject), hint); } } diff --git a/sentry-openfeign/src/main/java/io/sentry/openfeign/SentryFeignClient.java b/sentry-openfeign/src/main/java/io/sentry/openfeign/SentryFeignClient.java index 4d89a4ebce..361b743340 100644 --- a/sentry-openfeign/src/main/java/io/sentry/openfeign/SentryFeignClient.java +++ b/sentry-openfeign/src/main/java/io/sentry/openfeign/SentryFeignClient.java @@ -11,7 +11,7 @@ import io.sentry.ISpan; import io.sentry.SentryTraceHeader; import io.sentry.SpanStatus; -import io.sentry.hints.Hints; +import io.sentry.hints.Hint; import io.sentry.util.Objects; import java.io.IOException; import java.util.Collection; @@ -92,13 +92,13 @@ private void addBreadcrumb(final @NotNull Request request, final @Nullable Respo breadcrumb.setData("response_body_size", response.body().length()); } - final Hints hints = new Hints(); - hints.set(OPEN_FEIGN_REQUEST, request); + final Hint hint = new Hint(); + hint.set(OPEN_FEIGN_REQUEST, request); if (response != null) { - hints.set(OPEN_FEIGN_RESPONSE, response); + hint.set(OPEN_FEIGN_RESPONSE, response); } - hub.addBreadcrumb(breadcrumb, hints); + hub.addBreadcrumb(breadcrumb, hint); } static final class RequestWrapper { diff --git a/sentry-samples/sentry-samples-console/src/main/java/io/sentry/samples/console/Main.java b/sentry-samples/sentry-samples-console/src/main/java/io/sentry/samples/console/Main.java index 3b922df84c..29d3ca0271 100644 --- a/sentry-samples/sentry-samples-console/src/main/java/io/sentry/samples/console/Main.java +++ b/sentry-samples/sentry-samples-console/src/main/java/io/sentry/samples/console/Main.java @@ -8,7 +8,7 @@ import io.sentry.SentryEvent; import io.sentry.SentryLevel; import io.sentry.SpanStatus; -import io.sentry.hints.Hints; +import io.sentry.hints.Hint; import io.sentry.protocol.Message; import io.sentry.protocol.User; import java.util.Collections; @@ -136,9 +136,9 @@ public static void main(String[] args) throws InterruptedException { SentryEvent event = new SentryEvent(); event.setMessage(message); - final Hints hints = new Hints(); - hints.set("level", SentryLevel.DEBUG); - Sentry.captureEvent(event, hints); + final Hint hint = new Hint(); + hint.set("level", SentryLevel.DEBUG); + Sentry.captureEvent(event, hint); } // Performance feature @@ -170,7 +170,7 @@ public static void main(String[] args) throws InterruptedException { private static class SomeEventProcessor implements EventProcessor { @Override - public SentryEvent process(SentryEvent event, Hints hints) { + public SentryEvent process(SentryEvent event, Hint hint) { // Here you can modify the event as you need if (event.getLevel() != null && event.getLevel().ordinal() > SentryLevel.INFO.ordinal()) { event.addBreadcrumb(new Breadcrumb("Processed by " + SomeEventProcessor.class)); diff --git a/sentry-samples/sentry-samples-spring-boot/src/main/java/io/sentry/samples/spring/boot/CustomEventProcessor.java b/sentry-samples/sentry-samples-spring-boot/src/main/java/io/sentry/samples/spring/boot/CustomEventProcessor.java index 00e90d0002..1ef69b9671 100644 --- a/sentry-samples/sentry-samples-spring-boot/src/main/java/io/sentry/samples/spring/boot/CustomEventProcessor.java +++ b/sentry-samples/sentry-samples-spring-boot/src/main/java/io/sentry/samples/spring/boot/CustomEventProcessor.java @@ -2,7 +2,7 @@ import io.sentry.EventProcessor; import io.sentry.SentryEvent; -import io.sentry.hints.Hints; +import io.sentry.hints.Hint; import io.sentry.protocol.SentryRuntime; import org.jetbrains.annotations.NotNull; import org.springframework.boot.SpringBootVersion; @@ -25,7 +25,7 @@ public CustomEventProcessor() { } @Override - public @NotNull SentryEvent process(@NotNull SentryEvent event, @NotNull Hints hints) { + public @NotNull SentryEvent process(@NotNull SentryEvent event, @NotNull Hint hint) { final SentryRuntime runtime = new SentryRuntime(); runtime.setVersion(springBootVersion); runtime.setName("Spring Boot"); diff --git a/sentry-servlet-jakarta/src/main/java/io/sentry/servlet/jakarta/SentryRequestHttpServletRequestProcessor.java b/sentry-servlet-jakarta/src/main/java/io/sentry/servlet/jakarta/SentryRequestHttpServletRequestProcessor.java index 1310576026..101bd8585b 100644 --- a/sentry-servlet-jakarta/src/main/java/io/sentry/servlet/jakarta/SentryRequestHttpServletRequestProcessor.java +++ b/sentry-servlet-jakarta/src/main/java/io/sentry/servlet/jakarta/SentryRequestHttpServletRequestProcessor.java @@ -2,7 +2,7 @@ import io.sentry.EventProcessor; import io.sentry.SentryEvent; -import io.sentry.hints.Hints; +import io.sentry.hints.Hint; import io.sentry.protocol.Request; import io.sentry.util.Objects; import jakarta.servlet.http.HttpServletRequest; @@ -30,7 +30,7 @@ public SentryRequestHttpServletRequestProcessor(@NotNull HttpServletRequest http // httpRequest.getRequestURL() returns StringBuffer which is considered an obsolete class. @SuppressWarnings("JdkObsolete") @Override - public @NotNull SentryEvent process(@NotNull SentryEvent event, @NotNull Hints hints) { + public @NotNull SentryEvent process(@NotNull SentryEvent event, @NotNull Hint hint) { final Request sentryRequest = new Request(); sentryRequest.setMethod(httpRequest.getMethod()); sentryRequest.setQueryString(httpRequest.getQueryString()); diff --git a/sentry-servlet-jakarta/src/main/java/io/sentry/servlet/jakarta/SentryServletRequestListener.java b/sentry-servlet-jakarta/src/main/java/io/sentry/servlet/jakarta/SentryServletRequestListener.java index 416b984450..e3c759bc96 100644 --- a/sentry-servlet-jakarta/src/main/java/io/sentry/servlet/jakarta/SentryServletRequestListener.java +++ b/sentry-servlet-jakarta/src/main/java/io/sentry/servlet/jakarta/SentryServletRequestListener.java @@ -6,7 +6,7 @@ import io.sentry.Breadcrumb; import io.sentry.HubAdapter; import io.sentry.IHub; -import io.sentry.hints.Hints; +import io.sentry.hints.Hint; import io.sentry.util.Objects; import jakarta.servlet.ServletRequest; import jakarta.servlet.ServletRequestEvent; @@ -44,11 +44,11 @@ public void requestInitialized(@NotNull ServletRequestEvent servletRequestEvent) if (servletRequest instanceof HttpServletRequest) { final HttpServletRequest httpRequest = (HttpServletRequest) servletRequest; - final Hints hints = new Hints(); - hints.set(SERVLET_REQUEST, httpRequest); + final Hint hint = new Hint(); + hint.set(SERVLET_REQUEST, httpRequest); hub.addBreadcrumb( - Breadcrumb.http(httpRequest.getRequestURI(), httpRequest.getMethod()), hints); + Breadcrumb.http(httpRequest.getRequestURI(), httpRequest.getMethod()), hint); hub.configureScope( scope -> { diff --git a/sentry-servlet-jakarta/src/test/kotlin/io/sentry/servlet/jakarta/SentryRequestHttpServletRequestProcessorTest.kt b/sentry-servlet-jakarta/src/test/kotlin/io/sentry/servlet/jakarta/SentryRequestHttpServletRequestProcessorTest.kt index 9668a93af7..e696a621a7 100644 --- a/sentry-servlet-jakarta/src/test/kotlin/io/sentry/servlet/jakarta/SentryRequestHttpServletRequestProcessorTest.kt +++ b/sentry-servlet-jakarta/src/test/kotlin/io/sentry/servlet/jakarta/SentryRequestHttpServletRequestProcessorTest.kt @@ -5,7 +5,7 @@ import com.nhaarman.mockitokotlin2.mock import com.nhaarman.mockitokotlin2.whenever import io.sentry.SentryEvent import io.sentry.SentryOptions -import io.sentry.hints.Hints +import io.sentry.hints.Hint import jakarta.servlet.http.HttpServletRequest import java.net.URI import java.util.Collections @@ -30,7 +30,7 @@ class SentryRequestHttpServletRequestProcessorTest { val eventProcessor = SentryRequestHttpServletRequestProcessor(request) val event = SentryEvent() - eventProcessor.process(event, Hints()) + eventProcessor.process(event, Hint()) assertNotNull(event.request) val eventRequest = event.request!! @@ -57,7 +57,7 @@ class SentryRequestHttpServletRequestProcessorTest { val eventProcessor = SentryRequestHttpServletRequestProcessor(request) val event = SentryEvent() - eventProcessor.process(event, Hints()) + eventProcessor.process(event, Hint()) assertNotNull(event.request) { assertEquals( @@ -82,7 +82,7 @@ class SentryRequestHttpServletRequestProcessorTest { val eventProcessor = SentryRequestHttpServletRequestProcessor(request) val event = SentryEvent() - eventProcessor.process(event, Hints()) + eventProcessor.process(event, Hint()) assertNotNull(event.request) { assertNull(it.cookies) @@ -106,7 +106,7 @@ class SentryRequestHttpServletRequestProcessorTest { val eventProcessor = SentryRequestHttpServletRequestProcessor(request) val event = SentryEvent() - eventProcessor.process(event, Hints()) + eventProcessor.process(event, Hint()) assertNotNull(event.request) { req -> assertNotNull(req.headers) { diff --git a/sentry-servlet/src/main/java/io/sentry/servlet/SentryRequestHttpServletRequestProcessor.java b/sentry-servlet/src/main/java/io/sentry/servlet/SentryRequestHttpServletRequestProcessor.java index 0ff80fb335..aa87abccde 100644 --- a/sentry-servlet/src/main/java/io/sentry/servlet/SentryRequestHttpServletRequestProcessor.java +++ b/sentry-servlet/src/main/java/io/sentry/servlet/SentryRequestHttpServletRequestProcessor.java @@ -2,7 +2,7 @@ import io.sentry.EventProcessor; import io.sentry.SentryEvent; -import io.sentry.hints.Hints; +import io.sentry.hints.Hint; import io.sentry.protocol.Request; import io.sentry.util.Objects; import java.util.Arrays; @@ -30,7 +30,7 @@ public SentryRequestHttpServletRequestProcessor(@NotNull HttpServletRequest http // httpRequest.getRequestURL() returns StringBuffer which is considered an obsolete class. @SuppressWarnings("JdkObsolete") @Override - public @NotNull SentryEvent process(@NotNull SentryEvent event, @NotNull Hints hints) { + public @NotNull SentryEvent process(@NotNull SentryEvent event, @NotNull Hint hint) { final Request sentryRequest = new Request(); sentryRequest.setMethod(httpRequest.getMethod()); sentryRequest.setQueryString(httpRequest.getQueryString()); diff --git a/sentry-servlet/src/main/java/io/sentry/servlet/SentryServletRequestListener.java b/sentry-servlet/src/main/java/io/sentry/servlet/SentryServletRequestListener.java index 544ec8e68f..cf82fd853f 100644 --- a/sentry-servlet/src/main/java/io/sentry/servlet/SentryServletRequestListener.java +++ b/sentry-servlet/src/main/java/io/sentry/servlet/SentryServletRequestListener.java @@ -6,7 +6,7 @@ import io.sentry.Breadcrumb; import io.sentry.HubAdapter; import io.sentry.IHub; -import io.sentry.hints.Hints; +import io.sentry.hints.Hint; import io.sentry.util.Objects; import javax.servlet.ServletRequest; import javax.servlet.ServletRequestEvent; @@ -44,11 +44,11 @@ public void requestInitialized(@NotNull ServletRequestEvent servletRequestEvent) if (servletRequest instanceof HttpServletRequest) { final HttpServletRequest httpRequest = (HttpServletRequest) servletRequest; - final Hints hints = new Hints(); - hints.set(SERVLET_REQUEST, httpRequest); + final Hint hint = new Hint(); + hint.set(SERVLET_REQUEST, httpRequest); hub.addBreadcrumb( - Breadcrumb.http(httpRequest.getRequestURI(), httpRequest.getMethod()), hints); + Breadcrumb.http(httpRequest.getRequestURI(), httpRequest.getMethod()), hint); hub.configureScope( scope -> { diff --git a/sentry-servlet/src/test/kotlin/io/sentry/servlet/SentryRequestHttpServletRequestProcessorTest.kt b/sentry-servlet/src/test/kotlin/io/sentry/servlet/SentryRequestHttpServletRequestProcessorTest.kt index 7ec61b7ca2..8d8174c202 100644 --- a/sentry-servlet/src/test/kotlin/io/sentry/servlet/SentryRequestHttpServletRequestProcessorTest.kt +++ b/sentry-servlet/src/test/kotlin/io/sentry/servlet/SentryRequestHttpServletRequestProcessorTest.kt @@ -2,7 +2,7 @@ package io.sentry.servlet import io.sentry.SentryEvent import io.sentry.SentryOptions -import io.sentry.hints.Hints +import io.sentry.hints.Hint import org.springframework.mock.web.MockServletContext import org.springframework.test.web.servlet.request.MockMvcRequestBuilders import java.net.URI @@ -25,7 +25,7 @@ class SentryRequestHttpServletRequestProcessorTest { val eventProcessor = SentryRequestHttpServletRequestProcessor(request) val event = SentryEvent() - eventProcessor.process(event, Hints()) + eventProcessor.process(event, Hint()) assertNotNull(event.request) val eventRequest = event.request!! @@ -51,7 +51,7 @@ class SentryRequestHttpServletRequestProcessorTest { val eventProcessor = SentryRequestHttpServletRequestProcessor(request) val event = SentryEvent() - eventProcessor.process(event, Hints()) + eventProcessor.process(event, Hint()) assertNotNull(event.request) { assertEquals( @@ -74,7 +74,7 @@ class SentryRequestHttpServletRequestProcessorTest { val eventProcessor = SentryRequestHttpServletRequestProcessor(request) val event = SentryEvent() - eventProcessor.process(event, Hints()) + eventProcessor.process(event, Hint()) assertNotNull(event.request) { assertNull(it.cookies) @@ -96,7 +96,7 @@ class SentryRequestHttpServletRequestProcessorTest { val eventProcessor = SentryRequestHttpServletRequestProcessor(request) val event = SentryEvent() - eventProcessor.process(event, Hints()) + eventProcessor.process(event, Hint()) assertNotNull(event.request) { req -> assertNotNull(req.headers) { diff --git a/sentry-spring-boot-starter/src/test/kotlin/io/sentry/spring/boot/SentryAutoConfigurationTest.kt b/sentry-spring-boot-starter/src/test/kotlin/io/sentry/spring/boot/SentryAutoConfigurationTest.kt index 94c317cef4..898c362f5f 100644 --- a/sentry-spring-boot-starter/src/test/kotlin/io/sentry/spring/boot/SentryAutoConfigurationTest.kt +++ b/sentry-spring-boot-starter/src/test/kotlin/io/sentry/spring/boot/SentryAutoConfigurationTest.kt @@ -19,7 +19,7 @@ import io.sentry.SentryEvent import io.sentry.SentryLevel import io.sentry.SentryOptions import io.sentry.checkEvent -import io.sentry.hints.Hints +import io.sentry.hints.Hint import io.sentry.protocol.User import io.sentry.spring.HttpServletRequestSentryUserProvider import io.sentry.spring.SentryExceptionResolver @@ -662,7 +662,7 @@ class SentryAutoConfigurationTest { } class CustomBeforeSendCallback : SentryOptions.BeforeSendCallback { - override fun execute(event: SentryEvent, hints: Hints): SentryEvent? = null + override fun execute(event: SentryEvent, hint: Hint): SentryEvent? = null } @Configuration(proxyBeanMethods = false) @@ -673,7 +673,7 @@ class SentryAutoConfigurationTest { } class CustomBeforeBreadcrumbCallback : SentryOptions.BeforeBreadcrumbCallback { - override fun execute(breadcrumb: Breadcrumb, hints: Hints): Breadcrumb? = null + override fun execute(breadcrumb: Breadcrumb, hint: Hint): Breadcrumb? = null } @Configuration(proxyBeanMethods = false) @@ -684,7 +684,7 @@ class SentryAutoConfigurationTest { } class CustomEventProcessor : EventProcessor { - override fun process(event: SentryEvent, hints: Hints) = null + override fun process(event: SentryEvent, hint: Hint) = null } @Configuration(proxyBeanMethods = false) diff --git a/sentry-spring/api/sentry-spring.api b/sentry-spring/api/sentry-spring.api index b461ee70f3..1a185dee21 100644 --- a/sentry-spring/api/sentry-spring.api +++ b/sentry-spring/api/sentry-spring.api @@ -36,7 +36,7 @@ public class io/sentry/spring/SentryInitBeanPostProcessor : org/springframework/ public class io/sentry/spring/SentryRequestHttpServletRequestProcessor : io/sentry/EventProcessor { public fun (Lio/sentry/spring/tracing/TransactionNameProvider;Ljavax/servlet/http/HttpServletRequest;)V - public fun process (Lio/sentry/SentryEvent;Lio/sentry/hints/Hints;)Lio/sentry/SentryEvent; + public fun process (Lio/sentry/SentryEvent;Lio/sentry/hints/Hint;)Lio/sentry/SentryEvent; } public class io/sentry/spring/SentryRequestResolver { diff --git a/sentry-spring/src/main/java/io/sentry/spring/SentryExceptionResolver.java b/sentry-spring/src/main/java/io/sentry/spring/SentryExceptionResolver.java index 5db04fa335..d1ac9d0521 100644 --- a/sentry-spring/src/main/java/io/sentry/spring/SentryExceptionResolver.java +++ b/sentry-spring/src/main/java/io/sentry/spring/SentryExceptionResolver.java @@ -8,7 +8,7 @@ import io.sentry.SentryEvent; import io.sentry.SentryLevel; import io.sentry.exception.ExceptionMechanismException; -import io.sentry.hints.Hints; +import io.sentry.hints.Hint; import io.sentry.protocol.Mechanism; import io.sentry.spring.tracing.TransactionNameProvider; import io.sentry.util.Objects; @@ -59,11 +59,11 @@ public SentryExceptionResolver( event.setLevel(SentryLevel.FATAL); event.setTransaction(transactionNameProvider.provideTransactionName(request)); - final Hints hints = new Hints(); - hints.set(SPRING_RESOLVER_REQUEST, request); - hints.set(SPRING_RESOLVER_RESPONSE, response); + final Hint hint = new Hint(); + hint.set(SPRING_RESOLVER_REQUEST, request); + hint.set(SPRING_RESOLVER_RESPONSE, response); - hub.captureEvent(event, hints); + hub.captureEvent(event, hint); // null = run other HandlerExceptionResolvers to actually handle the exception return null; diff --git a/sentry-spring/src/main/java/io/sentry/spring/SentryRequestHttpServletRequestProcessor.java b/sentry-spring/src/main/java/io/sentry/spring/SentryRequestHttpServletRequestProcessor.java index 5c2b58fd70..34f7e5a0eb 100644 --- a/sentry-spring/src/main/java/io/sentry/spring/SentryRequestHttpServletRequestProcessor.java +++ b/sentry-spring/src/main/java/io/sentry/spring/SentryRequestHttpServletRequestProcessor.java @@ -3,7 +3,7 @@ import com.jakewharton.nopen.annotation.Open; import io.sentry.EventProcessor; import io.sentry.SentryEvent; -import io.sentry.hints.Hints; +import io.sentry.hints.Hint; import io.sentry.spring.tracing.TransactionNameProvider; import io.sentry.util.Objects; import javax.servlet.http.HttpServletRequest; @@ -24,8 +24,7 @@ public SentryRequestHttpServletRequestProcessor( } @Override - public @NotNull SentryEvent process( - final @NotNull SentryEvent event, final @NotNull Hints hints) { + public @NotNull SentryEvent process(final @NotNull SentryEvent event, final @NotNull Hint hint) { if (event.getTransaction() == null) { event.setTransaction(transactionNameProvider.provideTransactionName(request)); } diff --git a/sentry-spring/src/main/java/io/sentry/spring/SentrySpringFilter.java b/sentry-spring/src/main/java/io/sentry/spring/SentrySpringFilter.java index a0b45614a6..791936a8f3 100644 --- a/sentry-spring/src/main/java/io/sentry/spring/SentrySpringFilter.java +++ b/sentry-spring/src/main/java/io/sentry/spring/SentrySpringFilter.java @@ -13,7 +13,7 @@ import io.sentry.SentryLevel; import io.sentry.SentryOptions; import io.sentry.SentryOptions.RequestSize; -import io.sentry.hints.Hints; +import io.sentry.hints.Hint; import io.sentry.spring.tracing.SpringMvcTransactionNameProvider; import io.sentry.spring.tracing.TransactionNameProvider; import io.sentry.util.Objects; @@ -62,11 +62,11 @@ protected void doFilterInternal( final HttpServletRequest request = resolveHttpServletRequest(servletRequest); hub.pushScope(); try { - final Hints hints = new Hints(); - hints.set(SPRING_REQUEST_FILTER_REQUEST, servletRequest); - hints.set(SPRING_REQUEST_FILTER_RESPONSE, response); + final Hint hint = new Hint(); + hint.set(SPRING_REQUEST_FILTER_REQUEST, servletRequest); + hint.set(SPRING_REQUEST_FILTER_RESPONSE, response); - hub.addBreadcrumb(Breadcrumb.http(request.getRequestURI(), request.getMethod()), hints); + hub.addBreadcrumb(Breadcrumb.http(request.getRequestURI(), request.getMethod()), hint); configureScope(request); filterChain.doFilter(request, response); } finally { @@ -148,7 +148,7 @@ public RequestBodyExtractingEventProcessor( } @Override - public @NotNull SentryEvent process(@NotNull SentryEvent event, @NotNull Hints hints) { + public @NotNull SentryEvent process(@NotNull SentryEvent event, @NotNull Hint hint) { if (event.getRequest() != null) { event.getRequest().setData(requestPayloadExtractor.extract(request, options)); } diff --git a/sentry-spring/src/main/java/io/sentry/spring/tracing/SentrySpanClientHttpRequestInterceptor.java b/sentry-spring/src/main/java/io/sentry/spring/tracing/SentrySpanClientHttpRequestInterceptor.java index 1c1319f750..d12da58998 100644 --- a/sentry-spring/src/main/java/io/sentry/spring/tracing/SentrySpanClientHttpRequestInterceptor.java +++ b/sentry-spring/src/main/java/io/sentry/spring/tracing/SentrySpanClientHttpRequestInterceptor.java @@ -11,7 +11,7 @@ import io.sentry.SentryTraceHeader; import io.sentry.SpanStatus; import io.sentry.TracingOrigins; -import io.sentry.hints.Hints; +import io.sentry.hints.Hint; import io.sentry.util.Objects; import java.io.IOException; import org.jetbrains.annotations.NotNull; @@ -80,13 +80,13 @@ private void addBreadcrumb( Breadcrumb.http(request.getURI().toString(), request.getMethodValue(), responseStatusCode); breadcrumb.setData("request_body_size", body.length); - final Hints hints = new Hints(); - hints.set(SPRING_REQUEST_INTERCEPTOR_REQUEST, request); - hints.set(SPRING_REQUEST_INTERCEPTOR_REQUEST_BODY, body); + final Hint hint = new Hint(); + hint.set(SPRING_REQUEST_INTERCEPTOR_REQUEST, request); + hint.set(SPRING_REQUEST_INTERCEPTOR_REQUEST_BODY, body); if (response != null) { - hints.set(SPRING_REQUEST_INTERCEPTOR_RESPONSE, response); + hint.set(SPRING_REQUEST_INTERCEPTOR_RESPONSE, response); } - hub.addBreadcrumb(breadcrumb, hints); + hub.addBreadcrumb(breadcrumb, hint); } } diff --git a/sentry-spring/src/main/java/io/sentry/spring/tracing/SentrySpanClientWebRequestFilter.java b/sentry-spring/src/main/java/io/sentry/spring/tracing/SentrySpanClientWebRequestFilter.java index de5f2535bb..8c8525ad1b 100644 --- a/sentry-spring/src/main/java/io/sentry/spring/tracing/SentrySpanClientWebRequestFilter.java +++ b/sentry-spring/src/main/java/io/sentry/spring/tracing/SentrySpanClientWebRequestFilter.java @@ -10,7 +10,7 @@ import io.sentry.SentryTraceHeader; import io.sentry.SpanStatus; import io.sentry.TracingOrigins; -import io.sentry.hints.Hints; +import io.sentry.hints.Hint; import io.sentry.util.Objects; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -76,12 +76,12 @@ private void addBreadcrumb( request.method().name(), response != null ? response.rawStatusCode() : null); - final Hints hints = new Hints(); - hints.set(SPRING_EXCHANGE_FILTER_REQUEST, request); + final Hint hint = new Hint(); + hint.set(SPRING_EXCHANGE_FILTER_REQUEST, request); if (response != null) { - hints.set(SPRING_EXCHANGE_FILTER_RESPONSE, response); + hint.set(SPRING_EXCHANGE_FILTER_RESPONSE, response); } - hub.addBreadcrumb(breadcrumb, hints); + hub.addBreadcrumb(breadcrumb, hint); } } diff --git a/sentry-spring/src/main/java/io/sentry/spring/webflux/SentryWebExceptionHandler.java b/sentry-spring/src/main/java/io/sentry/spring/webflux/SentryWebExceptionHandler.java index 4099bd842e..ba71d8eb56 100644 --- a/sentry-spring/src/main/java/io/sentry/spring/webflux/SentryWebExceptionHandler.java +++ b/sentry-spring/src/main/java/io/sentry/spring/webflux/SentryWebExceptionHandler.java @@ -7,7 +7,7 @@ import io.sentry.SentryEvent; import io.sentry.SentryLevel; import io.sentry.exception.ExceptionMechanismException; -import io.sentry.hints.Hints; +import io.sentry.hints.Hint; import io.sentry.protocol.Mechanism; import io.sentry.util.Objects; import org.jetbrains.annotations.ApiStatus; @@ -43,11 +43,11 @@ public SentryWebExceptionHandler(final @NotNull IHub hub) { event.setLevel(SentryLevel.FATAL); event.setTransaction(TransactionNameProvider.provideTransactionName(serverWebExchange)); - final Hints hints = new Hints(); - hints.set(WEBFLUX_EXCEPTION_HANDLER_REQUEST, serverWebExchange.getRequest()); - hints.set(WEBFLUX_EXCEPTION_HANDLER_RESPONSE, serverWebExchange.getResponse()); + final Hint hint = new Hint(); + hint.set(WEBFLUX_EXCEPTION_HANDLER_REQUEST, serverWebExchange.getRequest()); + hint.set(WEBFLUX_EXCEPTION_HANDLER_RESPONSE, serverWebExchange.getResponse()); - hub.captureEvent(event, hints); + hub.captureEvent(event, hint); } return Mono.error(ex); } diff --git a/sentry-spring/src/main/java/io/sentry/spring/webflux/SentryWebFilter.java b/sentry-spring/src/main/java/io/sentry/spring/webflux/SentryWebFilter.java index e349ac4e9c..6613252c4b 100644 --- a/sentry-spring/src/main/java/io/sentry/spring/webflux/SentryWebFilter.java +++ b/sentry-spring/src/main/java/io/sentry/spring/webflux/SentryWebFilter.java @@ -5,7 +5,7 @@ import io.sentry.Breadcrumb; import io.sentry.IHub; -import io.sentry.hints.Hints; +import io.sentry.hints.Hint; import io.sentry.util.Objects; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; @@ -43,12 +43,12 @@ public Mono filter( final ServerHttpRequest request = serverWebExchange.getRequest(); final ServerHttpResponse response = serverWebExchange.getResponse(); - final Hints hints = new Hints(); - hints.set(WEBFLUX_FILTER_REQUEST, request); - hints.set(WEBFLUX_FILTER_RESPONSE, response); + final Hint hint = new Hint(); + hint.set(WEBFLUX_FILTER_REQUEST, request); + hint.set(WEBFLUX_FILTER_RESPONSE, response); hub.addBreadcrumb( - Breadcrumb.http(request.getURI().toString(), request.getMethodValue()), hints); + Breadcrumb.http(request.getURI().toString(), request.getMethodValue()), hint); hub.configureScope( scope -> scope.setRequest(sentryRequestResolver.resolveSentryRequest(request))); }); diff --git a/sentry-spring/src/test/kotlin/io/sentry/spring/SentryRequestHttpServletRequestProcessorTest.kt b/sentry-spring/src/test/kotlin/io/sentry/spring/SentryRequestHttpServletRequestProcessorTest.kt index 95bf6f5538..370fbc1ffc 100644 --- a/sentry-spring/src/test/kotlin/io/sentry/spring/SentryRequestHttpServletRequestProcessorTest.kt +++ b/sentry-spring/src/test/kotlin/io/sentry/spring/SentryRequestHttpServletRequestProcessorTest.kt @@ -5,7 +5,7 @@ import com.nhaarman.mockitokotlin2.whenever import io.sentry.IHub import io.sentry.SentryEvent import io.sentry.SentryOptions -import io.sentry.hints.Hints +import io.sentry.hints.Hint import io.sentry.spring.tracing.SpringMvcTransactionNameProvider import org.springframework.mock.web.MockServletContext import org.springframework.test.web.servlet.request.MockMvcRequestBuilders @@ -38,7 +38,7 @@ class SentryRequestHttpServletRequestProcessorTest { val eventProcessor = fixture.getSut(request) val event = SentryEvent() - eventProcessor.process(event, Hints()) + eventProcessor.process(event, Hint()) assertNotNull(event.transaction) assertEquals("GET /some-path", event.transaction) @@ -54,7 +54,7 @@ class SentryRequestHttpServletRequestProcessorTest { val event = SentryEvent() event.transaction = "some-transaction" - eventProcessor.process(event, Hints()) + eventProcessor.process(event, Hint()) assertNotNull(event.transaction) assertEquals("some-transaction", event.transaction) diff --git a/sentry/api/sentry.api b/sentry/api/sentry.api index b2195ad59b..4a4adea3e0 100644 --- a/sentry/api/sentry.api +++ b/sentry/api/sentry.api @@ -119,7 +119,7 @@ public final class io/sentry/DiagnosticLogger : io/sentry/ILogger { public final class io/sentry/DuplicateEventDetectionEventProcessor : io/sentry/EventProcessor { public fun (Lio/sentry/SentryOptions;)V - public fun process (Lio/sentry/SentryEvent;Lio/sentry/hints/Hints;)Lio/sentry/SentryEvent; + public fun process (Lio/sentry/SentryEvent;Lio/sentry/hints/Hint;)Lio/sentry/SentryEvent; } public final class io/sentry/EnvelopeReader : io/sentry/IEnvelopeReader { @@ -130,12 +130,12 @@ public final class io/sentry/EnvelopeReader : io/sentry/IEnvelopeReader { public final class io/sentry/EnvelopeSender : io/sentry/IEnvelopeSender { public fun (Lio/sentry/IHub;Lio/sentry/ISerializer;Lio/sentry/ILogger;J)V public synthetic fun processDirectory (Ljava/io/File;)V - public fun processEnvelopeFile (Ljava/lang/String;Lio/sentry/hints/Hints;)V + public fun processEnvelopeFile (Ljava/lang/String;Lio/sentry/hints/Hint;)V } public abstract interface class io/sentry/EventProcessor { - public fun process (Lio/sentry/SentryEvent;Lio/sentry/hints/Hints;)Lio/sentry/SentryEvent; - public fun process (Lio/sentry/protocol/SentryTransaction;Lio/sentry/hints/Hints;)Lio/sentry/protocol/SentryTransaction; + public fun process (Lio/sentry/SentryEvent;Lio/sentry/hints/Hint;)Lio/sentry/SentryEvent; + public fun process (Lio/sentry/protocol/SentryTransaction;Lio/sentry/hints/Hint;)Lio/sentry/protocol/SentryTransaction; } public final class io/sentry/ExternalOptions { @@ -185,13 +185,13 @@ public final class io/sentry/ExternalOptions { public final class io/sentry/Hub : io/sentry/IHub { public fun (Lio/sentry/SentryOptions;)V - public fun addBreadcrumb (Lio/sentry/Breadcrumb;Lio/sentry/hints/Hints;)V + public fun addBreadcrumb (Lio/sentry/Breadcrumb;Lio/sentry/hints/Hint;)V public fun bindClient (Lio/sentry/ISentryClient;)V - public fun captureEnvelope (Lio/sentry/SentryEnvelope;Lio/sentry/hints/Hints;)Lio/sentry/protocol/SentryId; - public fun captureEvent (Lio/sentry/SentryEvent;Lio/sentry/hints/Hints;)Lio/sentry/protocol/SentryId; - public fun captureException (Ljava/lang/Throwable;Lio/sentry/hints/Hints;)Lio/sentry/protocol/SentryId; + public fun captureEnvelope (Lio/sentry/SentryEnvelope;Lio/sentry/hints/Hint;)Lio/sentry/protocol/SentryId; + public fun captureEvent (Lio/sentry/SentryEvent;Lio/sentry/hints/Hint;)Lio/sentry/protocol/SentryId; + public fun captureException (Ljava/lang/Throwable;Lio/sentry/hints/Hint;)Lio/sentry/protocol/SentryId; public fun captureMessage (Ljava/lang/String;Lio/sentry/SentryLevel;)Lio/sentry/protocol/SentryId; - public fun captureTransaction (Lio/sentry/protocol/SentryTransaction;Lio/sentry/TraceState;Lio/sentry/hints/Hints;Lio/sentry/ProfilingTraceData;)Lio/sentry/protocol/SentryId; + public fun captureTransaction (Lio/sentry/protocol/SentryTransaction;Lio/sentry/TraceState;Lio/sentry/hints/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; @@ -225,13 +225,13 @@ public final class io/sentry/Hub : io/sentry/IHub { } public final class io/sentry/HubAdapter : io/sentry/IHub { - public fun addBreadcrumb (Lio/sentry/Breadcrumb;Lio/sentry/hints/Hints;)V + public fun addBreadcrumb (Lio/sentry/Breadcrumb;Lio/sentry/hints/Hint;)V public fun bindClient (Lio/sentry/ISentryClient;)V - public fun captureEnvelope (Lio/sentry/SentryEnvelope;Lio/sentry/hints/Hints;)Lio/sentry/protocol/SentryId; - public fun captureEvent (Lio/sentry/SentryEvent;Lio/sentry/hints/Hints;)Lio/sentry/protocol/SentryId; - public fun captureException (Ljava/lang/Throwable;Lio/sentry/hints/Hints;)Lio/sentry/protocol/SentryId; + public fun captureEnvelope (Lio/sentry/SentryEnvelope;Lio/sentry/hints/Hint;)Lio/sentry/protocol/SentryId; + public fun captureEvent (Lio/sentry/SentryEvent;Lio/sentry/hints/Hint;)Lio/sentry/protocol/SentryId; + public fun captureException (Ljava/lang/Throwable;Lio/sentry/hints/Hint;)Lio/sentry/protocol/SentryId; public fun captureMessage (Ljava/lang/String;Lio/sentry/SentryLevel;)Lio/sentry/protocol/SentryId; - public fun captureTransaction (Lio/sentry/protocol/SentryTransaction;Lio/sentry/TraceState;Lio/sentry/hints/Hints;Lio/sentry/ProfilingTraceData;)Lio/sentry/protocol/SentryId; + public fun captureTransaction (Lio/sentry/protocol/SentryTransaction;Lio/sentry/TraceState;Lio/sentry/hints/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; @@ -271,27 +271,27 @@ public abstract interface class io/sentry/IEnvelopeReader { } public abstract interface class io/sentry/IEnvelopeSender { - public abstract fun processEnvelopeFile (Ljava/lang/String;Lio/sentry/hints/Hints;)V + public abstract fun processEnvelopeFile (Ljava/lang/String;Lio/sentry/hints/Hint;)V } public abstract interface class io/sentry/IHub { public fun addBreadcrumb (Lio/sentry/Breadcrumb;)V - public abstract fun addBreadcrumb (Lio/sentry/Breadcrumb;Lio/sentry/hints/Hints;)V + public abstract fun addBreadcrumb (Lio/sentry/Breadcrumb;Lio/sentry/hints/Hint;)V public fun addBreadcrumb (Ljava/lang/String;)V public fun addBreadcrumb (Ljava/lang/String;Ljava/lang/String;)V public abstract fun bindClient (Lio/sentry/ISentryClient;)V public fun captureEnvelope (Lio/sentry/SentryEnvelope;)Lio/sentry/protocol/SentryId; - public abstract fun captureEnvelope (Lio/sentry/SentryEnvelope;Lio/sentry/hints/Hints;)Lio/sentry/protocol/SentryId; + public abstract fun captureEnvelope (Lio/sentry/SentryEnvelope;Lio/sentry/hints/Hint;)Lio/sentry/protocol/SentryId; public fun captureEvent (Lio/sentry/SentryEvent;)Lio/sentry/protocol/SentryId; - public abstract fun captureEvent (Lio/sentry/SentryEvent;Lio/sentry/hints/Hints;)Lio/sentry/protocol/SentryId; + public abstract fun captureEvent (Lio/sentry/SentryEvent;Lio/sentry/hints/Hint;)Lio/sentry/protocol/SentryId; public fun captureException (Ljava/lang/Throwable;)Lio/sentry/protocol/SentryId; - public abstract fun captureException (Ljava/lang/Throwable;Lio/sentry/hints/Hints;)Lio/sentry/protocol/SentryId; + public abstract fun captureException (Ljava/lang/Throwable;Lio/sentry/hints/Hint;)Lio/sentry/protocol/SentryId; public fun captureMessage (Ljava/lang/String;)Lio/sentry/protocol/SentryId; public abstract fun captureMessage (Ljava/lang/String;Lio/sentry/SentryLevel;)Lio/sentry/protocol/SentryId; public fun captureTransaction (Lio/sentry/protocol/SentryTransaction;Lio/sentry/TraceState;)Lio/sentry/protocol/SentryId; - public fun captureTransaction (Lio/sentry/protocol/SentryTransaction;Lio/sentry/TraceState;Lio/sentry/hints/Hints;)Lio/sentry/protocol/SentryId; - public abstract fun captureTransaction (Lio/sentry/protocol/SentryTransaction;Lio/sentry/TraceState;Lio/sentry/hints/Hints;Lio/sentry/ProfilingTraceData;)Lio/sentry/protocol/SentryId; - public fun captureTransaction (Lio/sentry/protocol/SentryTransaction;Lio/sentry/hints/Hints;)Lio/sentry/protocol/SentryId; + public fun captureTransaction (Lio/sentry/protocol/SentryTransaction;Lio/sentry/TraceState;Lio/sentry/hints/Hint;)Lio/sentry/protocol/SentryId; + public abstract fun captureTransaction (Lio/sentry/protocol/SentryTransaction;Lio/sentry/TraceState;Lio/sentry/hints/Hint;Lio/sentry/ProfilingTraceData;)Lio/sentry/protocol/SentryId; + public fun captureTransaction (Lio/sentry/protocol/SentryTransaction;Lio/sentry/hints/Hint;)Lio/sentry/protocol/SentryId; public abstract fun captureUserFeedback (Lio/sentry/UserFeedback;)V public abstract fun clearBreadcrumbs ()V public abstract fun clone ()Lio/sentry/IHub; @@ -349,24 +349,24 @@ public abstract interface class io/sentry/IScopeObserver { public abstract interface class io/sentry/ISentryClient { public fun captureEnvelope (Lio/sentry/SentryEnvelope;)Lio/sentry/protocol/SentryId; - public abstract fun captureEnvelope (Lio/sentry/SentryEnvelope;Lio/sentry/hints/Hints;)Lio/sentry/protocol/SentryId; + public abstract fun captureEnvelope (Lio/sentry/SentryEnvelope;Lio/sentry/hints/Hint;)Lio/sentry/protocol/SentryId; public fun captureEvent (Lio/sentry/SentryEvent;)Lio/sentry/protocol/SentryId; public fun captureEvent (Lio/sentry/SentryEvent;Lio/sentry/Scope;)Lio/sentry/protocol/SentryId; - public abstract fun captureEvent (Lio/sentry/SentryEvent;Lio/sentry/Scope;Lio/sentry/hints/Hints;)Lio/sentry/protocol/SentryId; - public fun captureEvent (Lio/sentry/SentryEvent;Lio/sentry/hints/Hints;)Lio/sentry/protocol/SentryId; + public abstract fun captureEvent (Lio/sentry/SentryEvent;Lio/sentry/Scope;Lio/sentry/hints/Hint;)Lio/sentry/protocol/SentryId; + public fun captureEvent (Lio/sentry/SentryEvent;Lio/sentry/hints/Hint;)Lio/sentry/protocol/SentryId; public fun captureException (Ljava/lang/Throwable;)Lio/sentry/protocol/SentryId; public fun captureException (Ljava/lang/Throwable;Lio/sentry/Scope;)Lio/sentry/protocol/SentryId; - public fun captureException (Ljava/lang/Throwable;Lio/sentry/Scope;Lio/sentry/hints/Hints;)Lio/sentry/protocol/SentryId; - public fun captureException (Ljava/lang/Throwable;Lio/sentry/hints/Hints;)Lio/sentry/protocol/SentryId; + public fun captureException (Ljava/lang/Throwable;Lio/sentry/Scope;Lio/sentry/hints/Hint;)Lio/sentry/protocol/SentryId; + public fun captureException (Ljava/lang/Throwable;Lio/sentry/hints/Hint;)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/Scope;)Lio/sentry/protocol/SentryId; public fun captureSession (Lio/sentry/Session;)V - public abstract fun captureSession (Lio/sentry/Session;Lio/sentry/hints/Hints;)V + public abstract fun captureSession (Lio/sentry/Session;Lio/sentry/hints/Hint;)V public fun captureTransaction (Lio/sentry/protocol/SentryTransaction;)Lio/sentry/protocol/SentryId; - public fun captureTransaction (Lio/sentry/protocol/SentryTransaction;Lio/sentry/Scope;Lio/sentry/hints/Hints;)Lio/sentry/protocol/SentryId; + public fun captureTransaction (Lio/sentry/protocol/SentryTransaction;Lio/sentry/Scope;Lio/sentry/hints/Hint;)Lio/sentry/protocol/SentryId; public fun captureTransaction (Lio/sentry/protocol/SentryTransaction;Lio/sentry/TraceState;)Lio/sentry/protocol/SentryId; - public fun captureTransaction (Lio/sentry/protocol/SentryTransaction;Lio/sentry/TraceState;Lio/sentry/Scope;Lio/sentry/hints/Hints;)Lio/sentry/protocol/SentryId; - public abstract fun captureTransaction (Lio/sentry/protocol/SentryTransaction;Lio/sentry/TraceState;Lio/sentry/Scope;Lio/sentry/hints/Hints;Lio/sentry/ProfilingTraceData;)Lio/sentry/protocol/SentryId; + public fun captureTransaction (Lio/sentry/protocol/SentryTransaction;Lio/sentry/TraceState;Lio/sentry/Scope;Lio/sentry/hints/Hint;)Lio/sentry/protocol/SentryId; + public abstract fun captureTransaction (Lio/sentry/protocol/SentryTransaction;Lio/sentry/TraceState;Lio/sentry/Scope;Lio/sentry/hints/Hint;Lio/sentry/ProfilingTraceData;)Lio/sentry/protocol/SentryId; public abstract fun captureUserFeedback (Lio/sentry/UserFeedback;)V public abstract fun close ()V public abstract fun flush (J)V @@ -504,8 +504,8 @@ public abstract interface class io/sentry/JsonUnknown { public final class io/sentry/MainEventProcessor : io/sentry/EventProcessor, java/io/Closeable { public fun (Lio/sentry/SentryOptions;)V public fun close ()V - public fun process (Lio/sentry/SentryEvent;Lio/sentry/hints/Hints;)Lio/sentry/SentryEvent; - public fun process (Lio/sentry/protocol/SentryTransaction;Lio/sentry/hints/Hints;)Lio/sentry/protocol/SentryTransaction; + public fun process (Lio/sentry/SentryEvent;Lio/sentry/hints/Hint;)Lio/sentry/SentryEvent; + public fun process (Lio/sentry/protocol/SentryTransaction;Lio/sentry/hints/Hint;)Lio/sentry/protocol/SentryTransaction; } public final class io/sentry/NoOpEnvelopeReader : io/sentry/IEnvelopeReader { @@ -514,13 +514,13 @@ public final class io/sentry/NoOpEnvelopeReader : io/sentry/IEnvelopeReader { } public final class io/sentry/NoOpHub : io/sentry/IHub { - public fun addBreadcrumb (Lio/sentry/Breadcrumb;Lio/sentry/hints/Hints;)V + public fun addBreadcrumb (Lio/sentry/Breadcrumb;Lio/sentry/hints/Hint;)V public fun bindClient (Lio/sentry/ISentryClient;)V - public fun captureEnvelope (Lio/sentry/SentryEnvelope;Lio/sentry/hints/Hints;)Lio/sentry/protocol/SentryId; - public fun captureEvent (Lio/sentry/SentryEvent;Lio/sentry/hints/Hints;)Lio/sentry/protocol/SentryId; - public fun captureException (Ljava/lang/Throwable;Lio/sentry/hints/Hints;)Lio/sentry/protocol/SentryId; + public fun captureEnvelope (Lio/sentry/SentryEnvelope;Lio/sentry/hints/Hint;)Lio/sentry/protocol/SentryId; + public fun captureEvent (Lio/sentry/SentryEvent;Lio/sentry/hints/Hint;)Lio/sentry/protocol/SentryId; + public fun captureException (Ljava/lang/Throwable;Lio/sentry/hints/Hint;)Lio/sentry/protocol/SentryId; public fun captureMessage (Ljava/lang/String;Lio/sentry/SentryLevel;)Lio/sentry/protocol/SentryId; - public fun captureTransaction (Lio/sentry/protocol/SentryTransaction;Lio/sentry/TraceState;Lio/sentry/hints/Hints;Lio/sentry/ProfilingTraceData;)Lio/sentry/protocol/SentryId; + public fun captureTransaction (Lio/sentry/protocol/SentryTransaction;Lio/sentry/TraceState;Lio/sentry/hints/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; @@ -640,7 +640,7 @@ public final class io/sentry/OptionsContainer { public final class io/sentry/OutboxSender : io/sentry/IEnvelopeSender { public fun (Lio/sentry/IHub;Lio/sentry/IEnvelopeReader;Lio/sentry/ISerializer;Lio/sentry/ILogger;J)V public synthetic fun processDirectory (Ljava/io/File;)V - public fun processEnvelopeFile (Ljava/lang/String;Lio/sentry/hints/Hints;)V + public fun processEnvelopeFile (Ljava/lang/String;Lio/sentry/hints/Hint;)V } public final class io/sentry/ProfilingTraceData : io/sentry/JsonSerializable, io/sentry/JsonUnknown { @@ -740,7 +740,7 @@ public final class io/sentry/Scope { public fun (Lio/sentry/SentryOptions;)V public fun addAttachment (Lio/sentry/Attachment;)V public fun addBreadcrumb (Lio/sentry/Breadcrumb;)V - public fun addBreadcrumb (Lio/sentry/Breadcrumb;Lio/sentry/hints/Hints;)V + public fun addBreadcrumb (Lio/sentry/Breadcrumb;Lio/sentry/hints/Hint;)V public fun addEventProcessor (Lio/sentry/EventProcessor;)V public fun clear ()V public fun clearAttachments ()V @@ -814,14 +814,14 @@ public final class io/sentry/SendFireAndForgetOutboxSender : io/sentry/SendCache public final class io/sentry/Sentry { public static fun addBreadcrumb (Lio/sentry/Breadcrumb;)V - public static fun addBreadcrumb (Lio/sentry/Breadcrumb;Lio/sentry/hints/Hints;)V + public static fun addBreadcrumb (Lio/sentry/Breadcrumb;Lio/sentry/hints/Hint;)V public static fun addBreadcrumb (Ljava/lang/String;)V public static fun addBreadcrumb (Ljava/lang/String;Ljava/lang/String;)V public static fun bindClient (Lio/sentry/ISentryClient;)V public static fun captureEvent (Lio/sentry/SentryEvent;)Lio/sentry/protocol/SentryId; - public static fun captureEvent (Lio/sentry/SentryEvent;Lio/sentry/hints/Hints;)Lio/sentry/protocol/SentryId; + public static fun captureEvent (Lio/sentry/SentryEvent;Lio/sentry/hints/Hint;)Lio/sentry/protocol/SentryId; public static fun captureException (Ljava/lang/Throwable;)Lio/sentry/protocol/SentryId; - public static fun captureException (Ljava/lang/Throwable;Lio/sentry/hints/Hints;)Lio/sentry/protocol/SentryId; + public static fun captureException (Ljava/lang/Throwable;Lio/sentry/hints/Hint;)Lio/sentry/protocol/SentryId; public static fun captureMessage (Ljava/lang/String;)Lio/sentry/protocol/SentryId; public static fun captureMessage (Ljava/lang/String;Lio/sentry/SentryLevel;)Lio/sentry/protocol/SentryId; public static fun captureUserFeedback (Lio/sentry/UserFeedback;)V @@ -943,10 +943,10 @@ public final class io/sentry/SentryBaseEvent$Serializer { } public final class io/sentry/SentryClient : io/sentry/ISentryClient { - public fun captureEnvelope (Lio/sentry/SentryEnvelope;Lio/sentry/hints/Hints;)Lio/sentry/protocol/SentryId; - public fun captureEvent (Lio/sentry/SentryEvent;Lio/sentry/Scope;Lio/sentry/hints/Hints;)Lio/sentry/protocol/SentryId; - public fun captureSession (Lio/sentry/Session;Lio/sentry/hints/Hints;)V - public fun captureTransaction (Lio/sentry/protocol/SentryTransaction;Lio/sentry/TraceState;Lio/sentry/Scope;Lio/sentry/hints/Hints;Lio/sentry/ProfilingTraceData;)Lio/sentry/protocol/SentryId; + public fun captureEnvelope (Lio/sentry/SentryEnvelope;Lio/sentry/hints/Hint;)Lio/sentry/protocol/SentryId; + public fun captureEvent (Lio/sentry/SentryEvent;Lio/sentry/Scope;Lio/sentry/hints/Hint;)Lio/sentry/protocol/SentryId; + public fun captureSession (Lio/sentry/Session;Lio/sentry/hints/Hint;)V + public fun captureTransaction (Lio/sentry/protocol/SentryTransaction;Lio/sentry/TraceState;Lio/sentry/Scope;Lio/sentry/hints/Hint;Lio/sentry/ProfilingTraceData;)Lio/sentry/protocol/SentryId; public fun captureUserFeedback (Lio/sentry/UserFeedback;)V public fun close ()V public fun flush (J)V @@ -1257,11 +1257,11 @@ public class io/sentry/SentryOptions { } public abstract interface class io/sentry/SentryOptions$BeforeBreadcrumbCallback { - public abstract fun execute (Lio/sentry/Breadcrumb;Lio/sentry/hints/Hints;)Lio/sentry/Breadcrumb; + public abstract fun execute (Lio/sentry/Breadcrumb;Lio/sentry/hints/Hint;)Lio/sentry/Breadcrumb; } public abstract interface class io/sentry/SentryOptions$BeforeSendCallback { - public abstract fun execute (Lio/sentry/SentryEvent;Lio/sentry/hints/Hints;)Lio/sentry/SentryEvent; + public abstract fun execute (Lio/sentry/SentryEvent;Lio/sentry/hints/Hint;)Lio/sentry/SentryEvent; } public final class io/sentry/SentryOptions$Proxy { @@ -1703,13 +1703,13 @@ public final class io/sentry/cache/EnvelopeCache : io/sentry/cache/IEnvelopeCach public static fun create (Lio/sentry/SentryOptions;)Lio/sentry/cache/IEnvelopeCache; public fun discard (Lio/sentry/SentryEnvelope;)V public fun iterator ()Ljava/util/Iterator; - public fun store (Lio/sentry/SentryEnvelope;Lio/sentry/hints/Hints;)V + public fun store (Lio/sentry/SentryEnvelope;Lio/sentry/hints/Hint;)V } public abstract interface class io/sentry/cache/IEnvelopeCache : java/lang/Iterable { public abstract fun discard (Lio/sentry/SentryEnvelope;)V public fun store (Lio/sentry/SentryEnvelope;)V - public abstract fun store (Lio/sentry/SentryEnvelope;Lio/sentry/hints/Hints;)V + public abstract fun store (Lio/sentry/SentryEnvelope;Lio/sentry/hints/Hint;)V } public final class io/sentry/clientreport/ClientReport : io/sentry/JsonSerializable, io/sentry/JsonUnknown { @@ -1845,7 +1845,7 @@ public abstract interface class io/sentry/hints/Flushable { public abstract fun waitFlush ()Z } -public final class io/sentry/hints/Hints { +public final class io/sentry/hints/Hint { public fun ()V public fun addAttachment (Lio/sentry/Attachment;)V public fun addAttachments (Ljava/util/List;)V @@ -1858,8 +1858,8 @@ public final class io/sentry/hints/Hints { public fun replaceAttachments (Ljava/util/List;)V public fun set (Ljava/lang/String;Ljava/lang/Object;)V public fun setScreenshot (Lio/sentry/Attachment;)V - public static fun withAttachment (Lio/sentry/Attachment;)Lio/sentry/hints/Hints; - public static fun withAttachments (Ljava/util/List;)Lio/sentry/hints/Hints; + public static fun withAttachment (Lio/sentry/Attachment;)Lio/sentry/hints/Hint; + public static fun withAttachments (Ljava/util/List;)Lio/sentry/hints/Hint; } public abstract interface class io/sentry/hints/Resettable { @@ -2841,7 +2841,7 @@ public final class io/sentry/transport/AsyncHttpTransport : io/sentry/transport/ public fun (Lio/sentry/transport/QueuedThreadPoolExecutor;Lio/sentry/SentryOptions;Lio/sentry/transport/RateLimiter;Lio/sentry/transport/ITransportGate;Lio/sentry/transport/HttpConnection;)V public fun close ()V public fun flush (J)V - public fun send (Lio/sentry/SentryEnvelope;Lio/sentry/hints/Hints;)V + public fun send (Lio/sentry/SentryEnvelope;Lio/sentry/hints/Hint;)V } public final class io/sentry/transport/CurrentDateProvider : io/sentry/transport/ICurrentDateProvider { @@ -2856,7 +2856,7 @@ public abstract interface class io/sentry/transport/ICurrentDateProvider { public abstract interface class io/sentry/transport/ITransport : java/io/Closeable { public abstract fun flush (J)V public fun send (Lio/sentry/SentryEnvelope;)V - public abstract fun send (Lio/sentry/SentryEnvelope;Lio/sentry/hints/Hints;)V + public abstract fun send (Lio/sentry/SentryEnvelope;Lio/sentry/hints/Hint;)V } public abstract interface class io/sentry/transport/ITransportGate { @@ -2868,14 +2868,14 @@ public final class io/sentry/transport/NoOpEnvelopeCache : io/sentry/cache/IEnve public fun discard (Lio/sentry/SentryEnvelope;)V public static fun getInstance ()Lio/sentry/transport/NoOpEnvelopeCache; public fun iterator ()Ljava/util/Iterator; - public fun store (Lio/sentry/SentryEnvelope;Lio/sentry/hints/Hints;)V + public fun store (Lio/sentry/SentryEnvelope;Lio/sentry/hints/Hint;)V } public final class io/sentry/transport/NoOpTransport : io/sentry/transport/ITransport { public fun close ()V public fun flush (J)V public static fun getInstance ()Lio/sentry/transport/NoOpTransport; - public fun send (Lio/sentry/SentryEnvelope;Lio/sentry/hints/Hints;)V + public fun send (Lio/sentry/SentryEnvelope;Lio/sentry/hints/Hint;)V } public final class io/sentry/transport/NoOpTransportGate : io/sentry/transport/ITransportGate { @@ -2886,7 +2886,7 @@ public final class io/sentry/transport/NoOpTransportGate : io/sentry/transport/I public final class io/sentry/transport/RateLimiter { public fun (Lio/sentry/SentryOptions;)V public fun (Lio/sentry/transport/ICurrentDateProvider;Lio/sentry/SentryOptions;)V - public fun filter (Lio/sentry/SentryEnvelope;Lio/sentry/hints/Hints;)Lio/sentry/SentryEnvelope; + public fun filter (Lio/sentry/SentryEnvelope;Lio/sentry/hints/Hint;)Lio/sentry/SentryEnvelope; public fun updateRetryAfterLimits (Ljava/lang/String;Ljava/lang/String;I)V } @@ -2904,7 +2904,7 @@ public final class io/sentry/transport/StdoutTransport : io/sentry/transport/ITr public fun (Lio/sentry/ISerializer;)V public fun close ()V public fun flush (J)V - public fun send (Lio/sentry/SentryEnvelope;Lio/sentry/hints/Hints;)V + public fun send (Lio/sentry/SentryEnvelope;Lio/sentry/hints/Hint;)V } public abstract class io/sentry/transport/TransportResult { @@ -2939,15 +2939,15 @@ public final class io/sentry/util/FileUtils { } public final class io/sentry/util/HintUtils { - public static fun createWithTypeCheckHint (Ljava/lang/Object;)Lio/sentry/hints/Hints; - public static fun getSentrySdkHint (Lio/sentry/hints/Hints;)Ljava/lang/Object; - public static fun hasType (Lio/sentry/hints/Hints;Ljava/lang/Class;)Z - public static fun runIfDoesNotHaveType (Lio/sentry/hints/Hints;Ljava/lang/Class;Lio/sentry/util/HintUtils$SentryNullableConsumer;)V - public static fun runIfHasType (Lio/sentry/hints/Hints;Ljava/lang/Class;Lio/sentry/util/HintUtils$SentryConsumer;)V - public static fun runIfHasType (Lio/sentry/hints/Hints;Ljava/lang/Class;Lio/sentry/util/HintUtils$SentryConsumer;Lio/sentry/util/HintUtils$SentryFallbackConsumer;)V - public static fun runIfHasTypeLogIfNot (Lio/sentry/hints/Hints;Ljava/lang/Class;Lio/sentry/ILogger;Lio/sentry/util/HintUtils$SentryConsumer;)V - public static fun setTypeCheckHint (Lio/sentry/hints/Hints;Ljava/lang/Object;)V - public static fun shouldApplyScopeData (Lio/sentry/hints/Hints;)Z + public static fun createWithTypeCheckHint (Ljava/lang/Object;)Lio/sentry/hints/Hint; + public static fun getSentrySdkHint (Lio/sentry/hints/Hint;)Ljava/lang/Object; + public static fun hasType (Lio/sentry/hints/Hint;Ljava/lang/Class;)Z + public static fun runIfDoesNotHaveType (Lio/sentry/hints/Hint;Ljava/lang/Class;Lio/sentry/util/HintUtils$SentryNullableConsumer;)V + public static fun runIfHasType (Lio/sentry/hints/Hint;Ljava/lang/Class;Lio/sentry/util/HintUtils$SentryConsumer;)V + public static fun runIfHasType (Lio/sentry/hints/Hint;Ljava/lang/Class;Lio/sentry/util/HintUtils$SentryConsumer;Lio/sentry/util/HintUtils$SentryFallbackConsumer;)V + public static fun runIfHasTypeLogIfNot (Lio/sentry/hints/Hint;Ljava/lang/Class;Lio/sentry/ILogger;Lio/sentry/util/HintUtils$SentryConsumer;)V + public static fun setTypeCheckHint (Lio/sentry/hints/Hint;Ljava/lang/Object;)V + public static fun shouldApplyScopeData (Lio/sentry/hints/Hint;)Z } public abstract interface class io/sentry/util/HintUtils$SentryConsumer { diff --git a/sentry/src/main/java/io/sentry/DirectoryProcessor.java b/sentry/src/main/java/io/sentry/DirectoryProcessor.java index 31bf14f5b9..3777a966f0 100644 --- a/sentry/src/main/java/io/sentry/DirectoryProcessor.java +++ b/sentry/src/main/java/io/sentry/DirectoryProcessor.java @@ -4,7 +4,7 @@ import io.sentry.hints.Cached; import io.sentry.hints.Flushable; -import io.sentry.hints.Hints; +import io.sentry.hints.Hint; import io.sentry.hints.Retryable; import io.sentry.hints.SubmissionResult; import io.sentry.util.HintUtils; @@ -63,18 +63,19 @@ public void processDirectory(final @NotNull File directory) { logger.log(SentryLevel.DEBUG, "Processing file: %s", file.getAbsolutePath()); - final SendCachedEnvelopeHint hint = new SendCachedEnvelopeHint(flushTimeoutMillis, logger); + final SendCachedEnvelopeHint cachedHint = + new SendCachedEnvelopeHint(flushTimeoutMillis, logger); - final Hints hints = HintUtils.createWithTypeCheckHint(hint); + final Hint hint = HintUtils.createWithTypeCheckHint(cachedHint); - processFile(file, hints); + processFile(file, hint); } } catch (Throwable e) { logger.log(SentryLevel.ERROR, e, "Failed processing '%s'", directory.getAbsolutePath()); } } - protected abstract void processFile(final @NotNull File file, final @NotNull Hints hints); + protected abstract void processFile(final @NotNull File file, final @NotNull Hint hint); protected abstract boolean isRelevantFileName(String fileName); diff --git a/sentry/src/main/java/io/sentry/DuplicateEventDetectionEventProcessor.java b/sentry/src/main/java/io/sentry/DuplicateEventDetectionEventProcessor.java index 2b049fa26d..896b5d8dd3 100644 --- a/sentry/src/main/java/io/sentry/DuplicateEventDetectionEventProcessor.java +++ b/sentry/src/main/java/io/sentry/DuplicateEventDetectionEventProcessor.java @@ -1,6 +1,6 @@ package io.sentry; -import io.sentry.hints.Hints; +import io.sentry.hints.Hint; import io.sentry.util.Objects; import java.util.ArrayList; import java.util.Collections; @@ -21,8 +21,7 @@ public DuplicateEventDetectionEventProcessor(final @NotNull SentryOptions option } @Override - public @Nullable SentryEvent process( - final @NotNull SentryEvent event, final @NotNull Hints hints) { + public @Nullable SentryEvent process(final @NotNull SentryEvent event, final @NotNull Hint hint) { if (options.isEnableDeduplication()) { final Throwable throwable = event.getThrowable(); if (throwable != null) { diff --git a/sentry/src/main/java/io/sentry/EnvelopeSender.java b/sentry/src/main/java/io/sentry/EnvelopeSender.java index 628f1b273d..4b41b31db6 100644 --- a/sentry/src/main/java/io/sentry/EnvelopeSender.java +++ b/sentry/src/main/java/io/sentry/EnvelopeSender.java @@ -2,7 +2,7 @@ import io.sentry.cache.EnvelopeCache; import io.sentry.hints.Flushable; -import io.sentry.hints.Hints; +import io.sentry.hints.Hint; import io.sentry.hints.Retryable; import io.sentry.util.HintUtils; import io.sentry.util.Objects; @@ -34,7 +34,7 @@ public EnvelopeSender( } @Override - protected void processFile(final @NotNull File file, final @NotNull Hints hints) { + protected void processFile(final @NotNull File file, final @NotNull Hint hint) { if (!file.isFile()) { logger.log(SentryLevel.DEBUG, "'%s' is not a file.", file.getAbsolutePath()); return; @@ -60,11 +60,11 @@ protected void processFile(final @NotNull File file, final @NotNull Hints hints) logger.log( SentryLevel.ERROR, "Failed to deserialize cached envelope %s", file.getAbsolutePath()); } else { - hub.captureEnvelope(envelope, hints); + hub.captureEnvelope(envelope, hint); } HintUtils.runIfHasTypeLogIfNot( - hints, + hint, Flushable.class, logger, (flushable) -> { @@ -80,7 +80,7 @@ protected void processFile(final @NotNull File file, final @NotNull Hints hints) logger.log( SentryLevel.ERROR, e, "Failed to capture cached envelope %s", file.getAbsolutePath()); HintUtils.runIfHasTypeLogIfNot( - hints, + hint, Retryable.class, logger, (retryable) -> { @@ -90,7 +90,7 @@ protected void processFile(final @NotNull File file, final @NotNull Hints hints) } finally { // Unless the transport marked this to be retried, it'll be deleted. HintUtils.runIfHasTypeLogIfNot( - hints, + hint, Retryable.class, logger, (retryable) -> { @@ -113,10 +113,10 @@ protected boolean isRelevantFileName(final @NotNull String fileName) { } @Override - public void processEnvelopeFile(final @NotNull String path, final @NotNull Hints hints) { + public void processEnvelopeFile(final @NotNull String path, final @NotNull Hint hint) { Objects.requireNonNull(path, "Path is required."); - processFile(new File(path), hints); + processFile(new File(path), hint); } private void safeDelete(final @NotNull File file, final @NotNull String errorMessageSuffix) { diff --git a/sentry/src/main/java/io/sentry/EventProcessor.java b/sentry/src/main/java/io/sentry/EventProcessor.java index cb18300c90..1030af9e98 100644 --- a/sentry/src/main/java/io/sentry/EventProcessor.java +++ b/sentry/src/main/java/io/sentry/EventProcessor.java @@ -1,6 +1,6 @@ package io.sentry; -import io.sentry.hints.Hints; +import io.sentry.hints.Hint; import io.sentry.protocol.SentryTransaction; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -14,11 +14,11 @@ public interface EventProcessor { * May mutate or drop a SentryEvent * * @param event the SentryEvent - * @param hints the Hint + * @param hint the Hint * @return the event itself, a mutated SentryEvent or null */ @Nullable - default SentryEvent process(@NotNull SentryEvent event, @NotNull Hints hints) { + default SentryEvent process(@NotNull SentryEvent event, @NotNull Hint hint) { return event; } @@ -26,11 +26,11 @@ default SentryEvent process(@NotNull SentryEvent event, @NotNull Hints hints) { * May mutate or drop a SentryTransaction * * @param transaction the SentryTransaction - * @param hints the Hint + * @param hint the Hint * @return the event itself, a mutated SentryTransaction or null */ @Nullable - default SentryTransaction process(@NotNull SentryTransaction transaction, @NotNull Hints hints) { + default SentryTransaction process(@NotNull SentryTransaction transaction, @NotNull Hint hint) { return transaction; } } diff --git a/sentry/src/main/java/io/sentry/Hub.java b/sentry/src/main/java/io/sentry/Hub.java index b46ef85727..ea53306086 100644 --- a/sentry/src/main/java/io/sentry/Hub.java +++ b/sentry/src/main/java/io/sentry/Hub.java @@ -2,7 +2,7 @@ import io.sentry.Stack.StackItem; import io.sentry.clientreport.DiscardReason; -import io.sentry.hints.Hints; +import io.sentry.hints.Hint; import io.sentry.hints.SessionEndHint; import io.sentry.hints.SessionStartHint; import io.sentry.protocol.SentryId; @@ -76,7 +76,7 @@ public boolean isEnabled() { @Override public @NotNull SentryId captureEvent( - final @NotNull SentryEvent event, final @Nullable Hints hints) { + final @NotNull SentryEvent event, final @Nullable Hint hint) { SentryId sentryId = SentryId.EMPTY_ID; if (!isEnabled()) { options @@ -89,7 +89,7 @@ public boolean isEnabled() { try { assignTraceContext(event); final StackItem item = stack.peek(); - sentryId = item.getClient().captureEvent(event, item.getScope(), hints); + sentryId = item.getClient().captureEvent(event, item.getScope(), hint); this.lastEventId = sentryId; } catch (Throwable e) { options @@ -128,7 +128,7 @@ public boolean isEnabled() { @ApiStatus.Internal @Override public @NotNull SentryId captureEnvelope( - final @NotNull SentryEnvelope envelope, final @Nullable Hints hints) { + final @NotNull SentryEnvelope envelope, final @Nullable Hint hint) { Objects.requireNonNull(envelope, "SentryEnvelope is required."); SentryId sentryId = SentryId.EMPTY_ID; @@ -141,7 +141,7 @@ public boolean isEnabled() { } else { try { final SentryId capturedEnvelopeId = - stack.peek().getClient().captureEnvelope(envelope, hints); + stack.peek().getClient().captureEnvelope(envelope, hint); if (capturedEnvelopeId != null) { sentryId = capturedEnvelopeId; } @@ -154,7 +154,7 @@ public boolean isEnabled() { @Override public @NotNull SentryId captureException( - final @NotNull Throwable throwable, final @Nullable Hints hints) { + final @NotNull Throwable throwable, final @Nullable Hint hint) { SentryId sentryId = SentryId.EMPTY_ID; if (!isEnabled()) { options @@ -169,7 +169,7 @@ public boolean isEnabled() { final StackItem item = stack.peek(); final SentryEvent event = new SentryEvent(throwable); assignTraceContext(event); - sentryId = item.getClient().captureEvent(event, item.getScope(), hints); + sentryId = item.getClient().captureEvent(event, item.getScope(), hint); } catch (Throwable e) { options .getLogger() @@ -236,14 +236,14 @@ public void startSession() { // single envelope // Or create the envelope here with both items and call `captureEnvelope` if (pair.getPrevious() != null) { - final Hints hints = HintUtils.createWithTypeCheckHint(new SessionEndHint()); + final Hint hint = HintUtils.createWithTypeCheckHint(new SessionEndHint()); - item.getClient().captureSession(pair.getPrevious(), hints); + item.getClient().captureSession(pair.getPrevious(), hint); } - final Hints hints = HintUtils.createWithTypeCheckHint(new SessionStartHint()); + final Hint hint = HintUtils.createWithTypeCheckHint(new SessionStartHint()); - item.getClient().captureSession(pair.getCurrent(), hints); + item.getClient().captureSession(pair.getCurrent(), hint); } else { options.getLogger().log(SentryLevel.WARNING, "Session could not be started."); } @@ -260,9 +260,9 @@ public void endSession() { final StackItem item = this.stack.peek(); final Session previousSession = item.getScope().endSession(); if (previousSession != null) { - final Hints hints = HintUtils.createWithTypeCheckHint(new SessionEndHint()); + final Hint hint = HintUtils.createWithTypeCheckHint(new SessionEndHint()); - item.getClient().captureSession(previousSession, hints); + item.getClient().captureSession(previousSession, hint); } } } @@ -294,7 +294,7 @@ public void close() { } @Override - public void addBreadcrumb(final @NotNull Breadcrumb breadcrumb, final @Nullable Hints hints) { + public void addBreadcrumb(final @NotNull Breadcrumb breadcrumb, final @Nullable Hint hint) { if (!isEnabled()) { options .getLogger() @@ -304,7 +304,7 @@ public void addBreadcrumb(final @NotNull Breadcrumb breadcrumb, final @Nullable } else if (breadcrumb == null) { options.getLogger().log(SentryLevel.WARNING, "addBreadcrumb called with null parameter."); } else { - stack.peek().getScope().addBreadcrumb(breadcrumb, hints); + stack.peek().getScope().addBreadcrumb(breadcrumb, hint); } } @@ -547,7 +547,7 @@ public void flush(long timeoutMillis) { public @NotNull SentryId captureTransaction( final @NotNull SentryTransaction transaction, final @Nullable TraceState traceState, - final @Nullable Hints hints, + final @Nullable Hint hint, final @Nullable ProfilingTraceData profilingTraceData) { Objects.requireNonNull(transaction, "transaction is required"); @@ -584,7 +584,7 @@ public void flush(long timeoutMillis) { sentryId = item.getClient() .captureTransaction( - transaction, traceState, item.getScope(), hints, profilingTraceData); + transaction, traceState, item.getScope(), hint, profilingTraceData); } catch (Throwable e) { options .getLogger() diff --git a/sentry/src/main/java/io/sentry/HubAdapter.java b/sentry/src/main/java/io/sentry/HubAdapter.java index 05deaee59a..15f044907b 100644 --- a/sentry/src/main/java/io/sentry/HubAdapter.java +++ b/sentry/src/main/java/io/sentry/HubAdapter.java @@ -1,6 +1,6 @@ package io.sentry; -import io.sentry.hints.Hints; +import io.sentry.hints.Hint; import io.sentry.protocol.SentryId; import io.sentry.protocol.SentryTransaction; import io.sentry.protocol.User; @@ -26,8 +26,8 @@ public boolean isEnabled() { } @Override - public @NotNull SentryId captureEvent(@NotNull SentryEvent event, @Nullable Hints hints) { - return Sentry.captureEvent(event, hints); + public @NotNull SentryId captureEvent(@NotNull SentryEvent event, @Nullable Hint hint) { + return Sentry.captureEvent(event, hint); } @Override @@ -37,14 +37,13 @@ public boolean isEnabled() { @ApiStatus.Internal @Override - public @NotNull SentryId captureEnvelope( - @NotNull SentryEnvelope envelope, @Nullable Hints hints) { - return Sentry.getCurrentHub().captureEnvelope(envelope, hints); + public @NotNull SentryId captureEnvelope(@NotNull SentryEnvelope envelope, @Nullable Hint hint) { + return Sentry.getCurrentHub().captureEnvelope(envelope, hint); } @Override - public @NotNull SentryId captureException(@NotNull Throwable throwable, @Nullable Hints hints) { - return Sentry.captureException(throwable, hints); + public @NotNull SentryId captureException(@NotNull Throwable throwable, @Nullable Hint hint) { + return Sentry.captureException(throwable, hint); } @Override @@ -68,8 +67,8 @@ public void close() { } @Override - public void addBreadcrumb(@NotNull Breadcrumb breadcrumb, @Nullable Hints hints) { - Sentry.addBreadcrumb(breadcrumb, hints); + public void addBreadcrumb(@NotNull Breadcrumb breadcrumb, @Nullable Hint hint) { + Sentry.addBreadcrumb(breadcrumb, hint); } @Override @@ -161,10 +160,10 @@ public void flush(long timeoutMillis) { public @NotNull SentryId captureTransaction( @NotNull SentryTransaction transaction, @Nullable TraceState traceState, - @Nullable Hints hints, + @Nullable Hint hint, @Nullable ProfilingTraceData profilingTraceData) { return Sentry.getCurrentHub() - .captureTransaction(transaction, traceState, hints, profilingTraceData); + .captureTransaction(transaction, traceState, hint, profilingTraceData); } @Override diff --git a/sentry/src/main/java/io/sentry/IEnvelopeSender.java b/sentry/src/main/java/io/sentry/IEnvelopeSender.java index f944804682..b37307fa5b 100644 --- a/sentry/src/main/java/io/sentry/IEnvelopeSender.java +++ b/sentry/src/main/java/io/sentry/IEnvelopeSender.java @@ -1,8 +1,8 @@ package io.sentry; -import io.sentry.hints.Hints; +import io.sentry.hints.Hint; import org.jetbrains.annotations.NotNull; public interface IEnvelopeSender { - void processEnvelopeFile(@NotNull String path, @NotNull Hints hints); + void processEnvelopeFile(@NotNull String path, @NotNull Hint hint); } diff --git a/sentry/src/main/java/io/sentry/IHub.java b/sentry/src/main/java/io/sentry/IHub.java index c23c4f52fe..f4223e6a28 100644 --- a/sentry/src/main/java/io/sentry/IHub.java +++ b/sentry/src/main/java/io/sentry/IHub.java @@ -1,6 +1,6 @@ package io.sentry; -import io.sentry.hints.Hints; +import io.sentry.hints.Hint; import io.sentry.protocol.SentryId; import io.sentry.protocol.SentryTransaction; import io.sentry.protocol.User; @@ -24,11 +24,11 @@ public interface IHub { * Captures the event. * * @param event the event - * @param hints SDK specific but provides high level information about the origin of the event + * @param hint SDK specific but provides high level information about the origin of the event * @return The Id (SentryId object) of the event */ @NotNull - SentryId captureEvent(@NotNull SentryEvent event, @Nullable Hints hints); + SentryId captureEvent(@NotNull SentryEvent event, @Nullable Hint hint); /** * Captures the event. @@ -64,11 +64,11 @@ public interface IHub { * Captures an envelope. * * @param envelope the SentryEnvelope to send. - * @param hints SDK specific but provides high level information about the origin of the event + * @param hint SDK specific but provides high level information about the origin of the event * @return The Id (SentryId object) of the event */ @NotNull - SentryId captureEnvelope(@NotNull SentryEnvelope envelope, @Nullable Hints hints); + SentryId captureEnvelope(@NotNull SentryEnvelope envelope, @Nullable Hint hint); /** * Captures an envelope. @@ -77,18 +77,18 @@ public interface IHub { * @return The Id (SentryId object) of the event */ default @NotNull SentryId captureEnvelope(@NotNull SentryEnvelope envelope) { - return captureEnvelope(envelope, new Hints()); + return captureEnvelope(envelope, new Hint()); } /** * Captures the exception. * * @param throwable The exception. - * @param hints SDK specific but provides high level information about the origin of the event + * @param hint SDK specific but provides high level information about the origin of the event * @return The Id (SentryId object) of the event */ @NotNull - SentryId captureException(@NotNull Throwable throwable, @Nullable Hints hints); + SentryId captureException(@NotNull Throwable throwable, @Nullable Hint hint); /** * Captures the exception. @@ -120,9 +120,9 @@ public interface IHub { * Adds a breadcrumb to the current Scope * * @param breadcrumb the breadcrumb - * @param hints SDK specific but provides high level information about the origin of the event + * @param hint SDK specific but provides high level information about the origin of the event */ - void addBreadcrumb(@NotNull Breadcrumb breadcrumb, @Nullable Hints hints); + void addBreadcrumb(@NotNull Breadcrumb breadcrumb, @Nullable Hint hint); /** * Adds a breadcrumb to the current Scope @@ -130,7 +130,7 @@ public interface IHub { * @param breadcrumb the breadcrumb */ default void addBreadcrumb(@NotNull Breadcrumb breadcrumb) { - addBreadcrumb(breadcrumb, new Hints()); + addBreadcrumb(breadcrumb, new Hint()); } /** @@ -272,7 +272,7 @@ default void addBreadcrumb(@NotNull String message, @NotNull String category) { * * @param transaction the transaction * @param traceState the trace state - * @param hints the hints + * @param hint the hints * @param profilingTraceData the profiling trace data * @return transaction's id */ @@ -281,7 +281,7 @@ default void addBreadcrumb(@NotNull String message, @NotNull String category) { SentryId captureTransaction( @NotNull SentryTransaction transaction, @Nullable TraceState traceState, - @Nullable Hints hints, + @Nullable Hint hint, final @Nullable ProfilingTraceData profilingTraceData); /** @@ -289,7 +289,7 @@ SentryId captureTransaction( * * @param transaction the transaction * @param traceState the trace state - * @param hints the hints + * @param hint the hints * @return transaction's id */ @ApiStatus.Internal @@ -297,15 +297,14 @@ SentryId captureTransaction( default SentryId captureTransaction( @NotNull SentryTransaction transaction, @Nullable TraceState traceState, - @Nullable Hints hints) { - return captureTransaction(transaction, traceState, hints, null); + @Nullable Hint hint) { + return captureTransaction(transaction, traceState, hint, null); } @ApiStatus.Internal @NotNull - default SentryId captureTransaction( - @NotNull SentryTransaction transaction, @Nullable Hints hints) { - return captureTransaction(transaction, null, hints); + default SentryId captureTransaction(@NotNull SentryTransaction transaction, @Nullable Hint hint) { + return captureTransaction(transaction, null, hint); } /** diff --git a/sentry/src/main/java/io/sentry/ISentryClient.java b/sentry/src/main/java/io/sentry/ISentryClient.java index 6b421542cf..30ca742838 100644 --- a/sentry/src/main/java/io/sentry/ISentryClient.java +++ b/sentry/src/main/java/io/sentry/ISentryClient.java @@ -1,6 +1,6 @@ package io.sentry; -import io.sentry.hints.Hints; +import io.sentry.hints.Hint; import io.sentry.protocol.Message; import io.sentry.protocol.SentryId; import io.sentry.protocol.SentryTransaction; @@ -23,11 +23,11 @@ public interface ISentryClient { * * @param event the event * @param scope An optional scope to be applied to the event. - * @param hints SDK specific but provides high level information about the origin of the event. + * @param hint SDK specific but provides high level information about the origin of the event. * @return The Id (SentryId object) of the event. */ @NotNull - SentryId captureEvent(@NotNull SentryEvent event, @Nullable Scope scope, @Nullable Hints hints); + SentryId captureEvent(@NotNull SentryEvent event, @Nullable Scope scope, @Nullable Hint hint); /** Flushes out the queue for up to timeout seconds and disable the client. */ void close(); @@ -64,11 +64,11 @@ public interface ISentryClient { * Capture the event * * @param event the event - * @param hints SDK specific but provides high level information about the origin of the event. + * @param hint SDK specific but provides high level information about the origin of the event. * @return The Id (SentryId object) of the event. */ - default @NotNull SentryId captureEvent(@NotNull SentryEvent event, @Nullable Hints hints) { - return captureEvent(event, null, hints); + default @NotNull SentryId captureEvent(@NotNull SentryEvent event, @Nullable Hint hint) { + return captureEvent(event, null, hint); } /** @@ -115,25 +115,25 @@ public interface ISentryClient { * Captures the exception. * * @param throwable The exception. - * @param hints SDK specific but provides high level information about the origin of the event + * @param hint SDK specific but provides high level information about the origin of the event * @param scope An optional scope to be applied to the event. * @return The Id (SentryId object) of the event */ default @NotNull SentryId captureException( - @NotNull Throwable throwable, @Nullable Scope scope, @Nullable Hints hints) { + @NotNull Throwable throwable, @Nullable Scope scope, @Nullable Hint hint) { SentryEvent event = new SentryEvent(throwable); - return captureEvent(event, scope, hints); + return captureEvent(event, scope, hint); } /** * Captures the exception. * * @param throwable The exception. - * @param hints SDK specific but provides high level information about the origin of the event + * @param hint SDK specific but provides high level information about the origin of the event * @return The Id (SentryId object) of the event */ - default @NotNull SentryId captureException(@NotNull Throwable throwable, @Nullable Hints hints) { - return captureException(throwable, null, hints); + default @NotNull SentryId captureException(@NotNull Throwable throwable, @Nullable Hint hint) { + return captureException(throwable, null, hint); } /** @@ -158,10 +158,10 @@ public interface ISentryClient { * Captures a session. This method transform a session to an envelope and forwards to * captureEnvelope * - * @param hints SDK specific but provides high level information about the origin of the event + * @param hint SDK specific but provides high level information about the origin of the event * @param session the Session */ - void captureSession(@NotNull Session session, @Nullable Hints hints); + void captureSession(@NotNull Session session, @Nullable Hint hint); /** * Captures a session. This method transform a session to an envelope and forwards to @@ -177,11 +177,11 @@ default void captureSession(@NotNull Session session) { * Captures an envelope. * * @param envelope the SentryEnvelope to send. - * @param hints SDK specific but provides high level information about the origin of the event + * @param hint SDK specific but provides high level information about the origin of the event * @return The Id (SentryId object) of the event */ @Nullable - SentryId captureEnvelope(@NotNull SentryEnvelope envelope, @Nullable Hints hints); + SentryId captureEnvelope(@NotNull SentryEnvelope envelope, @Nullable Hint hint); /** * Captures an envelope. @@ -198,13 +198,13 @@ default void captureSession(@NotNull Session session) { * * @param transaction the {@link ITransaction} to send * @param scope An optional scope to be applied to the event. - * @param hints SDK specific but provides high level information about the origin of the event + * @param hint SDK specific but provides high level information about the origin of the event * @return The Id (SentryId object) of the event */ @NotNull default SentryId captureTransaction( - @NotNull SentryTransaction transaction, @Nullable Scope scope, @Nullable Hints hints) { - return captureTransaction(transaction, null, scope, hints); + @NotNull SentryTransaction transaction, @Nullable Scope scope, @Nullable Hint hint) { + return captureTransaction(transaction, null, scope, hint); } /** @@ -213,7 +213,7 @@ default SentryId captureTransaction( * @param transaction the {@link ITransaction} to send * @param traceState the trace state * @param scope An optional scope to be applied to the event. - * @param hints SDK specific but provides high level information about the origin of the event + * @param hint SDK specific but provides high level information about the origin of the event * @return The Id (SentryId object) of the event */ @NotNull @@ -222,8 +222,8 @@ default SentryId captureTransaction( @NotNull SentryTransaction transaction, @Nullable TraceState traceState, @Nullable Scope scope, - @Nullable Hints hints) { - return captureTransaction(transaction, traceState, scope, hints, null); + @Nullable Hint hint) { + return captureTransaction(transaction, traceState, scope, hint, null); } /** @@ -232,7 +232,7 @@ default SentryId captureTransaction( * @param transaction the {@link ITransaction} to send * @param traceState the trace state * @param scope An optional scope to be applied to the event. - * @param hints SDK specific but provides high level information about the origin of the event + * @param hint SDK specific but provides high level information about the origin of the event * @param profilingTraceData An optional profiling trace data captured during the transaction * @return The Id (SentryId object) of the event */ @@ -242,7 +242,7 @@ SentryId captureTransaction( @NotNull SentryTransaction transaction, @Nullable TraceState traceState, @Nullable Scope scope, - @Nullable Hints hints, + @Nullable Hint hint, @Nullable ProfilingTraceData profilingTraceData); /** diff --git a/sentry/src/main/java/io/sentry/MainEventProcessor.java b/sentry/src/main/java/io/sentry/MainEventProcessor.java index 37cfece2df..83c0b56be0 100644 --- a/sentry/src/main/java/io/sentry/MainEventProcessor.java +++ b/sentry/src/main/java/io/sentry/MainEventProcessor.java @@ -1,7 +1,7 @@ package io.sentry; import io.sentry.hints.Cached; -import io.sentry.hints.Hints; +import io.sentry.hints.Hint; import io.sentry.protocol.DebugImage; import io.sentry.protocol.DebugMeta; import io.sentry.protocol.SentryException; @@ -65,15 +65,14 @@ public MainEventProcessor(final @NotNull SentryOptions options) { } @Override - public @NotNull SentryEvent process( - final @NotNull SentryEvent event, final @NotNull Hints hints) { + public @NotNull SentryEvent process(final @NotNull SentryEvent event, final @NotNull Hint hint) { setCommons(event); setExceptions(event); setDebugMeta(event); - if (shouldApplyScopeData(event, hints)) { + if (shouldApplyScopeData(event, hint)) { processNonCachedEvent(event); - setThreads(event, hints); + setThreads(event, hint); } return event; @@ -101,8 +100,8 @@ private void setDebugMeta(final @NotNull SentryEvent event) { } private boolean shouldApplyScopeData( - final @NotNull SentryBaseEvent event, final @NotNull Hints hints) { - if (HintUtils.shouldApplyScopeData(hints)) { + final @NotNull SentryBaseEvent event, final @NotNull Hint hint) { + if (HintUtils.shouldApplyScopeData(hint)) { return true; } else { options @@ -127,10 +126,10 @@ private void processNonCachedEvent(final @NotNull SentryBaseEvent event) { @Override public @NotNull SentryTransaction process( - final @NotNull SentryTransaction transaction, final @NotNull Hints hints) { + final @NotNull SentryTransaction transaction, final @NotNull Hint hint) { setCommons(transaction); - if (shouldApplyScopeData(transaction, hints)) { + if (shouldApplyScopeData(transaction, hint)) { processNonCachedEvent(transaction); } @@ -214,7 +213,7 @@ private void setExceptions(final @NotNull SentryEvent event) { } } - private void setThreads(final @NotNull SentryEvent event, final @NotNull Hints hints) { + private void setThreads(final @NotNull SentryEvent event, final @NotNull Hint hint) { if (event.getThreads() == null) { // collecting threadIds that came from the exception mechanism, so we can mark threads as // crashed properly @@ -237,7 +236,7 @@ private void setThreads(final @NotNull SentryEvent event, final @NotNull Hints h event.setThreads(sentryThreadFactory.getCurrentThreads(mechanismThreadIds)); } else if (options.isAttachStacktrace() && (eventExceptions == null || eventExceptions.isEmpty()) - && !isCachedHint(hints)) { + && !isCachedHint(hint)) { // when attachStacktrace is enabled, we attach only the current thread and its stack traces, // if there are no exceptions, exceptions have its own stack traces. event.setThreads(sentryThreadFactory.getCurrentThread()); @@ -249,11 +248,11 @@ private void setThreads(final @NotNull SentryEvent event, final @NotNull Hints h * If the event has a Cached Hint, it means that it came from the EnvelopeFileObserver. We don't * want to append the current thread to the event. * - * @param hints the Hints + * @param hint the Hints * @return true if Cached or false otherwise */ - private boolean isCachedHint(final @NotNull Hints hints) { - return HintUtils.hasType(hints, Cached.class); + private boolean isCachedHint(final @NotNull Hint hint) { + return HintUtils.hasType(hint, Cached.class); } @Override diff --git a/sentry/src/main/java/io/sentry/NoOpHub.java b/sentry/src/main/java/io/sentry/NoOpHub.java index 46ece2c91b..14b2975acf 100644 --- a/sentry/src/main/java/io/sentry/NoOpHub.java +++ b/sentry/src/main/java/io/sentry/NoOpHub.java @@ -1,6 +1,6 @@ package io.sentry; -import io.sentry.hints.Hints; +import io.sentry.hints.Hint; import io.sentry.protocol.SentryId; import io.sentry.protocol.SentryTransaction; import io.sentry.protocol.User; @@ -27,7 +27,7 @@ public boolean isEnabled() { } @Override - public @NotNull SentryId captureEvent(@NotNull SentryEvent event, @Nullable Hints hints) { + public @NotNull SentryId captureEvent(@NotNull SentryEvent event, @Nullable Hint hint) { return SentryId.EMPTY_ID; } @@ -37,13 +37,12 @@ public boolean isEnabled() { } @Override - public @NotNull SentryId captureEnvelope( - @NotNull SentryEnvelope envelope, @Nullable Hints hints) { + public @NotNull SentryId captureEnvelope(@NotNull SentryEnvelope envelope, @Nullable Hint hint) { return SentryId.EMPTY_ID; } @Override - public @NotNull SentryId captureException(@NotNull Throwable throwable, @Nullable Hints hints) { + public @NotNull SentryId captureException(@NotNull Throwable throwable, @Nullable Hint hint) { return SentryId.EMPTY_ID; } @@ -60,7 +59,7 @@ public void endSession() {} public void close() {} @Override - public void addBreadcrumb(@NotNull Breadcrumb breadcrumb, @Nullable Hints hints) {} + public void addBreadcrumb(@NotNull Breadcrumb breadcrumb, @Nullable Hint hint) {} @Override public void setLevel(@Nullable SentryLevel level) {} @@ -121,7 +120,7 @@ public void flush(long timeoutMillis) {} public @NotNull SentryId captureTransaction( final @NotNull SentryTransaction transaction, final @Nullable TraceState traceState, - final @Nullable Hints hints, + final @Nullable Hint hint, final @Nullable ProfilingTraceData profilingTraceData) { return SentryId.EMPTY_ID; } diff --git a/sentry/src/main/java/io/sentry/NoOpSentryClient.java b/sentry/src/main/java/io/sentry/NoOpSentryClient.java index d86f2165cd..7916c1b899 100644 --- a/sentry/src/main/java/io/sentry/NoOpSentryClient.java +++ b/sentry/src/main/java/io/sentry/NoOpSentryClient.java @@ -1,6 +1,6 @@ package io.sentry; -import io.sentry.hints.Hints; +import io.sentry.hints.Hint; import io.sentry.protocol.SentryId; import io.sentry.protocol.SentryTransaction; import org.jetbrains.annotations.NotNull; @@ -23,7 +23,7 @@ public boolean isEnabled() { @Override public @NotNull SentryId captureEvent( - @NotNull SentryEvent event, @Nullable Scope scope, @Nullable Hints hints) { + @NotNull SentryEvent event, @Nullable Scope scope, @Nullable Hint hint) { return SentryId.EMPTY_ID; } @@ -37,10 +37,10 @@ public void flush(long timeoutMillis) {} public void captureUserFeedback(@NotNull UserFeedback userFeedback) {} @Override - public void captureSession(@NotNull Session session, @Nullable Hints hints) {} + public void captureSession(@NotNull Session session, @Nullable Hint hint) {} @Override - public SentryId captureEnvelope(@NotNull SentryEnvelope envelope, @Nullable Hints hints) { + public SentryId captureEnvelope(@NotNull SentryEnvelope envelope, @Nullable Hint hint) { return SentryId.EMPTY_ID; } @@ -49,7 +49,7 @@ public SentryId captureEnvelope(@NotNull SentryEnvelope envelope, @Nullable Hint @NotNull SentryTransaction transaction, @Nullable TraceState traceState, @Nullable Scope scope, - @Nullable Hints hints, + @Nullable Hint hint, @Nullable ProfilingTraceData profilingTraceData) { return SentryId.EMPTY_ID; } diff --git a/sentry/src/main/java/io/sentry/OutboxSender.java b/sentry/src/main/java/io/sentry/OutboxSender.java index 122347765e..e653f170f8 100644 --- a/sentry/src/main/java/io/sentry/OutboxSender.java +++ b/sentry/src/main/java/io/sentry/OutboxSender.java @@ -4,7 +4,7 @@ import static io.sentry.cache.EnvelopeCache.PREFIX_CURRENT_SESSION_FILE; import io.sentry.hints.Flushable; -import io.sentry.hints.Hints; +import io.sentry.hints.Hint; import io.sentry.hints.Resettable; import io.sentry.hints.Retryable; import io.sentry.hints.SubmissionResult; @@ -53,7 +53,7 @@ public OutboxSender( } @Override - protected void processFile(final @NotNull File file, @NotNull Hints hints) { + protected void processFile(final @NotNull File file, @NotNull Hint hint) { Objects.requireNonNull(file, "File is required."); if (!isRelevantFileName(file.getName())) { @@ -69,14 +69,14 @@ protected void processFile(final @NotNull File file, @NotNull Hints hints) { "Stream from path %s resulted in a null envelope.", file.getAbsolutePath()); } else { - processEnvelope(envelope, hints); + processEnvelope(envelope, hint); logger.log(SentryLevel.DEBUG, "File '%s' is done.", file.getAbsolutePath()); } } catch (IOException e) { logger.log(SentryLevel.ERROR, "Error processing envelope.", e); } finally { HintUtils.runIfHasTypeLogIfNot( - hints, + hint, Retryable.class, logger, (retryable) -> { @@ -101,13 +101,13 @@ protected boolean isRelevantFileName(final @Nullable String fileName) { } @Override - public void processEnvelopeFile(@NotNull String path, @NotNull Hints hints) { + public void processEnvelopeFile(@NotNull String path, @NotNull Hint hint) { Objects.requireNonNull(path, "Path is required."); - processFile(new File(path), hints); + processFile(new File(path), hint); } - private void processEnvelope(final @NotNull SentryEnvelope envelope, final @NotNull Hints hints) + private void processEnvelope(final @NotNull SentryEnvelope envelope, final @NotNull Hint hint) throws IOException { logger.log( SentryLevel.DEBUG, @@ -135,10 +135,10 @@ private void processEnvelope(final @NotNull SentryEnvelope envelope, final @NotN logUnexpectedEventId(envelope, event.getEventId(), currentItem); continue; } - hub.captureEvent(event, hints); + hub.captureEvent(event, hint); logItemCaptured(currentItem); - if (!waitFlush(hints)) { + if (!waitFlush(hint)) { logTimeout(event.getEventId()); break; } @@ -167,10 +167,10 @@ private void processEnvelope(final @NotNull SentryEnvelope envelope, final @NotN // transient property. transaction.getContexts().getTrace().setSampled(true); } - hub.captureTransaction(transaction, envelope.getHeader().getTrace(), hints); + hub.captureTransaction(transaction, envelope.getHeader().getTrace(), hint); logItemCaptured(currentItem); - if (!waitFlush(hints)) { + if (!waitFlush(hint)) { logTimeout(transaction.getEventId()); break; } @@ -183,14 +183,14 @@ private void processEnvelope(final @NotNull SentryEnvelope envelope, final @NotN final SentryEnvelope newEnvelope = new SentryEnvelope( envelope.getHeader().getEventId(), envelope.getHeader().getSdkVersion(), item); - hub.captureEnvelope(newEnvelope, hints); + hub.captureEnvelope(newEnvelope, hint); logger.log( SentryLevel.DEBUG, "%s item %d is being captured.", item.getHeader().getType().getItemType(), currentItem); - if (!waitFlush(hints)) { + if (!waitFlush(hint)) { logger.log( SentryLevel.WARNING, "Timed out waiting for item type submission: %s", @@ -199,7 +199,7 @@ private void processEnvelope(final @NotNull SentryEnvelope envelope, final @NotN } } - final Object sentrySdkHint = HintUtils.getSentrySdkHint(hints); + final Object sentrySdkHint = HintUtils.getSentrySdkHint(hint); if (sentrySdkHint instanceof SubmissionResult) { if (!((SubmissionResult) sentrySdkHint).isSuccess()) { // Failed to send an item of the envelope: Stop attempting to send the rest (an attachment @@ -213,7 +213,7 @@ private void processEnvelope(final @NotNull SentryEnvelope envelope, final @NotN } // reset the Hint to its initial state as we use it multiple times. - HintUtils.runIfHasType(hints, Resettable.class, (resettable) -> resettable.reset()); + HintUtils.runIfHasType(hint, Resettable.class, (resettable) -> resettable.reset()); } } @@ -243,8 +243,8 @@ private void logTimeout(final @Nullable SentryId eventId) { logger.log(SentryLevel.WARNING, "Timed out waiting for event id submission: %s", eventId); } - private boolean waitFlush(final @NotNull Hints hints) { - @Nullable Object sentrySdkHint = HintUtils.getSentrySdkHint(hints); + private boolean waitFlush(final @NotNull Hint hint) { + @Nullable Object sentrySdkHint = HintUtils.getSentrySdkHint(hint); if (sentrySdkHint instanceof Flushable) { return ((Flushable) sentrySdkHint).waitFlush(); } else { diff --git a/sentry/src/main/java/io/sentry/Scope.java b/sentry/src/main/java/io/sentry/Scope.java index 331ae59f82..b2b60a699c 100644 --- a/sentry/src/main/java/io/sentry/Scope.java +++ b/sentry/src/main/java/io/sentry/Scope.java @@ -1,6 +1,6 @@ package io.sentry; -import io.sentry.hints.Hints; +import io.sentry.hints.Hint; import io.sentry.protocol.Contexts; import io.sentry.protocol.Request; import io.sentry.protocol.User; @@ -289,15 +289,15 @@ Queue getBreadcrumbs() { * * @param callback the BeforeBreadcrumb callback * @param breadcrumb the breadcrumb - * @param hints the hints + * @param hint the hints * @return the mutated breadcrumb or null if dropped */ private @Nullable Breadcrumb executeBeforeBreadcrumb( final @NotNull SentryOptions.BeforeBreadcrumbCallback callback, @NotNull Breadcrumb breadcrumb, - final @NotNull Hints hints) { + final @NotNull Hint hint) { try { - breadcrumb = callback.execute(breadcrumb, hints); + breadcrumb = callback.execute(breadcrumb, hint); } catch (Throwable e) { options .getLogger() @@ -318,19 +318,19 @@ Queue getBreadcrumbs() { * set * * @param breadcrumb the breadcrumb - * @param hints the hint + * @param hint the hint */ - public void addBreadcrumb(@NotNull Breadcrumb breadcrumb, @Nullable Hints hints) { + public void addBreadcrumb(@NotNull Breadcrumb breadcrumb, @Nullable Hint hint) { if (breadcrumb == null) { return; } - if (hints == null) { - hints = new Hints(); + if (hint == null) { + hint = new Hint(); } SentryOptions.BeforeBreadcrumbCallback callback = options.getBeforeBreadcrumb(); if (callback != null) { - breadcrumb = executeBeforeBreadcrumb(callback, breadcrumb, hints); + breadcrumb = executeBeforeBreadcrumb(callback, breadcrumb, hint); } if (breadcrumb != null) { this.breadcrumbs.add(breadcrumb); diff --git a/sentry/src/main/java/io/sentry/Sentry.java b/sentry/src/main/java/io/sentry/Sentry.java index a3dbc6c143..da5eaf0c40 100644 --- a/sentry/src/main/java/io/sentry/Sentry.java +++ b/sentry/src/main/java/io/sentry/Sentry.java @@ -2,7 +2,7 @@ import io.sentry.cache.EnvelopeCache; import io.sentry.config.PropertiesProviderFactory; -import io.sentry.hints.Hints; +import io.sentry.hints.Hint; import io.sentry.protocol.SentryId; import io.sentry.protocol.User; import io.sentry.util.FileUtils; @@ -281,12 +281,12 @@ public static synchronized void close() { * Captures the event. * * @param event the event - * @param hints SDK specific but provides high level information about the origin of the event + * @param hint SDK specific but provides high level information about the origin of the event * @return The Id (SentryId object) of the event */ public static @NotNull SentryId captureEvent( - final @NotNull SentryEvent event, final @Nullable Hints hints) { - return getCurrentHub().captureEvent(event, hints); + final @NotNull SentryEvent event, final @Nullable Hint hint) { + return getCurrentHub().captureEvent(event, hint); } /** @@ -325,12 +325,12 @@ public static synchronized void close() { * Captures the exception. * * @param throwable The exception. - * @param hints SDK specific but provides high level information about the origin of the event + * @param hint SDK specific but provides high level information about the origin of the event * @return The Id (SentryId object) of the event */ public static @NotNull SentryId captureException( - final @NotNull Throwable throwable, final @Nullable Hints hints) { - return getCurrentHub().captureException(throwable, hints); + final @NotNull Throwable throwable, final @Nullable Hint hint) { + return getCurrentHub().captureException(throwable, hint); } /** @@ -346,11 +346,11 @@ public static void captureUserFeedback(final @NotNull UserFeedback userFeedback) * Adds a breadcrumb to the current Scope * * @param breadcrumb the breadcrumb - * @param hints SDK specific but provides high level information about the origin of the event + * @param hint SDK specific but provides high level information about the origin of the event */ public static void addBreadcrumb( - final @NotNull Breadcrumb breadcrumb, final @Nullable Hints hints) { - getCurrentHub().addBreadcrumb(breadcrumb, hints); + final @NotNull Breadcrumb breadcrumb, final @Nullable Hint hint) { + getCurrentHub().addBreadcrumb(breadcrumb, hint); } /** diff --git a/sentry/src/main/java/io/sentry/SentryClient.java b/sentry/src/main/java/io/sentry/SentryClient.java index 5fd62f9b27..4d8f4476b7 100644 --- a/sentry/src/main/java/io/sentry/SentryClient.java +++ b/sentry/src/main/java/io/sentry/SentryClient.java @@ -3,7 +3,7 @@ import io.sentry.clientreport.DiscardReason; import io.sentry.exception.SentryEnvelopeException; import io.sentry.hints.DiskFlushNotification; -import io.sentry.hints.Hints; +import io.sentry.hints.Hint; import io.sentry.protocol.Contexts; import io.sentry.protocol.SentryId; import io.sentry.protocol.SentryTransaction; @@ -58,8 +58,8 @@ public boolean isEnabled() { } private boolean shouldApplyScopeData( - final @NotNull SentryBaseEvent event, final @NotNull Hints hints) { - if (HintUtils.shouldApplyScopeData(hints)) { + final @NotNull SentryBaseEvent event, final @NotNull Hint hint) { + if (HintUtils.shouldApplyScopeData(hint)) { return true; } else { options @@ -71,16 +71,15 @@ private boolean shouldApplyScopeData( @Override public @NotNull SentryId captureEvent( - @NotNull SentryEvent event, final @Nullable Scope scope, @Nullable Hints hints) { + @NotNull SentryEvent event, final @Nullable Scope scope, @Nullable Hint hint) { Objects.requireNonNull(event, "SentryEvent is required."); - if (hints == null) { - hints = new Hints(); + if (hint == null) { + hint = new Hint(); } - // TODO what does cached etc mean for devs manipulating hints in beforeSend and eventProcessor? - if (shouldApplyScopeData(event, hints)) { - addScopeAttachmentsToHints(scope, hints); + if (shouldApplyScopeData(event, hint)) { + addScopeAttachmentsToHint(scope, hint); } options.getLogger().log(SentryLevel.DEBUG, "Capturing event: %s", event.getEventId()); @@ -101,11 +100,11 @@ private boolean shouldApplyScopeData( } } - if (shouldApplyScopeData(event, hints)) { + if (shouldApplyScopeData(event, hint)) { // Event has already passed through here before it was cached // Going through again could be reading data that is no longer relevant // i.e proguard id, app version, threads - event = applyScope(event, scope, hints); + event = applyScope(event, scope, hint); if (event == null) { options.getLogger().log(SentryLevel.DEBUG, "Event was dropped by applyScope"); @@ -113,10 +112,10 @@ private boolean shouldApplyScopeData( } } - event = processEvent(event, hints, options.getEventProcessors()); + event = processEvent(event, hint, options.getEventProcessors()); if (event != null) { - event = executeBeforeSend(event, hints); + event = executeBeforeSend(event, hint); if (event == null) { options.getLogger().log(SentryLevel.DEBUG, "Event was dropped by beforeSend"); @@ -136,7 +135,7 @@ private boolean shouldApplyScopeData( @Nullable Session session = null; if (event != null) { - session = updateSessionData(event, hints, scope); + session = updateSessionData(event, hint, scope); if (!sample()) { options @@ -176,11 +175,11 @@ private boolean shouldApplyScopeData( ? scope.getTransaction().traceState() : null; final boolean shouldSendAttachments = event != null; - List attachments = shouldSendAttachments ? getAttachments(hints) : null; + List attachments = shouldSendAttachments ? getAttachments(hint) : null; final SentryEnvelope envelope = buildEnvelope(event, attachments, session, traceState, null); if (envelope != null) { - transport.send(envelope, hints); + transport.send(envelope, hint); } } catch (IOException | SentryEnvelopeException e) { options.getLogger().log(SentryLevel.WARNING, e, "Capturing event %s failed.", sentryId); @@ -192,9 +191,9 @@ private boolean shouldApplyScopeData( return sentryId; } - private void addScopeAttachmentsToHints(@Nullable Scope scope, @NotNull Hints hints) { + private void addScopeAttachmentsToHint(@Nullable Scope scope, @NotNull Hint hint) { if (scope != null) { - hints.addAttachments(scope.getAttachments()); + hint.addAttachments(scope.getAttachments()); } } @@ -224,10 +223,10 @@ private boolean shouldSendSessionUpdateForDroppedEvent( return false; } - private @Nullable List getAttachments(final @NotNull Hints hints) { - @NotNull final List attachments = hints.getAttachments(); + private @Nullable List getAttachments(final @NotNull Hint hint) { + @NotNull final List attachments = hint.getAttachments(); - @Nullable final Attachment screenshot = hints.getScreenshot(); + @Nullable final Attachment screenshot = hint.getScreenshot(); if (screenshot != null) { attachments.add(screenshot); } @@ -286,11 +285,11 @@ private boolean shouldSendSessionUpdateForDroppedEvent( @Nullable private SentryEvent processEvent( @NotNull SentryEvent event, - final @NotNull Hints hints, + final @NotNull Hint hint, final @NotNull List eventProcessors) { for (final EventProcessor processor : eventProcessors) { try { - event = processor.process(event, hints); + event = processor.process(event, hint); } catch (Throwable e) { options .getLogger() @@ -320,11 +319,11 @@ private SentryEvent processEvent( @Nullable private SentryTransaction processTransaction( @NotNull SentryTransaction transaction, - final @NotNull Hints hints, + final @NotNull Hint hint, final @NotNull List eventProcessors) { for (final EventProcessor processor : eventProcessors) { try { - transaction = processor.process(transaction, hints); + transaction = processor.process(transaction, hint); } catch (Throwable e) { options .getLogger() @@ -394,16 +393,16 @@ public void captureUserFeedback(final @NotNull UserFeedback userFeedback) { * Updates the session data based on the event, hint and scope data * * @param event the SentryEvent - * @param hints the hint or null + * @param hint the hint or null * @param scope the Scope or null */ @TestOnly @Nullable Session updateSessionData( - final @NotNull SentryEvent event, final @NotNull Hints hints, final @Nullable Scope scope) { + final @NotNull SentryEvent event, final @NotNull Hint hint, final @Nullable Scope scope) { Session clonedSession = null; - if (HintUtils.shouldApplyScopeData(hints)) { + if (HintUtils.shouldApplyScopeData(hint)) { if (scope != null) { clonedSession = scope.withSession( @@ -429,7 +428,7 @@ Session updateSessionData( if (session.update(status, userAgent, crashedOrErrored)) { // if hint is DiskFlushNotification, it means we have an uncaughtException // and we can end the session. - if (HintUtils.hasType(hints, DiskFlushNotification.class)) { + if (HintUtils.hasType(hint, DiskFlushNotification.class)) { session.end(); } } @@ -448,7 +447,7 @@ Session updateSessionData( @ApiStatus.Internal @Override - public void captureSession(final @NotNull Session session, final @Nullable Hints hints) { + public void captureSession(final @NotNull Session session, final @Nullable Hint hint) { Objects.requireNonNull(session, "Session is required."); if (session.getRelease() == null || session.getRelease().isEmpty()) { @@ -466,21 +465,21 @@ public void captureSession(final @NotNull Session session, final @Nullable Hints return; } - captureEnvelope(envelope, hints); + captureEnvelope(envelope, hint); } @ApiStatus.Internal @Override public @NotNull SentryId captureEnvelope( - final @NotNull SentryEnvelope envelope, @Nullable Hints hints) { + final @NotNull SentryEnvelope envelope, @Nullable Hint hint) { Objects.requireNonNull(envelope, "SentryEnvelope is required."); - if (hints == null) { - hints = new Hints(); + if (hint == null) { + hint = new Hint(); } try { - transport.send(envelope, hints); + transport.send(envelope, hint); } catch (IOException e) { options.getLogger().log(SentryLevel.ERROR, "Failed to capture envelope.", e); return SentryId.EMPTY_ID; @@ -498,16 +497,16 @@ public void captureSession(final @NotNull Session session, final @Nullable Hints @NotNull SentryTransaction transaction, @Nullable TraceState traceState, final @Nullable Scope scope, - @Nullable Hints hints, + @Nullable Hint hint, final @Nullable ProfilingTraceData profilingTraceData) { Objects.requireNonNull(transaction, "Transaction is required."); - if (hints == null) { - hints = new Hints(); + if (hint == null) { + hint = new Hint(); } - if (shouldApplyScopeData(transaction, hints)) { - addScopeAttachmentsToHints(scope, hints); + if (shouldApplyScopeData(transaction, hint)) { + addScopeAttachmentsToHint(scope, hint); } options @@ -519,11 +518,11 @@ public void captureSession(final @NotNull Session session, final @Nullable Hints sentryId = transaction.getEventId(); } - if (shouldApplyScopeData(transaction, hints)) { + if (shouldApplyScopeData(transaction, hint)) { transaction = applyScope(transaction, scope); if (transaction != null && scope != null) { - transaction = processTransaction(transaction, hints, scope.getEventProcessors()); + transaction = processTransaction(transaction, hint, scope.getEventProcessors()); } if (transaction == null) { @@ -532,7 +531,7 @@ public void captureSession(final @NotNull Session session, final @Nullable Hints } if (transaction != null) { - transaction = processTransaction(transaction, hints, options.getEventProcessors()); + transaction = processTransaction(transaction, hint, options.getEventProcessors()); } if (transaction == null) { @@ -544,13 +543,13 @@ public void captureSession(final @NotNull Session session, final @Nullable Hints final SentryEnvelope envelope = buildEnvelope( transaction, - filterForTransaction(getAttachments(hints)), + filterForTransaction(getAttachments(hint)), null, traceState, profilingTraceData); if (envelope != null) { - transport.send(envelope, hints); + transport.send(envelope, hint); } else { sentryId = SentryId.EMPTY_ID; } @@ -579,7 +578,7 @@ public void captureSession(final @NotNull Session session, final @Nullable Hints } private @Nullable SentryEvent applyScope( - @NotNull SentryEvent event, final @Nullable Scope scope, final @NotNull Hints hints) { + @NotNull SentryEvent event, final @Nullable Scope scope, final @NotNull Hint hint) { if (scope != null) { applyScope(event, scope); @@ -599,7 +598,7 @@ public void captureSession(final @NotNull Session session, final @Nullable Hints event.getContexts().setTrace(span.getSpanContext()); } - event = processEvent(event, hints, scope.getEventProcessors()); + event = processEvent(event, hint, scope.getEventProcessors()); } return event; } @@ -657,11 +656,11 @@ private void sortBreadcrumbsByDate( } private @Nullable SentryEvent executeBeforeSend( - @NotNull SentryEvent event, final @NotNull Hints hints) { + @NotNull SentryEvent event, final @NotNull Hint hint) { final SentryOptions.BeforeSendCallback beforeSend = options.getBeforeSend(); if (beforeSend != null) { try { - event = beforeSend.execute(event, hints); + event = beforeSend.execute(event, hint); } catch (Throwable e) { options .getLogger() diff --git a/sentry/src/main/java/io/sentry/SentryOptions.java b/sentry/src/main/java/io/sentry/SentryOptions.java index c1e1e28fa2..2c2a89dea0 100644 --- a/sentry/src/main/java/io/sentry/SentryOptions.java +++ b/sentry/src/main/java/io/sentry/SentryOptions.java @@ -5,7 +5,7 @@ import io.sentry.clientreport.ClientReportRecorder; import io.sentry.clientreport.IClientReportRecorder; import io.sentry.clientreport.NoOpClientReportRecorder; -import io.sentry.hints.Hints; +import io.sentry.hints.Hint; import io.sentry.protocol.SdkVersion; import io.sentry.transport.ITransportGate; import io.sentry.transport.NoOpEnvelopeCache; @@ -1594,11 +1594,11 @@ public interface BeforeSendCallback { * Mutates or drop an event before being sent * * @param event the event - * @param hints the hints + * @param hint the hints * @return the original event or the mutated event or null if event was dropped */ @Nullable - SentryEvent execute(@NotNull SentryEvent event, @NotNull Hints hints); + SentryEvent execute(@NotNull SentryEvent event, @NotNull Hint hint); } /** The BeforeBreadcrumb callback */ @@ -1608,11 +1608,11 @@ public interface BeforeBreadcrumbCallback { * Mutates or drop a callback before being added * * @param breadcrumb the breadcrumb - * @param hints the hints, usually the source of the breadcrumb + * @param hint the hints, usually the source of the breadcrumb * @return the original breadcrumb or the mutated breadcrumb of null if breadcrumb was dropped */ @Nullable - Breadcrumb execute(@NotNull Breadcrumb breadcrumb, @NotNull Hints hints); + Breadcrumb execute(@NotNull Breadcrumb breadcrumb, @NotNull Hint hint); } /** The traces sampler callback. */ diff --git a/sentry/src/main/java/io/sentry/SentryRuntimeEventProcessor.java b/sentry/src/main/java/io/sentry/SentryRuntimeEventProcessor.java index 0daca97076..43cbea7824 100644 --- a/sentry/src/main/java/io/sentry/SentryRuntimeEventProcessor.java +++ b/sentry/src/main/java/io/sentry/SentryRuntimeEventProcessor.java @@ -1,6 +1,6 @@ package io.sentry; -import io.sentry.hints.Hints; +import io.sentry.hints.Hint; import io.sentry.protocol.SentryRuntime; import io.sentry.protocol.SentryTransaction; import org.jetbrains.annotations.NotNull; @@ -22,14 +22,13 @@ public SentryRuntimeEventProcessor() { } @Override - public @NotNull SentryEvent process( - final @NotNull SentryEvent event, final @Nullable Hints hints) { + public @NotNull SentryEvent process(final @NotNull SentryEvent event, final @Nullable Hint hint) { return process(event); } @Override public @NotNull SentryTransaction process( - final @NotNull SentryTransaction transaction, final @Nullable Hints hints) { + final @NotNull SentryTransaction transaction, final @Nullable Hint hint) { return process(transaction); } diff --git a/sentry/src/main/java/io/sentry/UncaughtExceptionHandlerIntegration.java b/sentry/src/main/java/io/sentry/UncaughtExceptionHandlerIntegration.java index f7df56957e..965b3ff17b 100644 --- a/sentry/src/main/java/io/sentry/UncaughtExceptionHandlerIntegration.java +++ b/sentry/src/main/java/io/sentry/UncaughtExceptionHandlerIntegration.java @@ -5,7 +5,7 @@ import io.sentry.exception.ExceptionMechanismException; import io.sentry.hints.DiskFlushNotification; import io.sentry.hints.Flushable; -import io.sentry.hints.Hints; +import io.sentry.hints.Hint; import io.sentry.hints.SessionEnd; import io.sentry.protocol.Mechanism; import io.sentry.util.HintUtils; @@ -90,17 +90,17 @@ public void uncaughtException(Thread thread, Throwable thrown) { options.getLogger().log(SentryLevel.INFO, "Uncaught exception received."); try { - final UncaughtExceptionHint hint = + final UncaughtExceptionHint exceptionHint = new UncaughtExceptionHint(options.getFlushTimeoutMillis(), options.getLogger()); final Throwable throwable = getUnhandledThrowable(thread, thrown); final SentryEvent event = new SentryEvent(throwable); event.setLevel(SentryLevel.FATAL); - final Hints hints = HintUtils.createWithTypeCheckHint(hint); + final Hint hint = HintUtils.createWithTypeCheckHint(exceptionHint); - hub.captureEvent(event, hints); + hub.captureEvent(event, hint); // Block until the event is flushed to disk - if (!hint.waitFlush()) { + if (!exceptionHint.waitFlush()) { options .getLogger() .log( diff --git a/sentry/src/main/java/io/sentry/cache/EnvelopeCache.java b/sentry/src/main/java/io/sentry/cache/EnvelopeCache.java index 87d697ff79..5be26bf8a8 100644 --- a/sentry/src/main/java/io/sentry/cache/EnvelopeCache.java +++ b/sentry/src/main/java/io/sentry/cache/EnvelopeCache.java @@ -15,7 +15,7 @@ import io.sentry.SentryOptions; import io.sentry.Session; import io.sentry.hints.DiskFlushNotification; -import io.sentry.hints.Hints; +import io.sentry.hints.Hint; import io.sentry.hints.SessionEnd; import io.sentry.hints.SessionStart; import io.sentry.transport.NoOpEnvelopeCache; @@ -79,20 +79,20 @@ private EnvelopeCache( } @Override - public void store(final @NotNull SentryEnvelope envelope, final @NotNull Hints hints) { + public void store(final @NotNull SentryEnvelope envelope, final @NotNull Hint hint) { Objects.requireNonNull(envelope, "Envelope is required."); rotateCacheIfNeeded(allEnvelopeFiles()); final File currentSessionFile = getCurrentSessionFile(); - if (HintUtils.hasType(hints, SessionEnd.class)) { + if (HintUtils.hasType(hint, SessionEnd.class)) { if (!currentSessionFile.delete()) { options.getLogger().log(WARNING, "Current envelope doesn't exist."); } } - if (HintUtils.hasType(hints, SessionStart.class)) { + if (HintUtils.hasType(hint, SessionStart.class)) { boolean crashedLastRun = false; // TODO: should we move this to AppLifecycleIntegration? and do on SDK init? but it's too much @@ -200,7 +200,7 @@ public void store(final @NotNull SentryEnvelope envelope, final @NotNull Hints h writeEnvelopeToDisk(envelopeFile, envelope); // write file to the disk when its about to crash so crashedLastRun can be marked on restart - if (HintUtils.hasType(hints, DiskFlushNotification.class)) { + if (HintUtils.hasType(hint, DiskFlushNotification.class)) { writeCrashMarkerFile(); } } diff --git a/sentry/src/main/java/io/sentry/cache/IEnvelopeCache.java b/sentry/src/main/java/io/sentry/cache/IEnvelopeCache.java index 2d499fe49a..9a6e7056cd 100644 --- a/sentry/src/main/java/io/sentry/cache/IEnvelopeCache.java +++ b/sentry/src/main/java/io/sentry/cache/IEnvelopeCache.java @@ -1,15 +1,15 @@ package io.sentry.cache; import io.sentry.SentryEnvelope; -import io.sentry.hints.Hints; +import io.sentry.hints.Hint; import org.jetbrains.annotations.NotNull; public interface IEnvelopeCache extends Iterable { - void store(@NotNull SentryEnvelope envelope, @NotNull Hints hints); + void store(@NotNull SentryEnvelope envelope, @NotNull Hint hint); default void store(@NotNull SentryEnvelope envelope) { - store(envelope, new Hints()); + store(envelope, new Hint()); } void discard(@NotNull SentryEnvelope envelope); diff --git a/sentry/src/main/java/io/sentry/hints/Hints.java b/sentry/src/main/java/io/sentry/hints/Hint.java similarity index 87% rename from sentry/src/main/java/io/sentry/hints/Hints.java rename to sentry/src/main/java/io/sentry/hints/Hint.java index 0475df60cf..1e40302a83 100644 --- a/sentry/src/main/java/io/sentry/hints/Hints.java +++ b/sentry/src/main/java/io/sentry/hints/Hint.java @@ -8,7 +8,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -public final class Hints { +public final class Hint { private static final @NotNull Map> PRIMITIVE_MAPPINGS; @@ -28,16 +28,16 @@ public final class Hints { private final @NotNull List attachments = new ArrayList<>(); private @Nullable Attachment screenshot = null; - public static @NotNull Hints withAttachment(@Nullable Attachment attachment) { - @NotNull final Hints hints = new Hints(); - hints.addAttachment(attachment); - return hints; + public static @NotNull Hint withAttachment(@Nullable Attachment attachment) { + @NotNull final Hint hint = new Hint(); + hint.addAttachment(attachment); + return hint; } - public static @NotNull Hints withAttachments(@Nullable List attachments) { - @NotNull final Hints hints = new Hints(); - hints.addAttachments(attachments); - return hints; + public static @NotNull Hint withAttachments(@Nullable List attachments) { + @NotNull final Hint hint = new Hint(); + hint.addAttachments(attachments); + return hint; } public void set(@NotNull String name, @Nullable Object hint) { diff --git a/sentry/src/main/java/io/sentry/transport/AsyncHttpTransport.java b/sentry/src/main/java/io/sentry/transport/AsyncHttpTransport.java index d6ce0ec8b6..e472cde84a 100644 --- a/sentry/src/main/java/io/sentry/transport/AsyncHttpTransport.java +++ b/sentry/src/main/java/io/sentry/transport/AsyncHttpTransport.java @@ -9,7 +9,7 @@ import io.sentry.clientreport.DiscardReason; import io.sentry.hints.Cached; import io.sentry.hints.DiskFlushNotification; -import io.sentry.hints.Hints; +import io.sentry.hints.Hint; import io.sentry.hints.Retryable; import io.sentry.hints.SubmissionResult; import io.sentry.util.HintUtils; @@ -65,18 +65,18 @@ public AsyncHttpTransport( } @Override - public void send(final @NotNull SentryEnvelope envelope, final @NotNull Hints hints) + public void send(final @NotNull SentryEnvelope envelope, final @NotNull Hint hint) throws IOException { // For now no caching on envelopes IEnvelopeCache currentEnvelopeCache = envelopeCache; boolean cached = false; - if (HintUtils.hasType(hints, Cached.class)) { + if (HintUtils.hasType(hint, Cached.class)) { currentEnvelopeCache = NoOpEnvelopeCache.getInstance(); cached = true; options.getLogger().log(SentryLevel.DEBUG, "Captured Envelope is already cached"); } - final SentryEnvelope filteredEnvelope = rateLimiter.filter(envelope, hints); + final SentryEnvelope filteredEnvelope = rateLimiter.filter(envelope, hint); if (filteredEnvelope == null) { if (cached) { @@ -84,7 +84,7 @@ public void send(final @NotNull SentryEnvelope envelope, final @NotNull Hints hi } } else { SentryEnvelope envelopeThatMayIncludeClientReport; - if (HintUtils.hasType(hints, DiskFlushNotification.class)) { + if (HintUtils.hasType(hint, DiskFlushNotification.class)) { envelopeThatMayIncludeClientReport = options.getClientReportRecorder().attachReportToEnvelope(filteredEnvelope); } else { @@ -93,7 +93,7 @@ public void send(final @NotNull SentryEnvelope envelope, final @NotNull Hints hi final Future future = executor.submit( - new EnvelopeSender(envelopeThatMayIncludeClientReport, hints, currentEnvelopeCache)); + new EnvelopeSender(envelopeThatMayIncludeClientReport, hint, currentEnvelopeCache)); if (future != null && future.isCancelled()) { options @@ -118,11 +118,11 @@ private static QueuedThreadPoolExecutor initExecutor( if (r instanceof EnvelopeSender) { final EnvelopeSender envelopeSender = (EnvelopeSender) r; - if (!HintUtils.hasType(envelopeSender.hints, Cached.class)) { - envelopeCache.store(envelopeSender.envelope, envelopeSender.hints); + if (!HintUtils.hasType(envelopeSender.hint, Cached.class)) { + envelopeCache.store(envelopeSender.envelope, envelopeSender.hint); } - markHintWhenSendingFailed(envelopeSender.hints, true); + markHintWhenSendingFailed(envelopeSender.hint, true); logger.log(SentryLevel.WARNING, "Envelope rejected"); } }; @@ -156,12 +156,12 @@ public void close() throws IOException { /** * It marks the hints when sending has failed, so it's not necessary to wait the timeout * - * @param hints the Hints + * @param hint the Hints * @param retry if event should be retried or not */ - private static void markHintWhenSendingFailed(final @NotNull Hints hints, final boolean retry) { - HintUtils.runIfHasType(hints, SubmissionResult.class, result -> result.setResult(false)); - HintUtils.runIfHasType(hints, Retryable.class, retryable -> retryable.setRetry(retry)); + private static void markHintWhenSendingFailed(final @NotNull Hint hint, final boolean retry) { + HintUtils.runIfHasType(hint, SubmissionResult.class, result -> result.setResult(false)); + HintUtils.runIfHasType(hint, Retryable.class, retryable -> retryable.setRetry(retry)); } private static final class AsyncConnectionThreadFactory implements ThreadFactory { @@ -177,16 +177,16 @@ private static final class AsyncConnectionThreadFactory implements ThreadFactory private final class EnvelopeSender implements Runnable { private final @NotNull SentryEnvelope envelope; - private final @NotNull Hints hints; + private final @NotNull Hint hint; private final @NotNull IEnvelopeCache envelopeCache; private final TransportResult failedResult = TransportResult.error(); EnvelopeSender( final @NotNull SentryEnvelope envelope, - final @NotNull Hints hints, + final @NotNull Hint hint, final @NotNull IEnvelopeCache envelopeCache) { this.envelope = Objects.requireNonNull(envelope, "Envelope is required."); - this.hints = hints; + this.hint = hint; this.envelopeCache = Objects.requireNonNull(envelopeCache, "EnvelopeCache is required."); } @@ -202,7 +202,7 @@ public void run() { } finally { final TransportResult finalResult = result; HintUtils.runIfHasType( - hints, + hint, SubmissionResult.class, (submissionResult) -> { options @@ -219,10 +219,10 @@ public void run() { private @NotNull TransportResult flush() { TransportResult result = this.failedResult; - envelopeCache.store(envelope, hints); + envelopeCache.store(envelope, hint); HintUtils.runIfHasType( - hints, + hint, DiskFlushNotification.class, (diskFlushNotification) -> { diskFlushNotification.markFlushed(); @@ -246,7 +246,7 @@ public void run() { // ignore e.g. 429 as we're not the ones actively dropping if (result.getResponseCode() >= 400 && result.getResponseCode() != 429) { HintUtils.runIfDoesNotHaveType( - hints, + hint, Retryable.class, (hint) -> { options @@ -260,7 +260,7 @@ public void run() { } catch (IOException e) { // Failure due to IO is allowed to retry the event HintUtils.runIfHasType( - hints, + hint, Retryable.class, (retryable) -> { retryable.setRetry(true); @@ -276,7 +276,7 @@ public void run() { } else { // If transportGate is blocking from sending, allowed to retry HintUtils.runIfHasType( - hints, + hint, Retryable.class, (retryable) -> { retryable.setRetry(true); diff --git a/sentry/src/main/java/io/sentry/transport/ITransport.java b/sentry/src/main/java/io/sentry/transport/ITransport.java index 96f3585bf4..d2f755b8f4 100644 --- a/sentry/src/main/java/io/sentry/transport/ITransport.java +++ b/sentry/src/main/java/io/sentry/transport/ITransport.java @@ -1,17 +1,17 @@ package io.sentry.transport; import io.sentry.SentryEnvelope; -import io.sentry.hints.Hints; +import io.sentry.hints.Hint; import java.io.Closeable; import java.io.IOException; import org.jetbrains.annotations.NotNull; /** A transport is in charge of sending the event to the Sentry server. */ public interface ITransport extends Closeable { - void send(@NotNull SentryEnvelope envelope, @NotNull Hints hints) throws IOException; + void send(@NotNull SentryEnvelope envelope, @NotNull Hint hint) throws IOException; default void send(@NotNull SentryEnvelope envelope) throws IOException { - send(envelope, new Hints()); + send(envelope, new Hint()); } /** diff --git a/sentry/src/main/java/io/sentry/transport/NoOpEnvelopeCache.java b/sentry/src/main/java/io/sentry/transport/NoOpEnvelopeCache.java index 5ca1f53d75..7d638f5d6e 100644 --- a/sentry/src/main/java/io/sentry/transport/NoOpEnvelopeCache.java +++ b/sentry/src/main/java/io/sentry/transport/NoOpEnvelopeCache.java @@ -2,7 +2,7 @@ import io.sentry.SentryEnvelope; import io.sentry.cache.IEnvelopeCache; -import io.sentry.hints.Hints; +import io.sentry.hints.Hint; import java.util.ArrayList; import java.util.Iterator; import org.jetbrains.annotations.NotNull; @@ -15,7 +15,7 @@ public static NoOpEnvelopeCache getInstance() { } @Override - public void store(@NotNull SentryEnvelope envelope, @NotNull Hints hints) {} + public void store(@NotNull SentryEnvelope envelope, @NotNull Hint hint) {} @Override public void discard(@NotNull SentryEnvelope envelope) {} diff --git a/sentry/src/main/java/io/sentry/transport/NoOpTransport.java b/sentry/src/main/java/io/sentry/transport/NoOpTransport.java index 04040d8bf3..fce2d7aefe 100644 --- a/sentry/src/main/java/io/sentry/transport/NoOpTransport.java +++ b/sentry/src/main/java/io/sentry/transport/NoOpTransport.java @@ -1,7 +1,7 @@ package io.sentry.transport; import io.sentry.SentryEnvelope; -import io.sentry.hints.Hints; +import io.sentry.hints.Hint; import java.io.IOException; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; @@ -18,7 +18,7 @@ public final class NoOpTransport implements ITransport { private NoOpTransport() {} @Override - public void send(final @NotNull SentryEnvelope envelope, final @NotNull Hints hints) + public void send(final @NotNull SentryEnvelope envelope, final @NotNull Hint hint) throws IOException {} @Override diff --git a/sentry/src/main/java/io/sentry/transport/RateLimiter.java b/sentry/src/main/java/io/sentry/transport/RateLimiter.java index 56cc9253a6..deec4326b3 100644 --- a/sentry/src/main/java/io/sentry/transport/RateLimiter.java +++ b/sentry/src/main/java/io/sentry/transport/RateLimiter.java @@ -9,7 +9,7 @@ import io.sentry.SentryLevel; import io.sentry.SentryOptions; import io.sentry.clientreport.DiscardReason; -import io.sentry.hints.Hints; +import io.sentry.hints.Hint; import io.sentry.hints.Retryable; import io.sentry.hints.SubmissionResult; import io.sentry.util.HintUtils; @@ -44,7 +44,7 @@ public RateLimiter(final @NotNull SentryOptions options) { } public @Nullable SentryEnvelope filter( - final @NotNull SentryEnvelope envelope, final @NotNull Hints hints) { + final @NotNull SentryEnvelope envelope, final @NotNull Hint hint) { // Optimize for/No allocations if no items are under 429 List dropItems = null; for (SentryEnvelopeItem item : envelope.getItems()) { @@ -78,7 +78,7 @@ public RateLimiter(final @NotNull SentryOptions options) { if (toSend.isEmpty()) { options.getLogger().log(SentryLevel.INFO, "Envelope discarded due all items rate limited."); - markHintWhenSendingFailed(hints, false); + markHintWhenSendingFailed(hint, false); return null; } @@ -88,14 +88,14 @@ public RateLimiter(final @NotNull SentryOptions options) { } /** - * It marks the hints when sending has failed, so it's not necessary to wait the timeout + * It marks the hint when sending has failed, so it's not necessary to wait the timeout * - * @param hints the Hints + * @param hint the Hints * @param retry if event should be retried or not */ - private static void markHintWhenSendingFailed(final @NotNull Hints hints, final boolean retry) { - HintUtils.runIfHasType(hints, SubmissionResult.class, result -> result.setResult(false)); - HintUtils.runIfHasType(hints, Retryable.class, retryable -> retryable.setRetry(retry)); + private static void markHintWhenSendingFailed(final @NotNull Hint hint, final boolean retry) { + HintUtils.runIfHasType(hint, SubmissionResult.class, result -> result.setResult(false)); + HintUtils.runIfHasType(hint, Retryable.class, retryable -> retryable.setRetry(retry)); } /** diff --git a/sentry/src/main/java/io/sentry/transport/StdoutTransport.java b/sentry/src/main/java/io/sentry/transport/StdoutTransport.java index 676360ce54..1f035e0e34 100644 --- a/sentry/src/main/java/io/sentry/transport/StdoutTransport.java +++ b/sentry/src/main/java/io/sentry/transport/StdoutTransport.java @@ -2,7 +2,7 @@ import io.sentry.ISerializer; import io.sentry.SentryEnvelope; -import io.sentry.hints.Hints; +import io.sentry.hints.Hint; import io.sentry.util.Objects; import java.io.IOException; import org.jetbrains.annotations.NotNull; @@ -16,7 +16,7 @@ public StdoutTransport(final @NotNull ISerializer serializer) { } @Override - public void send(final @NotNull SentryEnvelope envelope, final @NotNull Hints hints) + public void send(final @NotNull SentryEnvelope envelope, final @NotNull Hint hint) throws IOException { Objects.requireNonNull(envelope, "SentryEnvelope is required"); diff --git a/sentry/src/main/java/io/sentry/util/HintUtils.java b/sentry/src/main/java/io/sentry/util/HintUtils.java index 78e802076a..e43aafac35 100644 --- a/sentry/src/main/java/io/sentry/util/HintUtils.java +++ b/sentry/src/main/java/io/sentry/util/HintUtils.java @@ -5,63 +5,63 @@ import io.sentry.ILogger; import io.sentry.hints.ApplyScopeData; import io.sentry.hints.Cached; -import io.sentry.hints.Hints; +import io.sentry.hints.Hint; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -/** Util class dealing with Hints as not to pollute the Hints API with internal functionality */ +/** Util class dealing with Hint as not to pollute the Hint API with internal functionality */ @ApiStatus.Internal public final class HintUtils { private HintUtils() {} @ApiStatus.Internal - public static Hints createWithTypeCheckHint(Object hint) { - Hints hints = new Hints(); - setTypeCheckHint(hints, hint); - return hints; + public static Hint createWithTypeCheckHint(Object typeCheckHint) { + Hint hint = new Hint(); + setTypeCheckHint(hint, typeCheckHint); + return hint; } @ApiStatus.Internal - public static void setTypeCheckHint(@NotNull Hints hints, Object hint) { - hints.set(SENTRY_TYPE_CHECK_HINT, hint); + public static void setTypeCheckHint(@NotNull Hint hint, Object typeCheckHint) { + hint.set(SENTRY_TYPE_CHECK_HINT, typeCheckHint); } @ApiStatus.Internal - public static @Nullable Object getSentrySdkHint(@NotNull Hints hints) { - return hints.get(SENTRY_TYPE_CHECK_HINT); + public static @Nullable Object getSentrySdkHint(@NotNull Hint hint) { + return hint.get(SENTRY_TYPE_CHECK_HINT); } @ApiStatus.Internal - public static boolean hasType(@NotNull Hints hints, @NotNull Class clazz) { - final Object sentrySdkHint = getSentrySdkHint(hints); + public static boolean hasType(@NotNull Hint hint, @NotNull Class clazz) { + final Object sentrySdkHint = getSentrySdkHint(hint); return clazz.isInstance(sentrySdkHint); } @ApiStatus.Internal public static void runIfDoesNotHaveType( - @NotNull Hints hints, @NotNull Class clazz, SentryNullableConsumer lambda) { + @NotNull Hint hint, @NotNull Class clazz, SentryNullableConsumer lambda) { runIfHasType( - hints, + hint, clazz, (ignored) -> {}, - (hint, clazz2) -> { - lambda.accept(hint); + (value, clazz2) -> { + lambda.accept(value); }); } @ApiStatus.Internal public static void runIfHasType( - @NotNull Hints hints, @NotNull Class clazz, SentryConsumer lambda) { - runIfHasType(hints, clazz, lambda, (hint, clazz2) -> {}); + @NotNull Hint hint, @NotNull Class clazz, SentryConsumer lambda) { + runIfHasType(hint, clazz, lambda, (value, clazz2) -> {}); } @ApiStatus.Internal public static void runIfHasTypeLogIfNot( - @NotNull Hints hints, @NotNull Class clazz, ILogger logger, SentryConsumer lambda) { + @NotNull Hint hint, @NotNull Class clazz, ILogger logger, SentryConsumer lambda) { runIfHasType( - hints, + hint, clazz, lambda, (sentrySdkHint, expectedClass) -> { @@ -72,12 +72,12 @@ public static void runIfHasTypeLogIfNot( @SuppressWarnings("unchecked") @ApiStatus.Internal public static void runIfHasType( - @NotNull Hints hints, + @NotNull Hint hint, @NotNull Class clazz, SentryConsumer lambda, SentryFallbackConsumer fallbackLambda) { - Object sentrySdkHint = getSentrySdkHint(hints); - if (hasType(hints, clazz) && sentrySdkHint != null) { + Object sentrySdkHint = getSentrySdkHint(hint); + if (hasType(hint, clazz) && sentrySdkHint != null) { lambda.accept((T) sentrySdkHint); } else { fallbackLambda.accept(sentrySdkHint, clazz); @@ -91,8 +91,8 @@ public static void runIfHasType( * @return true if it should apply scope's data or false otherwise */ @ApiStatus.Internal - public static boolean shouldApplyScopeData(@NotNull Hints hints) { - return !hasType(hints, Cached.class) || hasType(hints, ApplyScopeData.class); + public static boolean shouldApplyScopeData(@NotNull Hint hint) { + return !hasType(hint, Cached.class) || hasType(hint, ApplyScopeData.class); } @FunctionalInterface diff --git a/sentry/src/test/java/io/sentry/CustomEventProcessor.kt b/sentry/src/test/java/io/sentry/CustomEventProcessor.kt index b18ef86fcf..a6ed0afc07 100644 --- a/sentry/src/test/java/io/sentry/CustomEventProcessor.kt +++ b/sentry/src/test/java/io/sentry/CustomEventProcessor.kt @@ -1,7 +1,7 @@ package io.sentry -import io.sentry.hints.Hints +import io.sentry.hints.Hint class CustomEventProcessor : EventProcessor { - override fun process(event: SentryEvent, hints: Hints): SentryEvent? = null + override fun process(event: SentryEvent, hint: Hint): SentryEvent? = null } diff --git a/sentry/src/test/java/io/sentry/DuplicateEventDetectionEventProcessorTest.kt b/sentry/src/test/java/io/sentry/DuplicateEventDetectionEventProcessorTest.kt index 5047983bac..e8fb213a5f 100644 --- a/sentry/src/test/java/io/sentry/DuplicateEventDetectionEventProcessorTest.kt +++ b/sentry/src/test/java/io/sentry/DuplicateEventDetectionEventProcessorTest.kt @@ -1,7 +1,7 @@ package io.sentry import io.sentry.exception.ExceptionMechanismException -import io.sentry.hints.Hints +import io.sentry.hints.Hint import io.sentry.protocol.Mechanism import java.lang.RuntimeException import kotlin.test.Test @@ -26,9 +26,12 @@ class DuplicateEventDetectionEventProcessorTest { @Test fun `does not drop event if no previous event with same exception was processed`() { val processor = fixture.getSut() - processor.process(SentryEvent(), Hints()) + processor.process(SentryEvent(), Hint()) - val result = processor.process(SentryEvent(RuntimeException()), Hints()) + val result = processor.process( + SentryEvent(RuntimeException()), + Hint() + ) assertNotNull(result) } @@ -37,9 +40,9 @@ class DuplicateEventDetectionEventProcessorTest { fun `drops event with the same exception`() { val processor = fixture.getSut() val event = SentryEvent(RuntimeException()) - processor.process(event, Hints()) + processor.process(event, Hint()) - val result = processor.process(event, Hints()) + val result = processor.process(event, Hint()) assertNull(result) } @@ -47,9 +50,12 @@ class DuplicateEventDetectionEventProcessorTest { fun `drops event with mechanism exception having an exception that has already been processed`() { val processor = fixture.getSut() val event = SentryEvent(RuntimeException()) - processor.process(event, Hints()) + processor.process(event, Hint()) - val result = processor.process(SentryEvent(ExceptionMechanismException(Mechanism(), event.throwable!!, Thread.currentThread())), Hints()) + val result = processor.process( + SentryEvent(ExceptionMechanismException(Mechanism(), event.throwable!!, Thread.currentThread())), + Hint() + ) assertNull(result) } @@ -57,9 +63,12 @@ class DuplicateEventDetectionEventProcessorTest { fun `drops event with exception that has already been processed with event with mechanism exception`() { val processor = fixture.getSut() val sentryEvent = SentryEvent(ExceptionMechanismException(Mechanism(), RuntimeException(), Thread.currentThread())) - processor.process(sentryEvent, Hints()) + processor.process(sentryEvent, Hint()) - val result = processor.process(SentryEvent((sentryEvent.throwable as ExceptionMechanismException).throwable), Hints()) + val result = processor.process( + SentryEvent((sentryEvent.throwable as ExceptionMechanismException).throwable), + Hint() + ) assertNull(result) } @@ -68,9 +77,12 @@ class DuplicateEventDetectionEventProcessorTest { fun `drops event with the cause equal to exception in already processed event`() { val processor = fixture.getSut() val event = SentryEvent(RuntimeException()) - processor.process(event, Hints()) + processor.process(event, Hint()) - val result = processor.process(SentryEvent(RuntimeException(event.throwable)), Hints()) + val result = processor.process( + SentryEvent(RuntimeException(event.throwable)), + Hint() + ) assertNull(result) } @@ -79,9 +91,12 @@ class DuplicateEventDetectionEventProcessorTest { fun `drops event with any of the causes has been already processed`() { val processor = fixture.getSut() val event = SentryEvent(RuntimeException()) - processor.process(event, Hints()) + processor.process(event, Hint()) - val result = processor.process(SentryEvent(RuntimeException(RuntimeException(event.throwable))), Hints()) + val result = processor.process( + SentryEvent(RuntimeException(RuntimeException(event.throwable))), + Hint() + ) assertNull(result) } @@ -90,7 +105,7 @@ class DuplicateEventDetectionEventProcessorTest { fun `does not deduplicate is deduplication is disabled`() { val processor = fixture.getSut(enableDeduplication = false) val event = SentryEvent(RuntimeException()) - assertNotNull(processor.process(event, Hints())) - assertNotNull(processor.process(event, Hints())) + assertNotNull(processor.process(event, Hint())) + assertNotNull(processor.process(event, Hint())) } } diff --git a/sentry/src/test/java/io/sentry/EnvelopeSenderTest.kt b/sentry/src/test/java/io/sentry/EnvelopeSenderTest.kt index 91254d2447..d141a0afec 100644 --- a/sentry/src/test/java/io/sentry/EnvelopeSenderTest.kt +++ b/sentry/src/test/java/io/sentry/EnvelopeSenderTest.kt @@ -8,7 +8,7 @@ import com.nhaarman.mockitokotlin2.verify import com.nhaarman.mockitokotlin2.verifyNoMoreInteractions import com.nhaarman.mockitokotlin2.whenever import io.sentry.cache.EnvelopeCache -import io.sentry.hints.Hints +import io.sentry.hints.Hint import io.sentry.hints.Retryable import io.sentry.util.HintUtils import io.sentry.util.noFlushTimeout @@ -112,7 +112,7 @@ class EnvelopeSenderTest { val sut = fixture.getSut() val testFile = File(Files.createTempFile(tempDirectory, "send-cached-event-test", EnvelopeCache.SUFFIX_ENVELOPE_FILE).toUri()) testFile.deleteOnExit() - sut.processFile(testFile, Hints()) + sut.processFile(testFile, Hint()) verify(fixture.logger)!!.log(eq(SentryLevel.ERROR), eq(expected), eq("Failed to capture cached envelope %s"), eq(testFile.absolutePath)) verifyNoMoreInteractions(fixture.hub) } diff --git a/sentry/src/test/java/io/sentry/HubTest.kt b/sentry/src/test/java/io/sentry/HubTest.kt index eb1a31cd9e..c3b8e7c228 100644 --- a/sentry/src/test/java/io/sentry/HubTest.kt +++ b/sentry/src/test/java/io/sentry/HubTest.kt @@ -18,7 +18,7 @@ import io.sentry.cache.EnvelopeCache import io.sentry.clientreport.ClientReportTestHelper.Companion.assertClientReport import io.sentry.clientreport.DiscardReason import io.sentry.clientreport.DiscardedEvent -import io.sentry.hints.Hints +import io.sentry.hints.Hint import io.sentry.hints.SessionEndHint import io.sentry.hints.SessionStartHint import io.sentry.protocol.SentryId @@ -265,7 +265,7 @@ class HubTest { sut.close() sut.captureEvent(SentryEvent()) - verify(mockClient, never()).captureEvent(any(), any()) + verify(mockClient, never()).captureEvent(any(), any()) } @Test diff --git a/sentry/src/test/java/io/sentry/MainEventProcessorTest.kt b/sentry/src/test/java/io/sentry/MainEventProcessorTest.kt index cd20824588..970eb936d6 100644 --- a/sentry/src/test/java/io/sentry/MainEventProcessorTest.kt +++ b/sentry/src/test/java/io/sentry/MainEventProcessorTest.kt @@ -6,7 +6,7 @@ import com.nhaarman.mockitokotlin2.times import com.nhaarman.mockitokotlin2.verify import com.nhaarman.mockitokotlin2.whenever import io.sentry.hints.ApplyScopeData -import io.sentry.hints.Hints +import io.sentry.hints.Hint import io.sentry.protocol.DebugMeta import io.sentry.protocol.SdkVersion import io.sentry.protocol.SentryTransaction @@ -65,7 +65,7 @@ class MainEventProcessorTest { val crashedThread = Thread.currentThread() var event = generateCrashedEvent(crashedThread) - event = sut.process(event, Hints()) + event = sut.process(event, Hint()) assertNotNull(event.exceptions) { assertSame(crashedThread.id, it.first().threadId) @@ -86,7 +86,7 @@ class MainEventProcessorTest { val crashedThread = Thread() var event = generateCrashedEvent(crashedThread) - event = sut.process(event, Hints()) + event = sut.process(event, Hint()) assertNotNull(event.threads) { threads -> assertTrue(threads.any { it.isCrashed == true }) @@ -98,7 +98,7 @@ class MainEventProcessorTest { val sut = fixture.getSut() val crashedThread = Thread.currentThread() var event = generateCrashedEvent(crashedThread) - event = sut.process(event, Hints()) + event = sut.process(event, Hint()) assertEquals("release", event.release) assertEquals("environment", event.environment) @@ -135,7 +135,7 @@ class MainEventProcessorTest { event.release = "eventRelease" event.serverName = "eventServerName" - event = sut.process(event, Hints()) + event = sut.process(event, Hint()) assertEquals("eventRelease", event.release) assertEquals("eventEnvironment", event.environment) @@ -182,7 +182,7 @@ class MainEventProcessorTest { val sut = fixture.getSut(attachThreads = false, attachStackTrace = false) var event = SentryEvent() - event = sut.process(event, Hints()) + event = sut.process(event, Hint()) assertNull(event.threads) } @@ -192,7 +192,7 @@ class MainEventProcessorTest { val sut = fixture.getSut() var event = SentryEvent() - event = sut.process(event, Hints()) + event = sut.process(event, Hint()) assertNotNull(event.threads) } @@ -202,7 +202,7 @@ class MainEventProcessorTest { val sut = fixture.getSut(attachThreads = false, attachStackTrace = true) var event = SentryEvent() - event = sut.process(event, Hints()) + event = sut.process(event, Hint()) assertNotNull(event.threads) { assertEquals(1, it.count()) @@ -214,7 +214,7 @@ class MainEventProcessorTest { val sut = fixture.getSut(attachThreads = false, attachStackTrace = true) var event = SentryEvent(RuntimeException("error")) - event = sut.process(event, Hints()) + event = sut.process(event, Hint()) assertNull(event.threads) } @@ -223,7 +223,7 @@ class MainEventProcessorTest { fun `sets sdkVersion in the event`() { val sut = fixture.getSut() val event = SentryEvent() - sut.process(event, Hints()) + sut.process(event, Hint()) assertNotNull(event.sdk) { assertEquals(it.name, "test") assertEquals(it.version, "1.2.3") @@ -234,7 +234,7 @@ class MainEventProcessorTest { fun `when event and SentryOptions do not have environment set, sets production as environment`() { val sut = fixture.getSut(environment = null) val event = SentryEvent() - sut.process(event, Hints()) + sut.process(event, Hint()) assertEquals("production", event.environment) } @@ -242,7 +242,7 @@ class MainEventProcessorTest { fun `when event does not have ip address set and sendDefaultPii is set to true, sets {{auto}} as the ip address`() { val sut = fixture.getSut(sendDefaultPii = true) val event = SentryEvent() - sut.process(event, Hints()) + sut.process(event, Hint()) assertNotNull(event.user) { assertEquals("{{auto}}", it.ipAddress) } @@ -255,7 +255,7 @@ class MainEventProcessorTest { event.user = User().apply { ipAddress = "192.168.0.1" } - sut.process(event, Hints()) + sut.process(event, Hint()) assertNotNull(event.user) { assertEquals("192.168.0.1", it.ipAddress) } @@ -266,7 +266,7 @@ class MainEventProcessorTest { val sut = fixture.getSut(sendDefaultPii = false) val event = SentryEvent() event.user = User() - sut.process(event, Hints()) + sut.process(event, Hint()) assertNotNull(event.user) { assertNull(it.ipAddress) } @@ -277,7 +277,7 @@ class MainEventProcessorTest { val sut = fixture.getSut(environment = null) val event = SentryEvent() event.environment = "staging" - sut.process(event, Hints()) + sut.process(event, Hint()) assertEquals("staging", event.environment) } @@ -285,7 +285,7 @@ class MainEventProcessorTest { fun `when event does not have environment set and SentryOptions have environment set, uses environment from SentryOptions`() { val sut = fixture.getSut(environment = "custom") val event = SentryEvent() - sut.process(event, Hints()) + sut.process(event, Hint()) assertEquals("custom", event.environment) } @@ -293,7 +293,7 @@ class MainEventProcessorTest { fun `sets tags from SentryOptions`() { val sut = fixture.getSut(tags = mapOf("tag1" to "value1", "tag2" to "value2")) val event = SentryEvent() - sut.process(event, Hints()) + sut.process(event, Hint()) assertNotNull(event.tags) { assertEquals("value1", it["tag1"]) assertEquals("value2", it["tag2"]) @@ -305,7 +305,7 @@ class MainEventProcessorTest { val sut = fixture.getSut(tags = mapOf("tag1" to "value1", "tag2" to "value2")) val event = SentryEvent() event.setTag("tag2", "event-tag-value") - sut.process(event, Hints()) + sut.process(event, Hint()) assertNotNull(event.tags) { assertEquals("value1", it["tag1"]) assertEquals("event-tag-value", it["tag2"]) @@ -316,7 +316,7 @@ class MainEventProcessorTest { fun `sets servername retrieved from the local address`() { val processor = fixture.getSut(serverName = null, host = "aHost") val event = SentryEvent() - processor.process(event, Hints()) + processor.process(event, Hint()) assertEquals("aHost", event.serverName) } @@ -324,7 +324,7 @@ class MainEventProcessorTest { fun `sets servername to null if retrieving takes longer time`() { val processor = fixture.getSut(serverName = null, host = "aHost", resolveHostDelay = 2000) val event = SentryEvent() - processor.process(event, Hints()) + processor.process(event, Hint()) assertNull(event.serverName) } @@ -332,10 +332,10 @@ class MainEventProcessorTest { fun `uses cache to retrieve servername for subsequent events`() { val processor = fixture.getSut(serverName = null, host = "aHost", hostnameCacheDuration = 1000) val firstEvent = SentryEvent() - processor.process(firstEvent, Hints()) + processor.process(firstEvent, Hint()) assertEquals("aHost", firstEvent.serverName) val secondEvent = SentryEvent() - processor.process(secondEvent, Hints()) + processor.process(secondEvent, Hint()) assertEquals("aHost", secondEvent.serverName) verify(fixture.getLocalhost, times(1)).canonicalHostName } @@ -344,7 +344,7 @@ class MainEventProcessorTest { fun `when cache expires, retrieves new host name from the local address`() { val processor = fixture.getSut(serverName = null, host = "aHost") val firstEvent = SentryEvent() - processor.process(firstEvent, Hints()) + processor.process(firstEvent, Hint()) assertEquals("aHost", firstEvent.serverName) reset(fixture.getLocalhost) @@ -352,7 +352,7 @@ class MainEventProcessorTest { await.untilAsserted { val secondEvent = SentryEvent() - processor.process(secondEvent, Hints()) + processor.process(secondEvent, Hint()) assertEquals("newHost", secondEvent.serverName) } } @@ -362,7 +362,7 @@ class MainEventProcessorTest { val processor = fixture.getSut(serverName = null, host = "aHost") val event = SentryEvent() event.serverName = "eventHost" - processor.process(event, Hints()) + processor.process(event, Hint()) assertEquals("eventHost", event.serverName) } @@ -370,7 +370,7 @@ class MainEventProcessorTest { fun `does not set serverName on events if serverName is set on SentryOptions`() { val processor = fixture.getSut(serverName = "optionsHost", host = "aHost") val event = SentryEvent() - processor.process(event, Hints()) + processor.process(event, Hint()) assertEquals("optionsHost", event.serverName) } @@ -379,7 +379,7 @@ class MainEventProcessorTest { val processor = fixture.getSut(serverName = "optionsHost") var transaction = SentryTransaction(fixture.sentryTracer) - transaction = processor.process(transaction, Hints()) + transaction = processor.process(transaction, Hint()) assertEquals("optionsHost", transaction.serverName) } @@ -389,7 +389,7 @@ class MainEventProcessorTest { val processor = fixture.getSut() var transaction = SentryTransaction(fixture.sentryTracer) - transaction = processor.process(transaction, Hints()) + transaction = processor.process(transaction, Hint()) assertEquals("dist", transaction.dist) } @@ -399,7 +399,7 @@ class MainEventProcessorTest { val processor = fixture.getSut(sendDefaultPii = true) var transaction = SentryTransaction(fixture.sentryTracer) - transaction = processor.process(transaction, Hints()) + transaction = processor.process(transaction, Hint()) assertNotNull(transaction.user) } @@ -421,7 +421,7 @@ class MainEventProcessorTest { val sut = fixture.getSut(proguardUuid = "id1") var event = SentryEvent() - event = sut.process(event, Hints()) + event = sut.process(event, Hint()) assertNotNull(event.debugMeta) { assertNotNull(it.images) { images -> @@ -437,7 +437,7 @@ class MainEventProcessorTest { var event = SentryEvent() event.debugMeta = DebugMeta() - event = sut.process(event, Hints()) + event = sut.process(event, Hint()) assertNotNull(event.debugMeta) { assertNotNull(it.images) { images -> diff --git a/sentry/src/test/java/io/sentry/NoOpHubTest.kt b/sentry/src/test/java/io/sentry/NoOpHubTest.kt index 5f6e2ad749..0c9c904e16 100644 --- a/sentry/src/test/java/io/sentry/NoOpHubTest.kt +++ b/sentry/src/test/java/io/sentry/NoOpHubTest.kt @@ -1,7 +1,7 @@ package io.sentry import com.nhaarman.mockitokotlin2.mock -import io.sentry.hints.Hints +import io.sentry.hints.Hint import io.sentry.protocol.SentryId import kotlin.test.Test import kotlin.test.assertEquals @@ -30,7 +30,7 @@ class NoOpHubTest { @Test fun `captureTransaction returns empty SentryId`() = - assertEquals(SentryId.EMPTY_ID, sut.captureTransaction(mock(), mock())) + assertEquals(SentryId.EMPTY_ID, sut.captureTransaction(mock(), mock())) @Test fun `captureException returns empty SentryId`() = diff --git a/sentry/src/test/java/io/sentry/ScopeTest.kt b/sentry/src/test/java/io/sentry/ScopeTest.kt index 3e67d0fb36..bb1fb37b4f 100644 --- a/sentry/src/test/java/io/sentry/ScopeTest.kt +++ b/sentry/src/test/java/io/sentry/ScopeTest.kt @@ -5,7 +5,7 @@ import com.nhaarman.mockitokotlin2.eq import com.nhaarman.mockitokotlin2.mock import com.nhaarman.mockitokotlin2.never import com.nhaarman.mockitokotlin2.verify -import io.sentry.hints.Hints +import io.sentry.hints.Hint import io.sentry.protocol.Request import io.sentry.protocol.User import io.sentry.test.callMethod @@ -859,7 +859,7 @@ class ScopeTest { private fun eventProcessor(): EventProcessor { return object : EventProcessor { - override fun process(event: SentryEvent, hints: Hints): SentryEvent? { + override fun process(event: SentryEvent, hint: Hint): SentryEvent? { return event } } diff --git a/sentry/src/test/java/io/sentry/SentryClientTest.kt b/sentry/src/test/java/io/sentry/SentryClientTest.kt index b3672b04c1..26d9fd41c1 100644 --- a/sentry/src/test/java/io/sentry/SentryClientTest.kt +++ b/sentry/src/test/java/io/sentry/SentryClientTest.kt @@ -22,7 +22,7 @@ import io.sentry.exception.SentryEnvelopeException import io.sentry.hints.ApplyScopeData import io.sentry.hints.Cached import io.sentry.hints.DiskFlushNotification -import io.sentry.hints.Hints +import io.sentry.hints.Hint import io.sentry.protocol.Mechanism import io.sentry.protocol.Request import io.sentry.protocol.SdkVersion @@ -788,7 +788,7 @@ class SentryClientTest { val event = SentryEvent().apply { exceptions = createNonHandledException() } - fixture.getSut().updateSessionData(event, Hints(), scope) + fixture.getSut().updateSessionData(event, Hint(), scope) scope.withSession { assertEquals(Session.State.Crashed, it!!.status) } @@ -802,7 +802,10 @@ class SentryClientTest { val session = it.current val level = session.status val event = SentryEvent() - fixture.getSut().updateSessionData(event, Hints(), scope) + fixture.getSut().updateSessionData( + event, + Hint(), scope + ) assertEquals(level, session.status) } } @@ -814,7 +817,7 @@ class SentryClientTest { val event = SentryEvent().apply { exceptions = createNonHandledException() } - fixture.getSut().updateSessionData(event, Hints(), scope) + fixture.getSut().updateSessionData(event, Hint(), scope) scope.withSession { assertEquals(1, it!!.errorCount()) } @@ -829,7 +832,7 @@ class SentryClientTest { val event = SentryEvent().apply { setExceptions(exceptions) } - fixture.getSut().updateSessionData(event, Hints(), scope) + fixture.getSut().updateSessionData(event, Hint(), scope) scope.withSession { assertEquals(1, it!!.errorCount()) } @@ -843,7 +846,10 @@ class SentryClientTest { val session = it.current val errorCount = session.errorCount() val event = SentryEvent() - fixture.getSut().updateSessionData(event, Hints(), scope) + fixture.getSut().updateSessionData( + event, + Hint(), scope + ) assertEquals(errorCount, session.errorCount()) } } @@ -858,7 +864,10 @@ class SentryClientTest { headers = mutableMapOf("user-agent" to "jamesBond") } } - fixture.getSut().updateSessionData(event, Hints(), scope) + fixture.getSut().updateSessionData( + event, + Hint(), scope + ) scope.withSession { assertEquals("jamesBond", it!!.userAgent) } @@ -877,7 +886,10 @@ class SentryClientTest { headers = mutableMapOf() } } - fixture.getSut().updateSessionData(event, Hints(), scope) + fixture.getSut().updateSessionData( + event, + Hint(), scope + ) assertEquals(userAgent, session.userAgent) } } @@ -886,7 +898,7 @@ class SentryClientTest { fun `When capture an event and there's no session, do nothing`() { val scope = Scope(fixture.sentryOptions) val event = SentryEvent() - fixture.getSut().updateSessionData(event, Hints(), scope) + fixture.getSut().updateSessionData(event, Hint(), scope) scope.withSession { assertNull(it) } @@ -1283,9 +1295,9 @@ class SentryClientTest { fun `screenshot is added to the envelope from the hint`() { val sut = fixture.getSut() val attachment = Attachment.fromScreenshot(byteArrayOf()) - val hints = Hints().also { it.screenshot = attachment } + val hint = Hint().also { it.screenshot = attachment } - sut.captureEvent(SentryEvent(), hints) + sut.captureEvent(SentryEvent(), hint) verify(fixture.transport).send( check { envelope -> @@ -1303,9 +1315,9 @@ class SentryClientTest { fixture.sentryOptions.beforeSend = CustomBeforeSendCallback() val sut = fixture.getSut() val attachment = Attachment.fromScreenshot(byteArrayOf()) - val hints = Hints().also { it.screenshot = attachment } + val hint = Hint().also { it.screenshot = attachment } - sut.captureEvent(SentryEvent(), hints) + sut.captureEvent(SentryEvent(), hint) verify(fixture.transport).send( check { envelope -> @@ -1597,7 +1609,7 @@ class SentryClientTest { fun `can pass an attachment via hints`() { val sut = fixture.getSut() - sut.captureException(IllegalStateException(), Hints.withAttachment(fixture.attachment)) + sut.captureException(IllegalStateException(), Hint.withAttachment(fixture.attachment)) thenEnvelopeIsSentWith(eventCount = 1, sessionCount = 0, attachmentCount = 1) } @@ -1608,7 +1620,7 @@ class SentryClientTest { val scope = givenScopeWithStartedSession() scope.addAttachment(fixture.attachment2) - sut.captureException(IllegalStateException(), scope, Hints.withAttachment(fixture.attachment)) + sut.captureException(IllegalStateException(), scope, Hint.withAttachment(fixture.attachment)) thenEnvelopeIsSentWith(eventCount = 1, sessionCount = 1, attachmentCount = 2) } @@ -1625,7 +1637,7 @@ class SentryClientTest { val scope = givenScopeWithStartedSession() scope.addAttachment(fixture.attachment2) - sut.captureException(IllegalStateException(), scope, Hints.withAttachment(fixture.attachment)) + sut.captureException(IllegalStateException(), scope, Hint.withAttachment(fixture.attachment)) thenEnvelopeIsSentWith(eventCount = 1, sessionCount = 1, attachmentCount = 3) } @@ -1641,7 +1653,7 @@ class SentryClientTest { val scope = givenScopeWithStartedSession() scope.addAttachment(fixture.attachment2) - sut.captureException(IllegalStateException(), scope, Hints.withAttachment(fixture.attachment)) + sut.captureException(IllegalStateException(), scope, Hint.withAttachment(fixture.attachment)) thenEnvelopeIsSentWith(eventCount = 1, sessionCount = 1, attachmentCount = 1) } @@ -1650,15 +1662,15 @@ class SentryClientTest { fun `can add to attachments in eventProcessor`() { val sut = fixture.getSut { options -> options.addEventProcessor(object : EventProcessor { - override fun process(event: SentryEvent, hints: Hints): SentryEvent? { - assertEquals(listOf(fixture.attachment, fixture.attachment2), hints.attachments) - hints.addAttachment(fixture.attachment3) + override fun process(event: SentryEvent, hint: Hint): SentryEvent? { + assertEquals(listOf(fixture.attachment, fixture.attachment2), hint.attachments) + hint.addAttachment(fixture.attachment3) return event } override fun process( transaction: SentryTransaction, - hints: Hints + hint: Hint ): SentryTransaction? { return transaction } @@ -1667,7 +1679,7 @@ class SentryClientTest { val scope = givenScopeWithStartedSession() scope.addAttachment(fixture.attachment2) - sut.captureException(IllegalStateException(), scope, Hints.withAttachment(fixture.attachment)) + sut.captureException(IllegalStateException(), scope, Hint.withAttachment(fixture.attachment)) thenEnvelopeIsSentWith(eventCount = 1, sessionCount = 1, attachmentCount = 3) } @@ -1676,14 +1688,14 @@ class SentryClientTest { fun `can replace attachments in eventProcessor`() { val sut = fixture.getSut { options -> options.addEventProcessor(object : EventProcessor { - override fun process(event: SentryEvent, hints: Hints): SentryEvent? { - hints.replaceAttachments(listOf(fixture.attachment)) + override fun process(event: SentryEvent, hint: Hint): SentryEvent? { + hint.replaceAttachments(listOf(fixture.attachment)) return event } override fun process( transaction: SentryTransaction, - hints: Hints + hint: Hint ): SentryTransaction? { return transaction } @@ -1692,7 +1704,7 @@ class SentryClientTest { val scope = givenScopeWithStartedSession() scope.addAttachment(fixture.attachment2) - sut.captureException(IllegalStateException(), scope, Hints.withAttachment(fixture.attachment)) + sut.captureException(IllegalStateException(), scope, Hint.withAttachment(fixture.attachment)) thenEnvelopeIsSentWith(eventCount = 1, sessionCount = 1, attachmentCount = 1) } @@ -1705,7 +1717,7 @@ class SentryClientTest { sut.captureTransaction( SentryTransaction(fixture.sentryTracer), scope, - Hints.withAttachment(fixture.attachment) + Hint.withAttachment(fixture.attachment) ) thenEnvelopeIsSentWith(eventCount = 0, sessionCount = 0, attachmentCount = 1, transactionCount = 1) @@ -1721,7 +1733,7 @@ class SentryClientTest { sut.captureTransaction( SentryTransaction(fixture.sentryTracer), scope, - Hints.withAttachment(fixture.attachment) + Hint.withAttachment(fixture.attachment) ) thenEnvelopeIsSentWith(eventCount = 0, sessionCount = 0, attachmentCount = 2, transactionCount = 1) @@ -1731,16 +1743,16 @@ class SentryClientTest { fun `can add to attachments in eventProcessor for transactions`() { val sut = fixture.getSut { options -> options.addEventProcessor(object : EventProcessor { - override fun process(event: SentryEvent, hints: Hints): SentryEvent? { + override fun process(event: SentryEvent, hint: Hint): SentryEvent? { return event } override fun process( transaction: SentryTransaction, - hints: Hints + hint: Hint ): SentryTransaction? { - assertEquals(listOf(fixture.attachment, fixture.attachment2), hints.attachments) - hints.addAttachment(fixture.attachment3) + assertEquals(listOf(fixture.attachment, fixture.attachment2), hint.attachments) + hint.addAttachment(fixture.attachment3) return transaction } }) @@ -1752,7 +1764,7 @@ class SentryClientTest { sut.captureTransaction( SentryTransaction(fixture.sentryTracer), scope, - Hints.withAttachment(fixture.attachment) + Hint.withAttachment(fixture.attachment) ) thenEnvelopeIsSentWith(eventCount = 0, sessionCount = 0, attachmentCount = 3, transactionCount = 1) @@ -1762,15 +1774,15 @@ class SentryClientTest { fun `can replace attachments in eventProcessor for transactions`() { val sut = fixture.getSut { options -> options.addEventProcessor(object : EventProcessor { - override fun process(event: SentryEvent, hints: Hints): SentryEvent? { + override fun process(event: SentryEvent, hint: Hint): SentryEvent? { return event } override fun process( transaction: SentryTransaction, - hints: Hints + hint: Hint ): SentryTransaction? { - hints.replaceAttachments(listOf(fixture.attachment)) + hint.replaceAttachments(listOf(fixture.attachment)) return transaction } }) @@ -1782,7 +1794,7 @@ class SentryClientTest { sut.captureTransaction( SentryTransaction(fixture.sentryTracer), scope, - Hints.withAttachment(fixture.attachment) + Hint.withAttachment(fixture.attachment) ) thenEnvelopeIsSentWith(eventCount = 0, sessionCount = 0, attachmentCount = 1, transactionCount = 1) @@ -1797,7 +1809,7 @@ class SentryClientTest { } val scope = givenScopeWithStartedSession() - scope.addBreadcrumb(Breadcrumb.info("hello from breadcrumb"), Hints.withAttachment(fixture.attachment)) + scope.addBreadcrumb(Breadcrumb.info("hello from breadcrumb"), Hint.withAttachment(fixture.attachment)) sut.captureException(IllegalStateException(), scope) @@ -1871,8 +1883,8 @@ class SentryClientTest { } class CustomBeforeSendCallback : SentryOptions.BeforeSendCallback { - override fun execute(event: SentryEvent, hints: Hints): SentryEvent? { - hints.screenshot = null + override fun execute(event: SentryEvent, hint: Hint): SentryEvent? { + hint.screenshot = null return event } @@ -2034,7 +2046,7 @@ class SentryClientTest { private fun eventProcessorThrows(): EventProcessor { return object : EventProcessor { - override fun process(event: SentryEvent, hints: Hints): SentryEvent? { + override fun process(event: SentryEvent, hint: Hint): SentryEvent? { throw Throwable() } } diff --git a/sentry/src/test/java/io/sentry/clientreport/ClientReportTest.kt b/sentry/src/test/java/io/sentry/clientreport/ClientReportTest.kt index adae6a946c..e5071a2c06 100644 --- a/sentry/src/test/java/io/sentry/clientreport/ClientReportTest.kt +++ b/sentry/src/test/java/io/sentry/clientreport/ClientReportTest.kt @@ -14,7 +14,7 @@ import io.sentry.Session import io.sentry.UserFeedback import io.sentry.dsnString import io.sentry.hints.DiskFlushNotification -import io.sentry.hints.Hints +import io.sentry.hints.Hint import io.sentry.hints.Retryable import io.sentry.protocol.SentryId import io.sentry.protocol.SentryTransaction @@ -150,13 +150,13 @@ class ClientReportTest { class DropEverythingEventProcessor : EventProcessor { - override fun process(event: SentryEvent, hints: Hints): SentryEvent? { + override fun process(event: SentryEvent, hint: Hint): SentryEvent? { return null } override fun process( transaction: SentryTransaction, - hints: Hints + hint: Hint ): SentryTransaction? { return null } diff --git a/sentry/src/test/java/io/sentry/hints/HintTest.kt b/sentry/src/test/java/io/sentry/hints/HintTest.kt new file mode 100644 index 0000000000..ffde4fd048 --- /dev/null +++ b/sentry/src/test/java/io/sentry/hints/HintTest.kt @@ -0,0 +1,202 @@ +package io.sentry.hints + +import io.sentry.Attachment +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertNotNull +import kotlin.test.assertNull + +class HintTest { + @Test + fun `getting as wrong class returns null`() { + val hint = Hint() + hint.set("hint1", "not a number") + + assertNull(hint.getAs("hint1", Int::class.java)) + } + + @Test + fun `getting as correct class returns it`() { + val hint = Hint() + hint.set("hint1", "some string") + + assertEquals("some string", hint.getAs("hint1", String::class.java)) + } + + @Test + fun `getting casted returns null if not contained`() { + val hint = Hint() + assertNull(hint.getAs("hint-does-not-exist", Int::class.java)) + } + + @Test + fun `getting returns null if not contained`() { + val hint = Hint() + assertNull(hint.get("hint-does-not-exist")) + } + + @Test + fun `kotlin java interop for primitives works for float`() { + val hint = Hint() + hint.set("hint1", 1.3f) + assertEquals(1.3f, hint.getAs("hint1", Float::class.java)) + } + + @Test + fun `kotlin java interop for primitives works for double`() { + val hint = Hint() + hint.set("hint1", 1.4) + assertEquals(1.4, hint.getAs("hint1", Double::class.java)) + } + + @Test + fun `kotlin java interop for primitives works for long`() { + val hint = Hint() + hint.set("hint1", 1718L) + assertEquals(1718L, hint.getAs("hint1", Long::class.java)) + } + + @Test + fun `kotlin java interop for primitives works for int`() { + val hint = Hint() + hint.set("hint1", 123) + assertEquals(123, hint.getAs("hint1", Int::class.java)) + } + + @Test + fun `kotlin java interop for primitives works for short`() { + val hint = Hint() + val s: Short = 123 + hint.set("hint1", s) + assertEquals(s, hint.getAs("hint1", Short::class.java)) + } + + @Test + fun `kotlin java interop for primitives works for byte`() { + val hint = Hint() + val b: Byte = 1 + hint.set("hint1", b) + assertEquals(b, hint.getAs("hint1", Byte::class.java)) + } + + @Test + fun `kotlin java interop for primitives works for char`() { + val hint = Hint() + hint.set("hint1", 'a') + assertEquals('a', hint.getAs("hint1", Char::class.java)) + } + + @Test + fun `kotlin java interop for primitives works for boolean`() { + val hint = Hint() + hint.set("hint1", true) + assertEquals(true, hint.getAs("hint1", Boolean::class.java)) + } + + @Test + fun `setting twice only keeps second value`() { + val hint = Hint() + + hint.set("hint1", "some string") + hint.set("hint1", "a different string") + + assertEquals("a different string", hint.getAs("hint1", String::class.java)) + } + + @Test + fun `after removing the value is gone`() { + val hint = Hint() + + hint.set("hint1", "some string") + assertEquals("some string", hint.getAs("hint1", String::class.java)) + + hint.remove("hint1") + assertNull(hint.get("hint1")) + } + + @Test + fun `removing leaves other values`() { + val hint = Hint() + + hint.set("hint1", "some string") + assertEquals("some string", hint.getAs("hint1", String::class.java)) + hint.set("hint2", "another string") + + hint.remove("hint1") + assertNull(hint.get("hint1")) + assertEquals("another string", hint.getAs("hint2", String::class.java)) + } + + @Test + fun `can retrieve Attachments`() { + val hint = Hint() + assertNotNull(hint.attachments) + } + + @Test + fun `can create hints with attachment`() { + val attachment = newAttachment("test1") + val hint = Hint.withAttachment(attachment) + assertEquals(listOf(attachment), hint.attachments) + } + + @Test + fun `can create hints with attachments`() { + val attachment1 = newAttachment("test1") + val attachment2 = newAttachment("test1") + val hint = Hint.withAttachments(listOf(attachment1, attachment2)) + assertEquals(listOf(attachment1, attachment2), hint.attachments) + } + + @Test + fun `can add an attachment`() { + val hint = Hint() + val attachment = newAttachment("test1") + hint.addAttachment(attachment) + + assertEquals(listOf(attachment), hint.attachments) + } + + @Test + fun `can add multiple attachments`() { + val hint = Hint() + val attachment1 = newAttachment("test1") + val attachment2 = newAttachment("test2") + hint.addAttachment(attachment1) + hint.addAttachment(attachment2) + + assertEquals(listOf(attachment1, attachment2), hint.attachments) + } + + @Test + fun `after reset list is empty`() { + val hint = Hint() + val attachment1 = newAttachment("test1") + val attachment2 = newAttachment("test2") + hint.addAttachment(attachment1) + hint.addAttachment(attachment2) + + hint.clearAttachments() + + assertEquals(emptyList(), hint.attachments) + } + + @Test + fun `after replace list contains only new item`() { + val hint = Hint() + val attachment1 = newAttachment("test1") + val attachment2 = newAttachment("test2") + val attachment3 = newAttachment("test2") + val attachment4 = newAttachment("test2") + hint.addAttachment(attachment1) + hint.addAttachment(attachment2) + + hint.replaceAttachments(listOf(attachment3, attachment4)) + + assertEquals(listOf(attachment3, attachment4), hint.attachments) + } + + companion object { + fun newAttachment(content: String) = Attachment(content.toByteArray(), "$content.txt") + } +} diff --git a/sentry/src/test/java/io/sentry/hints/HintsTest.kt b/sentry/src/test/java/io/sentry/hints/HintsTest.kt deleted file mode 100644 index 92e6d302cd..0000000000 --- a/sentry/src/test/java/io/sentry/hints/HintsTest.kt +++ /dev/null @@ -1,202 +0,0 @@ -package io.sentry.hints - -import io.sentry.Attachment -import kotlin.test.Test -import kotlin.test.assertEquals -import kotlin.test.assertNotNull -import kotlin.test.assertNull - -class HintsTest { - @Test - fun `getting as wrong class returns null`() { - val hints = Hints() - hints.set("hint1", "not a number") - - assertNull(hints.getAs("hint1", Int::class.java)) - } - - @Test - fun `getting as correct class returns it`() { - val hints = Hints() - hints.set("hint1", "some string") - - assertEquals("some string", hints.getAs("hint1", String::class.java)) - } - - @Test - fun `getting casted returns null if not contained`() { - val hints = Hints() - assertNull(hints.getAs("hint-does-not-exist", Int::class.java)) - } - - @Test - fun `getting returns null if not contained`() { - val hints = Hints() - assertNull(hints.get("hint-does-not-exist")) - } - - @Test - fun `kotlin java interop for primitives works for float`() { - val hints = Hints() - hints.set("hint1", 1.3f) - assertEquals(1.3f, hints.getAs("hint1", Float::class.java)) - } - - @Test - fun `kotlin java interop for primitives works for double`() { - val hints = Hints() - hints.set("hint1", 1.4) - assertEquals(1.4, hints.getAs("hint1", Double::class.java)) - } - - @Test - fun `kotlin java interop for primitives works for long`() { - val hints = Hints() - hints.set("hint1", 1718L) - assertEquals(1718L, hints.getAs("hint1", Long::class.java)) - } - - @Test - fun `kotlin java interop for primitives works for int`() { - val hints = Hints() - hints.set("hint1", 123) - assertEquals(123, hints.getAs("hint1", Int::class.java)) - } - - @Test - fun `kotlin java interop for primitives works for short`() { - val hints = Hints() - val s: Short = 123 - hints.set("hint1", s) - assertEquals(s, hints.getAs("hint1", Short::class.java)) - } - - @Test - fun `kotlin java interop for primitives works for byte`() { - val hints = Hints() - val b: Byte = 1 - hints.set("hint1", b) - assertEquals(b, hints.getAs("hint1", Byte::class.java)) - } - - @Test - fun `kotlin java interop for primitives works for char`() { - val hints = Hints() - hints.set("hint1", 'a') - assertEquals('a', hints.getAs("hint1", Char::class.java)) - } - - @Test - fun `kotlin java interop for primitives works for boolean`() { - val hints = Hints() - hints.set("hint1", true) - assertEquals(true, hints.getAs("hint1", Boolean::class.java)) - } - - @Test - fun `setting twice only keeps second value`() { - val hints = Hints() - - hints.set("hint1", "some string") - hints.set("hint1", "a different string") - - assertEquals("a different string", hints.getAs("hint1", String::class.java)) - } - - @Test - fun `after removing the value is gone`() { - val hints = Hints() - - hints.set("hint1", "some string") - assertEquals("some string", hints.getAs("hint1", String::class.java)) - - hints.remove("hint1") - assertNull(hints.get("hint1")) - } - - @Test - fun `removing leaves other values`() { - val hints = Hints() - - hints.set("hint1", "some string") - assertEquals("some string", hints.getAs("hint1", String::class.java)) - hints.set("hint2", "another string") - - hints.remove("hint1") - assertNull(hints.get("hint1")) - assertEquals("another string", hints.getAs("hint2", String::class.java)) - } - - @Test - fun `can retrieve Attachments`() { - val hints = Hints() - assertNotNull(hints.attachments) - } - - @Test - fun `can create hints with attachment`() { - val attachment = newAttachment("test1") - val hints = Hints.withAttachment(attachment) - assertEquals(listOf(attachment), hints.attachments) - } - - @Test - fun `can create hints with attachments`() { - val attachment1 = newAttachment("test1") - val attachment2 = newAttachment("test1") - val hints = Hints.withAttachments(listOf(attachment1, attachment2)) - assertEquals(listOf(attachment1, attachment2), hints.attachments) - } - - @Test - fun `can add an attachment`() { - val hints = Hints() - val attachment = newAttachment("test1") - hints.addAttachment(attachment) - - assertEquals(listOf(attachment), hints.attachments) - } - - @Test - fun `can add multiple attachments`() { - val hints = Hints() - val attachment1 = newAttachment("test1") - val attachment2 = newAttachment("test2") - hints.addAttachment(attachment1) - hints.addAttachment(attachment2) - - assertEquals(listOf(attachment1, attachment2), hints.attachments) - } - - @Test - fun `after reset list is empty`() { - val hints = Hints() - val attachment1 = newAttachment("test1") - val attachment2 = newAttachment("test2") - hints.addAttachment(attachment1) - hints.addAttachment(attachment2) - - hints.clearAttachments() - - assertEquals(emptyList(), hints.attachments) - } - - @Test - fun `after replace list contains only new item`() { - val hints = Hints() - val attachment1 = newAttachment("test1") - val attachment2 = newAttachment("test2") - val attachment3 = newAttachment("test2") - val attachment4 = newAttachment("test2") - hints.addAttachment(attachment1) - hints.addAttachment(attachment2) - - hints.replaceAttachments(listOf(attachment3, attachment4)) - - assertEquals(listOf(attachment3, attachment4), hints.attachments) - } - - companion object { - fun newAttachment(content: String) = Attachment(content.toByteArray(), "$content.txt") - } -} diff --git a/sentry/src/test/java/io/sentry/transport/RateLimiterTest.kt b/sentry/src/test/java/io/sentry/transport/RateLimiterTest.kt index 59006bf2ef..e7fd08e411 100644 --- a/sentry/src/test/java/io/sentry/transport/RateLimiterTest.kt +++ b/sentry/src/test/java/io/sentry/transport/RateLimiterTest.kt @@ -22,7 +22,7 @@ import io.sentry.TransactionContext import io.sentry.UserFeedback import io.sentry.clientreport.DiscardReason import io.sentry.clientreport.IClientReportRecorder -import io.sentry.hints.Hints +import io.sentry.hints.Hint import io.sentry.protocol.SentryId import io.sentry.protocol.SentryTransaction import io.sentry.protocol.User @@ -64,7 +64,7 @@ class RateLimiterTest { rateLimiter.updateRetryAfterLimits("50:transaction:key, 1:default;error;security:organization", null, 1) - val result = rateLimiter.filter(envelope, Hints()) + val result = rateLimiter.filter(envelope, Hint()) assertNotNull(result) assertEquals(1, result.items.count()) } @@ -80,7 +80,7 @@ class RateLimiterTest { rateLimiter.updateRetryAfterLimits("50:transaction:key, 2700:default;error;security:organization", null, 1) - val result = rateLimiter.filter(envelope, Hints()) + val result = rateLimiter.filter(envelope, Hint()) assertNull(result) } @@ -95,7 +95,7 @@ class RateLimiterTest { rateLimiter.updateRetryAfterLimits("1:transaction:key, 1:default;error;security:organization", null, 1) - val result = rateLimiter.filter(envelope, Hints()) + val result = rateLimiter.filter(envelope, Hint()) assertNotNull(result) assertEquals(2, result.items.count()) } @@ -109,7 +109,7 @@ class RateLimiterTest { rateLimiter.updateRetryAfterLimits("50::key", null, 1) - val result = rateLimiter.filter(envelope, Hints()) + val result = rateLimiter.filter(envelope, Hint()) assertNull(result) } @@ -122,7 +122,7 @@ class RateLimiterTest { rateLimiter.updateRetryAfterLimits("1::key, 60:default;error;security:organization", null, 1) - val result = rateLimiter.filter(envelope, Hints()) + val result = rateLimiter.filter(envelope, Hint()) assertNull(result) } @@ -135,7 +135,7 @@ class RateLimiterTest { rateLimiter.updateRetryAfterLimits("60:error:key, 1:error:organization", null, 1) - val result = rateLimiter.filter(envelope, Hints()) + val result = rateLimiter.filter(envelope, Hint()) assertNull(result) } @@ -148,7 +148,7 @@ class RateLimiterTest { rateLimiter.updateRetryAfterLimits("1:error:key, 5:error:organization", null, 1) - val result = rateLimiter.filter(envelope, Hints()) + val result = rateLimiter.filter(envelope, Hint()) assertNull(result) } @@ -161,7 +161,7 @@ class RateLimiterTest { rateLimiter.updateRetryAfterLimits(null, null, 429) - val result = rateLimiter.filter(envelope, Hints()) + val result = rateLimiter.filter(envelope, Hint()) assertNull(result) } @@ -186,7 +186,7 @@ class RateLimiterTest { val envelope = SentryEnvelope(SentryEnvelopeHeader(), arrayListOf(eventItem, userFeedbackItem, sessionItem, attachmentItem)) rateLimiter.updateRetryAfterLimits(null, null, 429) - val result = rateLimiter.filter(envelope, Hints()) + val result = rateLimiter.filter(envelope, Hint()) assertNull(result) @@ -218,7 +218,7 @@ class RateLimiterTest { val envelope = SentryEnvelope(SentryEnvelopeHeader(), arrayListOf(eventItem, userFeedbackItem, sessionItem, attachmentItem)) rateLimiter.updateRetryAfterLimits("60:error:key, 1:error:organization", null, 1) - val result = rateLimiter.filter(envelope, Hints()) + val result = rateLimiter.filter(envelope, Hint()) assertNotNull(result) assertEquals(3, result.items.toList().size) diff --git a/sentry/src/test/java/io/sentry/util/HintUtilsTest.kt b/sentry/src/test/java/io/sentry/util/HintUtilsTest.kt index 425eb31a0d..d6f24ab566 100644 --- a/sentry/src/test/java/io/sentry/util/HintUtilsTest.kt +++ b/sentry/src/test/java/io/sentry/util/HintUtilsTest.kt @@ -4,7 +4,7 @@ import com.nhaarman.mockitokotlin2.mock import io.sentry.CustomCachedApplyScopeDataHint import io.sentry.hints.ApplyScopeData import io.sentry.hints.Cached -import io.sentry.hints.Hints +import io.sentry.hints.Hint import kotlin.test.Test import kotlin.test.assertFalse import kotlin.test.assertTrue @@ -19,7 +19,7 @@ class HintUtilsTest { @Test fun `if event is not Cached, it should apply scopes data`() { - assertTrue(HintUtils.shouldApplyScopeData(Hints())) + assertTrue(HintUtils.shouldApplyScopeData(Hint())) } @Test From df7012120c40730da73f6677c9854be67a21421e Mon Sep 17 00:00:00 2001 From: Alexander Dinauer Date: Fri, 20 May 2022 11:39:52 +0200 Subject: [PATCH 7/9] Remove commented out code --- .../src/main/java/io/sentry/util/LogUtils.java | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/sentry/src/main/java/io/sentry/util/LogUtils.java b/sentry/src/main/java/io/sentry/util/LogUtils.java index 3c97a50e74..3316b1dce7 100644 --- a/sentry/src/main/java/io/sentry/util/LogUtils.java +++ b/sentry/src/main/java/io/sentry/util/LogUtils.java @@ -19,20 +19,4 @@ public static void logNotInstanceOf( sentrySdkHint != null ? sentrySdkHint.getClass().getCanonicalName() : "Hint", expectedClass.getCanonicalName()); } - - // public static void logIfNotFlushable( - // final @NotNull ILogger logger, final @Nullable Object sentrySdkHint) { - // logger.log( - // SentryLevel.DEBUG, - // "%s is not Flushable", - // sentrySdkHint != null ? sentrySdkHint.getClass().getCanonicalName() : "Hint"); - // } - // - // public static void logIfNotRetryable( - // final @NotNull ILogger logger, final @Nullable Object sentrySdkHint) { - // logger.log( - // SentryLevel.DEBUG, - // "%s is not Retryable", - // sentrySdkHint != null ? sentrySdkHint.getClass().getCanonicalName() : "Hint"); - // } } From 1c9f5bab6442409ff0fe63efb0094f49a8c9671e Mon Sep 17 00:00:00 2001 From: Alexander Dinauer Date: Fri, 20 May 2022 18:43:04 +0200 Subject: [PATCH 8/9] Code Review --- sentry/src/main/java/io/sentry/TypeCheckHint.java | 1 - sentry/src/test/java/io/sentry/SentryClientTest.kt | 6 +++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/sentry/src/main/java/io/sentry/TypeCheckHint.java b/sentry/src/main/java/io/sentry/TypeCheckHint.java index cc50b40c37..a1631234cc 100644 --- a/sentry/src/main/java/io/sentry/TypeCheckHint.java +++ b/sentry/src/main/java/io/sentry/TypeCheckHint.java @@ -2,7 +2,6 @@ import org.jetbrains.annotations.ApiStatus; -// TODO can this be an enum? /** Constants used for Type Check hints. */ public final class TypeCheckHint { diff --git a/sentry/src/test/java/io/sentry/SentryClientTest.kt b/sentry/src/test/java/io/sentry/SentryClientTest.kt index 26d9fd41c1..41f85ced34 100644 --- a/sentry/src/test/java/io/sentry/SentryClientTest.kt +++ b/sentry/src/test/java/io/sentry/SentryClientTest.kt @@ -1646,7 +1646,7 @@ class SentryClientTest { fun `can replace attachments in beforeSend`() { val sut = fixture.getSut { options -> options.setBeforeSend { event, hints -> - hints.replaceAttachments(listOf(fixture.attachment)) + hints.replaceAttachments(listOf(fixture.attachment3)) event } } @@ -1689,7 +1689,7 @@ class SentryClientTest { val sut = fixture.getSut { options -> options.addEventProcessor(object : EventProcessor { override fun process(event: SentryEvent, hint: Hint): SentryEvent? { - hint.replaceAttachments(listOf(fixture.attachment)) + hint.replaceAttachments(listOf(fixture.attachment3)) return event } @@ -1782,7 +1782,7 @@ class SentryClientTest { transaction: SentryTransaction, hint: Hint ): SentryTransaction? { - hint.replaceAttachments(listOf(fixture.attachment)) + hint.replaceAttachments(listOf(fixture.attachment3)) return transaction } }) From 5b71f25b558e2d469bf02f1a06441595aba52581 Mon Sep 17 00:00:00 2001 From: Alexander Dinauer Date: Mon, 23 May 2022 08:50:32 +0200 Subject: [PATCH 9/9] Rename SentryFallbackConsumer as it is Hints specific --- sentry/api/sentry.api | 4 ++-- sentry/src/main/java/io/sentry/util/HintUtils.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/sentry/api/sentry.api b/sentry/api/sentry.api index 4a4adea3e0..7c1e8a3234 100644 --- a/sentry/api/sentry.api +++ b/sentry/api/sentry.api @@ -2944,7 +2944,7 @@ public final class io/sentry/util/HintUtils { public static fun hasType (Lio/sentry/hints/Hint;Ljava/lang/Class;)Z public static fun runIfDoesNotHaveType (Lio/sentry/hints/Hint;Ljava/lang/Class;Lio/sentry/util/HintUtils$SentryNullableConsumer;)V public static fun runIfHasType (Lio/sentry/hints/Hint;Ljava/lang/Class;Lio/sentry/util/HintUtils$SentryConsumer;)V - public static fun runIfHasType (Lio/sentry/hints/Hint;Ljava/lang/Class;Lio/sentry/util/HintUtils$SentryConsumer;Lio/sentry/util/HintUtils$SentryFallbackConsumer;)V + public static fun runIfHasType (Lio/sentry/hints/Hint;Ljava/lang/Class;Lio/sentry/util/HintUtils$SentryConsumer;Lio/sentry/util/HintUtils$SentryHintFallback;)V public static fun runIfHasTypeLogIfNot (Lio/sentry/hints/Hint;Ljava/lang/Class;Lio/sentry/ILogger;Lio/sentry/util/HintUtils$SentryConsumer;)V public static fun setTypeCheckHint (Lio/sentry/hints/Hint;Ljava/lang/Object;)V public static fun shouldApplyScopeData (Lio/sentry/hints/Hint;)Z @@ -2954,7 +2954,7 @@ public abstract interface class io/sentry/util/HintUtils$SentryConsumer { public abstract fun accept (Ljava/lang/Object;)V } -public abstract interface class io/sentry/util/HintUtils$SentryFallbackConsumer { +public abstract interface class io/sentry/util/HintUtils$SentryHintFallback { public abstract fun accept (Ljava/lang/Object;Ljava/lang/Class;)V } diff --git a/sentry/src/main/java/io/sentry/util/HintUtils.java b/sentry/src/main/java/io/sentry/util/HintUtils.java index e43aafac35..73067c1568 100644 --- a/sentry/src/main/java/io/sentry/util/HintUtils.java +++ b/sentry/src/main/java/io/sentry/util/HintUtils.java @@ -75,7 +75,7 @@ public static void runIfHasType( @NotNull Hint hint, @NotNull Class clazz, SentryConsumer lambda, - SentryFallbackConsumer fallbackLambda) { + SentryHintFallback fallbackLambda) { Object sentrySdkHint = getSentrySdkHint(hint); if (hasType(hint, clazz) && sentrySdkHint != null) { lambda.accept((T) sentrySdkHint); @@ -106,7 +106,7 @@ public interface SentryNullableConsumer { } @FunctionalInterface - public interface SentryFallbackConsumer { + public interface SentryHintFallback { void accept(@Nullable Object sentrySdkHint, @NotNull Class clazz); } }