-
-
Notifications
You must be signed in to change notification settings - Fork 32
Call Sentry#close
on JVM shutdown.
#497
Changes from 4 commits
61743dd
129adf2
8952638
3fae6fa
6836004
fd70029
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,21 @@ | ||||||
package io.sentry.core; | ||||||
|
||||||
import io.sentry.core.util.Objects; | ||||||
import org.jetbrains.annotations.NotNull; | ||||||
|
||||||
/** Registers hook that closes {@link Hub} when main thread shuts down. */ | ||||||
public final class ShutdownHookIntegration implements Integration { | ||||||
|
||||||
private final @NotNull Runtime runtime; | ||||||
|
||||||
public ShutdownHookIntegration(final @NotNull Runtime runtime) { | ||||||
this.runtime = Objects.requireNonNull(runtime, "Runtime is required"); | ||||||
} | ||||||
maciejwalkowiak marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
@Override | ||||||
public void register(@NotNull IHub hub, @NotNull SentryOptions options) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. any reason to not apply the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No specific reason, I've seen some methods with My personal take on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. got it, just asking cus it was in my first GH "suggestion". Agreed that they should be treated as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps there is a way to configure static code analysis to make sure it doesn't sneak in? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. all the data classes are mutable by design, I've tried once but then it warned about almost everything. |
||||||
Objects.requireNonNull(hub, "Hub is required"); | ||||||
|
||||||
runtime.addShutdownHook(new Thread(() -> hub.close())); | ||||||
} | ||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package io.sentry.core | ||
|
||
import com.nhaarman.mockitokotlin2.any | ||
import com.nhaarman.mockitokotlin2.mock | ||
import com.nhaarman.mockitokotlin2.verify | ||
import kotlin.test.Test | ||
|
||
class ShutdownHookIntegrationTest { | ||
|
||
@Test | ||
fun `registration attaches shutdown hook to runtime`() { | ||
val runtime = mock<Runtime>() | ||
val integration = ShutdownHookIntegration(runtime) | ||
|
||
integration.register(NoOpHub.getInstance(), SentryOptions()) | ||
|
||
verify(runtime).addShutdownHook(any()) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed offline, for now it makes sense to just add the "event cache" related stuff into Android and focus on the core not having offline caching altogether.
Down the road when the need comes we can revisit and think of a better way to "opt-in" to offline mode in a simple way, that would work for Android or Java apps (say desktop could leverage that)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Just so that it doesn't get lost - I think we should expose ideally single method that turns on caching which takes
cachePathDir
as parameter and under the hood also turns on all cache-related integrations.