Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR] Capture Replays for ANRs and crashes #3565

Merged
merged 255 commits into from
Jul 30, 2024
Merged

Conversation

romtsn
Copy link
Member

@romtsn romtsn commented Jul 11, 2024

📜 Description

The main changes are:

ANRs part

  • We persist replay_id from scope to disk
    • We then retrieve it in AnrV2EventProcessor and set it as context to read it out later, when constructing DSC Baggage, so it gets linked with the replay properly
    • Also made a fix that we fall back to propagationContext in case there's no active transaction on scope, to always have a trace to link to

Replay part

  • We now observe values that are necessary for capturing a replay segment and store the to disk continuously
  • On next app launch we read out those values + construct a new cache out of the screenshots saved to disk in the previous run
    • For that we also made BaseCaptureStrategy.createSegment method fully parameterized, to supply things like breadcrumbs/rrweb events/segment values not only from the current app run, but also from the previously serialized values when needed

TODO leftovers

There are some leftovers which (imo) is fine to address later, namely:

  • Infer traceContext for replay events from the event values, when the event is Backfillable (=sent on next app launch)
  • Infer options and tags for replay events from disk (we already have .options_cache for that), when the event is Backfillable (=sent on next app launch)
  • Choose better serialization format for an ongoing segment, because it's currently awful

💡 Motivation and Context

Part of getsentry/sentry#70065

💚 How did you test it?

Manually + automated

Next up

Do the same for crashes and JS crashes, and after that get to the buffer mode as it's a bit more work there

Example ANR with a linked replay

https://sentry-sdks.sentry.io/issues/5587028220/events/635b45b8a6254aa29f8d4f1734480613

Base automatically changed from rz/feat/session-replay to main July 15, 2024 17:11
}

// we need to round to the nearest frame to include breadcrumbs/events happened after the frame was captured
val duration = roundToNearestFrame(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
val duration = roundToNearestFrame(
val durationMillis = roundToNearestFrame(

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will address in the other PR since this line has changed there

Copy link
Member

@markushi markushi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good, left a few comments 🚀

isClosed.set(true)
}

// TODO: it's awful, choose a better serialization format
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would appending only the new items to the file work better?

sentry/src/main/java/io/sentry/Scope.java Outdated Show resolved Hide resolved
@romtsn romtsn changed the title [SR] Capture Replays for ANRs in session mode [SR] Capture Replays for ANRs and crashes Jul 30, 2024
@romtsn romtsn merged commit e039872 into main Jul 30, 2024
25 of 26 checks passed
@romtsn romtsn deleted the rz/feat/session-replay-anrs branch July 30, 2024 19:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants