-
-
Notifications
You must be signed in to change notification settings - Fork 442
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deduplicate events happening in multiple threads simultaneously (#2845)
- Loading branch information
Showing
14 changed files
with
325 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
sentry-samples/sentry-samples-android/src/main/res/values/strings.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
sentry/src/main/java/io/sentry/DeduplicateMultithreadedEventProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package io.sentry; | ||
|
||
import io.sentry.hints.EventDropReason; | ||
import io.sentry.protocol.SentryException; | ||
import io.sentry.util.HintUtils; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
/** | ||
* An event processor that deduplicates crash events of the same type that are simultaneously from | ||
* multiple threads. This can be the case for OutOfMemory errors or CursorWindowAllocationException, | ||
* basically any error related to allocating memory when it's low. | ||
*/ | ||
public final class DeduplicateMultithreadedEventProcessor implements EventProcessor { | ||
|
||
private final @NotNull Map<String, Long> processedEvents = | ||
Collections.synchronizedMap(new HashMap<>()); | ||
|
||
private final @NotNull SentryOptions options; | ||
|
||
public DeduplicateMultithreadedEventProcessor(final @NotNull SentryOptions options) { | ||
this.options = options; | ||
} | ||
|
||
@Override | ||
public @Nullable SentryEvent process(final @NotNull SentryEvent event, final @NotNull Hint hint) { | ||
if (!HintUtils.hasType(hint, UncaughtExceptionHandlerIntegration.UncaughtExceptionHint.class)) { | ||
// only dedupe crashes coming from our exception handler, because custom errors/crashes might | ||
// be sent on purpose | ||
return event; | ||
} | ||
|
||
final SentryException exception = event.getUnhandledException(); | ||
if (exception == null) { | ||
return event; | ||
} | ||
|
||
final String type = exception.getType(); | ||
if (type == null) { | ||
return event; | ||
} | ||
|
||
final Long currentEventTid = exception.getThreadId(); | ||
if (currentEventTid == null) { | ||
return event; | ||
} | ||
|
||
final Long tid = processedEvents.get(type); | ||
if (tid != null && !tid.equals(currentEventTid)) { | ||
options | ||
.getLogger() | ||
.log( | ||
SentryLevel.INFO, | ||
"Event %s has been dropped due to multi-threaded deduplication", | ||
event.getEventId()); | ||
HintUtils.setEventDropReason(hint, EventDropReason.MULTITHREADED_DEDUPLICATION); | ||
return null; | ||
} | ||
processedEvents.put(type, currentEventTid); | ||
return event; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package io.sentry.hints; | ||
|
||
import org.jetbrains.annotations.ApiStatus; | ||
|
||
/** A reason for which an event was dropped, used for (not to confuse with ClientReports) */ | ||
@ApiStatus.Internal | ||
public enum EventDropReason { | ||
MULTITHREADED_DEDUPLICATION | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.