diff --git a/sentry-android-core/src/main/java/io/sentry/android/core/ViewHierarchyEventProcessor.java b/sentry-android-core/src/main/java/io/sentry/android/core/ViewHierarchyEventProcessor.java index b2b79b17426..675715a3835 100644 --- a/sentry-android-core/src/main/java/io/sentry/android/core/ViewHierarchyEventProcessor.java +++ b/sentry-android-core/src/main/java/io/sentry/android/core/ViewHierarchyEventProcessor.java @@ -14,6 +14,7 @@ import io.sentry.android.core.internal.gestures.ViewUtils; import io.sentry.protocol.ViewHierarchy; import io.sentry.protocol.ViewHierarchyNode; +import io.sentry.util.HintUtils; import io.sentry.util.JsonSerializationUtils; import io.sentry.util.Objects; import java.util.ArrayList; @@ -43,6 +44,10 @@ public ViewHierarchyEventProcessor(final @NotNull SentryAndroidOptions options) return event; } + if (HintUtils.isFromHybridSdk(hint)) { + return event; + } + final @Nullable Activity activity = CurrentActivityHolder.getInstance().getActivity(); final @Nullable ViewHierarchy viewHierarchy = snapshotViewHierarchy(activity, options.getLogger()); diff --git a/sentry-android-core/src/test/java/io/sentry/android/core/ViewHierarchyEventProcessorTest.kt b/sentry-android-core/src/test/java/io/sentry/android/core/ViewHierarchyEventProcessorTest.kt index b06e9c8cb38..a74e83858a3 100644 --- a/sentry-android-core/src/test/java/io/sentry/android/core/ViewHierarchyEventProcessorTest.kt +++ b/sentry-android-core/src/test/java/io/sentry/android/core/ViewHierarchyEventProcessorTest.kt @@ -9,6 +9,7 @@ import io.sentry.Hint import io.sentry.JsonSerializable import io.sentry.JsonSerializer import io.sentry.SentryEvent +import io.sentry.TypeCheckHint import io.sentry.protocol.SentryException import org.junit.runner.RunWith import org.mockito.invocation.InvocationOnMock @@ -64,10 +65,10 @@ class ViewHierarchyEventProcessorTest { fun process( attachViewHierarchy: Boolean, - event: SentryEvent + event: SentryEvent, + hint: Hint = Hint() ): Pair { val processor = getSut(attachViewHierarchy) - val hint = Hint() processor.process(event, hint) return Pair(event, hint) @@ -104,6 +105,22 @@ class ViewHierarchyEventProcessorTest { assertNull(viewHierarchy) } + @Test + fun `when an event errored, the view hierarchy should not attached if the event is from hybrid sdk`() { + val hintFromHybridSdk = Hint() + hintFromHybridSdk.set(TypeCheckHint.SENTRY_IS_FROM_HYBRID_SDK, true) + val (event, hint) = fixture.process( + true, + SentryEvent().apply { + exceptions = listOf(SentryException()) + }, + hintFromHybridSdk + ) + + assertNotNull(event) + assertNull(hint.viewHierarchy) + } + @Test fun `when an event errored, the view hierarchy should not attached if the feature is disabled`() { val (event, hint) = fixture.process(