|
41 | 41 | import java.util.List; |
42 | 42 | import java.util.Locale; |
43 | 43 | import java.util.Map; |
44 | | -import java.util.concurrent.atomic.AtomicBoolean; |
45 | 44 | import java.util.concurrent.atomic.AtomicReference; |
46 | 45 | import org.jetbrains.annotations.ApiStatus; |
47 | 46 | import org.jetbrains.annotations.NotNull; |
@@ -250,51 +249,33 @@ public static SentryId captureEnvelopeNonTerminating(final @NotNull byte[] envel |
250 | 249 | final @NotNull EnvelopeEventState eventState = eventStateOf(envelope, serializer); |
251 | 250 |
|
252 | 251 | if (eventState != EnvelopeEventState.NONE) { |
253 | | - final @Nullable Session session = recordSessionError(scopes, options, eventState); |
254 | | - if (session != null && options.getEnvelopeDiskCache() instanceof EnvelopeCache) { |
255 | | - ((EnvelopeCache) options.getEnvelopeDiskCache()).persistCurrentSession(session); |
256 | | - } |
257 | | - } |
258 | | - |
259 | | - return scopes.captureEnvelope(envelope); |
260 | | - } catch (Exception e) { |
261 | | - options.getLogger().log(SentryLevel.ERROR, "Failed to capture envelope", e); |
262 | | - } |
263 | | - return null; |
264 | | - } |
265 | | - |
266 | | - /** |
267 | | - * Records the envelope's error on the current session under the scope lock and returns the |
268 | | - * snapshot taken while holding it, so the caller can persist it without keeping the lock during |
269 | | - * disk I/O. Returns null when there is no session or it had already reached a terminal state. |
270 | | - */ |
271 | | - private static @Nullable Session recordSessionError( |
272 | | - final @NotNull IScopes scopes, |
273 | | - final @NotNull SentryOptions options, |
274 | | - final @NotNull EnvelopeEventState eventState) { |
275 | | - final @NotNull AtomicReference<Session> snapshotRef = new AtomicReference<>(); |
276 | | - scopes.configureScope( |
277 | | - scope -> { |
278 | | - final @NotNull AtomicBoolean updated = new AtomicBoolean(false); |
279 | | - final @Nullable Session snapshot = |
| 252 | + scopes.configureScope( |
| 253 | + scope -> { |
280 | 254 | scope.withSession( |
281 | 255 | session -> { |
282 | 256 | if (session != null) { |
283 | | - updated.set( |
| 257 | + final boolean updated = |
284 | 258 | eventState == EnvelopeEventState.UNHANDLED |
285 | 259 | ? session.recordNonTerminatingUnhandledError() |
286 | | - : session.update(null, null, true, null)); |
| 260 | + : session.update(null, null, true, null); |
| 261 | + if (updated && options.getEnvelopeDiskCache() instanceof EnvelopeCache) { |
| 262 | + ((EnvelopeCache) options.getEnvelopeDiskCache()) |
| 263 | + .persistCurrentSession(session); |
| 264 | + } |
287 | 265 | } else { |
288 | 266 | options |
289 | 267 | .getLogger() |
290 | 268 | .log(INFO, "Session is null on captureEnvelopeNonTerminating"); |
291 | 269 | } |
292 | 270 | }); |
293 | | - if (updated.get()) { |
294 | | - snapshotRef.set(snapshot); |
295 | | - } |
296 | | - }); |
297 | | - return snapshotRef.get(); |
| 271 | + }); |
| 272 | + } |
| 273 | + |
| 274 | + return scopes.captureEnvelope(envelope); |
| 275 | + } catch (Exception e) { |
| 276 | + options.getLogger().log(SentryLevel.ERROR, "Failed to capture envelope", e); |
| 277 | + } |
| 278 | + return null; |
298 | 279 | } |
299 | 280 |
|
300 | 281 | /** What the events inside an envelope amount to, from the session's point of view. */ |
|
0 commit comments