|
2 | 2 |
|
3 | 3 | import com.jakewharton.nopen.annotation.Open; |
4 | 4 | import io.sentry.EventProcessor; |
| 5 | +import io.sentry.HubAdapter; |
| 6 | +import io.sentry.IHub; |
5 | 7 | import io.sentry.ITransportFactory; |
6 | 8 | import io.sentry.Integration; |
7 | 9 | import io.sentry.Sentry; |
8 | 10 | import io.sentry.SentryOptions; |
9 | 11 | import io.sentry.SentryOptions.TracesSamplerCallback; |
| 12 | +import io.sentry.util.Objects; |
10 | 13 | import org.jetbrains.annotations.NotNull; |
11 | 14 | import org.jetbrains.annotations.Nullable; |
12 | 15 | import org.springframework.beans.BeansException; |
| 16 | +import org.springframework.beans.factory.DisposableBean; |
13 | 17 | import org.springframework.beans.factory.config.BeanPostProcessor; |
14 | 18 | import org.springframework.context.ApplicationContext; |
15 | 19 | import org.springframework.context.ApplicationContextAware; |
16 | 20 |
|
17 | | -/** Initializes Sentry after all beans are registered. */ |
| 21 | +/** |
| 22 | + * Initializes Sentry after all beans are registered. Closes Sentry on Spring application context |
| 23 | + * destroy. |
| 24 | + */ |
18 | 25 | @Open |
19 | | -public class SentryInitBeanPostProcessor implements BeanPostProcessor, ApplicationContextAware { |
| 26 | +public class SentryInitBeanPostProcessor |
| 27 | + implements BeanPostProcessor, ApplicationContextAware, DisposableBean { |
20 | 28 | private @Nullable ApplicationContext applicationContext; |
21 | 29 |
|
| 30 | + private final @NotNull IHub hub; |
| 31 | + |
| 32 | + public SentryInitBeanPostProcessor() { |
| 33 | + this(HubAdapter.getInstance()); |
| 34 | + } |
| 35 | + |
| 36 | + SentryInitBeanPostProcessor(final @NotNull IHub hub) { |
| 37 | + Objects.requireNonNull(hub, "hub is required"); |
| 38 | + this.hub = hub; |
| 39 | + } |
| 40 | + |
22 | 41 | @Override |
23 | 42 | @SuppressWarnings({"unchecked", "deprecation"}) |
24 | 43 | public @NotNull Object postProcessAfterInitialization( |
@@ -68,4 +87,9 @@ public void setApplicationContext(final @NotNull ApplicationContext applicationC |
68 | 87 | throws BeansException { |
69 | 88 | this.applicationContext = applicationContext; |
70 | 89 | } |
| 90 | + |
| 91 | + @Override |
| 92 | + public void destroy() { |
| 93 | + hub.close(); |
| 94 | + } |
71 | 95 | } |
0 commit comments