Android
Configure Session Capture

Configure Session Capture

Session replay shows what the user saw before an error, or along a journey you care about. This page sets it up in an Android app: turn it on, hide what is private, decide which sessions upload replay, and then change all of it from the dashboard without a release. It assumes the SDK is installed and started as in the Quick Start.

StepWhat you doWhere
1Turn on replay and set its limitsApp code
2Hide private contentApp code and layouts
3Choose whether replays show imagesDashboard or app code
4Choose which sessions upload replayDashboard or app code
5Capture one user or deviceDashboard
6Change collection with rulesDashboard

Step 1: Turn on replay and set the limits in the app

An Android app records a wireframe: when something on screen changed, at most 5 times a second, the SDK reads the app's windows (activities, dialogs, popups) and records what the views and Jetpack Compose screens show as HTML, which the dashboard replays with the same rrweb player as a browser session. No screenshot is taken and no video is encoded: a clip is tens of kilobytes.

Replay is off until you turn it on with screenCapture:

Traceway.init(
    this,
    TracewayOptions(
        token = BuildConfig.TRACEWAY_TOKEN,
        screenCapture = true,
        fps = 5,               // the default and the most
        maxBufferFrames = 150, // the default; the longest clip
    ),
)

The options you set in the app are the most replay can ever do. A Data Collection rule can record less or stop recording, but never more: without screenCapture turned on, nothing is recorded, whatever a rule says. The other ceilings that matter for replay:

  • replayImages: the most a replay may show of images (see Step 3).
  • captureUserActions and captureNavigation: the taps and screens shown next to the replay, and the steps recording triggers match.
  • sessions: the session records (session.start, session.end) the Sessions page is built from. The session id exists either way, so error clips, captures and rules that stream replay still work.
  • fps and maxBufferFrames: how often a frame is taken at most (5 a second by default, never more) and how many frames the device holds. A rule cannot raise them.

sampleRate, baselineSampleRate and recordAllSessions are defaults, not ceilings: a rule can change them in either direction.

Replay waits on the device until something asks for it. The last frames stay in a ring of maxBufferFrames frames (150 by default, at least 30 seconds at 5 frames a second). An exception uploads the replay of up to the last 30 seconds as its clip, cut to the frames the ring holds, so a clip is never longer than the ring. While a capture or a rule streams replay, the session leaves as consecutive segments of up to 10 seconds that each start with a full snapshot, and the session player plays them back to back.

Replay always goes to Traceway, also when telemetry sends logs, traces and metrics to another provider. Without a token (standalone), nothing is recorded.

A frame is taken only when the screen changed, so 150 frames at 5 a second cover at least 30 seconds: an error clip holds the whole 30 seconds. Streamed segments last up to 10 seconds.

How often a frame is taken.

The Flutter, Android and iOS SDKs take a wireframe frame by the same rules:

  • At most fps a second, 5 by default and at most 5. A higher value is held to 5, and the debug log says so once.
  • Only when the screen changed. Drawing, a touch or a navigation only marks the screen as changed, and the next capture, at most 200 ms later, reads it. A screen at rest takes no frames, and while a session streams, a segment's time in which nothing was recorded uploads nothing: a still screen costs its first segment only.
  • One short step on the main thread (the UI isolate in Flutter). A capture reads the screen there into a copy. Comparing it with the last frame, building the rrweb events, encoding pictures, compressing and assembling segments run off that thread: on a thread of the SDK's own on Android and iOS, and on background isolates in Flutter.
  • A tenth of that thread at most. A read starts only while the reads of the last second took under 100 ms. A read is not cut short once it started; one that goes past the 100 ms is paid back before the next (a 300 ms read is followed by 3 seconds without one), and one read stops at 3,000 views or nodes, recording a larger screen cut off there. A capture that is skipped or falls behind doubles the interval, down to one capture a second, and it comes back step by step when captures keep up. A capture never waits in a queue, and it always reads the screen as it is at that moment.
  • Reported on the session. Session events carry traceway.replay.capture_rate, the median captures a second over the seconds the screen changed, and traceway.replay.dropped_captures.

What each SDK costs with these rules is on SDK Performance.

On Android, a screen that a touch moved and that comes to rest (a fling that stopped) is captured at once, even while the rate is lowered, so the replay shows where the scroll settled. A screen that redraws on its own, such as a ticking chart, keeps the lowered rate. While the app is in the background, the replay shows a blank "App in the background" screen.

Step 2: Hide private content

Masks change the recording only: the user sees no difference in the live app.

Inputs are masked by default

Text typed into a field is replaced with *, and a password field always shows dots. Hints and floating labels are not typed text and stay readable. Only a rule that sets replay.maskAllInputs to false turns this off; turning it back on drops the frames recorded without it and the clips made from them that are not uploaded yet.

The soft keyboard is drawn by the system, not by the app, so the replay never records its keys. While it is up, the wireframe draws a neutral box labelled "Keyboard" where it covers the app. What the user types shows only in the field, masked like any other typed text.

On Android 11 and later the box covers the window's keyboard inset, below that the part of the screen the keyboard hides, light or dark as the app's theme is.

Mark views with a mask

A blur mask keeps the layout and replaces its text with * and its images with placeholders. A blank mask is a box of one color, and nothing inside it is recorded. A mask covers the view and everything inside it.

import android.graphics.Color
import com.tracewayapp.traceway.TracewayMaskMode
import com.tracewayapp.traceway.tracewayMask
 
cardNumberView.tracewayMask = TracewayMaskMode.blur()
profileHeader.tracewayMask = TracewayMaskMode.blank(Color.BLACK)
cardNumberView.tracewayMask = null // no mask

From Java: Traceway.mask(view, TracewayMaskMode.blur()) and Traceway.unmask(view). In a layout, with no code:

<TextView
    android:id="@+id/card_number"
    android:tag="traceway-mask" />   <!-- blur; "traceway-blank" for a blank box -->

In Jetpack Compose, with the modifier or a test tag:

import com.tracewayapp.traceway.TracewayMaskMode
import com.tracewayapp.traceway.compose.tracewayMask
 
Text(address, Modifier.tracewayMask())
Box(Modifier.tracewayMask(TracewayMaskMode.blank())) { AccountDetails() }
Text(iban, Modifier.testTag("traceway-blank"))

A masked view's text and label are left out of tap records too, and a mask tag never names a view in a selector.

Check the mask before you ship

A mask you forgot is a leak, and the live app looks the same with or without one. Before a release, record a session of the screens that show private data and play it:

  1. In a debug build, turn on recordAllSessions so every session streams its replay, or create a capture for your test device (Step 5).
  2. Open each screen that shows card numbers, addresses, balances, messages or other private content, and type into its fields.
  3. Open the session on the Sessions page and play it. Every masked part should be a box or * characters, typed text should be *, and no password field should show what was typed.
  4. Open the session's Actions list: the taps on masked controls must not show their text or label.

Turn recordAllSessions off again before you ship.

Step 3: Choose whether replays show images

Two settings decide it, and the lower one wins, in the order off, wifi, always:

  • replay.images, the collection setting: off, wifi (the default) or always. Set it in a Data Collection rule (Signals tab, Replay images: Off, Wi‑Fi only or Always), or in the app's own collection document. A device picks up a change at its next poll, so you can turn images off for everyone without a release. A stricter value also drops the frames the device still holds and the clips it has not uploaded yet.
  • replayImages, the app's ceiling (always by default). Set to off, every image stays a placeholder whatever a rule says.

With the defaults, replays carry the app's pictures on Wi‑Fi and none on a mobile network. The network is checked when a frame is captured, so a picture recorded on Wi‑Fi stays in its clip. The policy covers pictures only: the wireframe itself, error reports, logs, traces, metrics and the settings poll go out on any network.

The ceiling in the app:

TracewayOptions(
    token = BuildConfig.TRACEWAY_TOKEN,
    screenCapture = true,
    replayImages = TracewayImagePolicy.WIFI, // never more than Wi‑Fi only, whatever a rule says
)

What Wi‑Fi only means on Android. A network is unmetered when ConnectivityManager.isActiveNetworkMetered() is false: Wi‑Fi and Ethernet, usually. On Android 7 and later the SDK follows the default network as it changes. The ACCESS_NETWORK_STATE permission this needs comes with the library's manifest.

The size limits, the same on Android, iOS and Flutter:

  • A picture is made from the pixels the app shows in that place, never from a screenshot of the window. It is copied at its displayed size (one pixel per dp on Android, per point on iOS, per logical pixel in Flutter), at most 384 pixels on its longest side, and encoded as JPEG at quality 0.45.
  • A picture with see-through pixels is never a JPEG, which would replay it as a black or white box. It is a PNG, at most 192 pixels on its longest side.
  • A picture larger than 48 KiB is tried once more at half the size, then left out.
  • The same image at the same size is one picture, however many places show it. A recorder keeps at most 128 pictures; past that, the one shown longest ago makes room, and it is recorded again when it comes back.
  • A clip or a streamed segment carries at most 128 KiB of pictures, counting every copy in its snapshot and its changes. The SDKs handle a segment that would carry more in different ways:
    • iOS ends the streamed segment at that frame and starts the next one there, with its own allowance, so the pictures keep showing while a grid of pictures scrolls. This sends more. A clip that still carries more, a single screen with more pictures than that, shows placeholders.
    • Android and Flutter keep the segment and show placeholders for all of its pictures, with its layout, text and taps intact. The next segment starts with a fresh allowance.
  • A session uploads at most 4 MiB of pictures; past that, new images are placeholders. A picture is counted once per session, when a segment that carries it is first uploaded, so a session that only buffers spends nothing. This is not a cap on the upload: every segment starts with the whole screen, so a picture is sent again with each clip or segment that shows it, within the 128 KiB a segment carries and the session's 50 MiB of replay.
  • Pictures are encoded off the main thread, so the first frame that shows an image has its placeholder and a later frame the picture.
  • An image inside a mask is never captured: nothing of it is read or encoded.
  • Each session reports the policy it started with (traceway.replay.images) and the picture bytes it encoded (traceway.replay.image_bytes).

What is recorded on Android:

  • The bitmap an ImageView shows through a BitmapDrawable (the top bitmap of a layer drawable, as a Glide crossfade shows it), and bitmap backgrounds.
  • Vector drawables, shapes and small icons keep their usual look whatever the policy; animated images are not recorded frame by frame.
  • Jetpack Compose images stay placeholders: the semantics tree that Compose screens are recorded from holds no pixels.
  • A picture's style stays in the recording for 30 seconds after its view left the screen, so scrolling back does not encode it again.

Step 4: Choose which sessions upload replay

What uploads by default

Out of the box, replay is uploaded only for sessions that had an error. The built-in trigger fires on every exception and uploads:

  • the replay of up to the last 30 seconds, cut to the frames the device holds, as the exception's clip;
  • the breadcrumbs of the last 10 minutes: logs, requests, screens, taps and events.

Clips are rationed to one every 5 seconds and 20 per session. The exceptions in between still get their breadcrumbs. An app that never throws uploads no replay at all, only its session records and metrics.

Record every session or a sample

To see sessions that had no error, stream their replay. There are two ways:

  • In the app, recordAllSessions streams every breadcrumb signal and the replay of every session. It suits a debug build or a small test group; in a production app it uploads a lot.
  • From the dashboard, a rule whose Signals tab sets Session replay to Stream streams the replay of the devices it applies to. To record only a share of their sessions, add replay.sessionSampleRate on the rule's JSON tab. The choice is made per session id, so a session is recorded whole or not at all, and the sessions left out keep their error clips:
{
  "replay": { "mode": "stream", "sessionSampleRate": 0.1 }
}

Healthy session sample (%) on the Signals tab (sessions.baselineSampleRate) sends the breadcrumbs of a share of sessions all the time, so you can compare healthy sessions with failing ones. It does not stream replay.

In the app:

TracewayOptions(
    token = BuildConfig.TRACEWAY_TOKEN,
    screenCapture = true,
    recordAllSessions = true, // stream every session; for a debug build or a test group
)

Record a journey with a trigger

A recording trigger waits for a journey, a sequence of steps, and records the session when it happens: it uploads the replay and breadcrumbs the device holds from before the first step, then keeps recording for as long as you say. Build one on the dashboard:

  1. Open Data Collection in the project's sidebar, click New Rule (or edit a rule) and open the Triggers tab.
  2. Click Add recording trigger and give it a Trigger name.
  3. For each step, pick its Event and fill in what it matches: a View selector (or Widget selector in Flutter) for a tap, a Route pattern such as /orders/{id} for a navigation, or a Log message for a log line. Within seconds of previous step limits how long the user may take. Add step adds the next one.
  4. Set Replay lookback (seconds), how much of what happened before the journey to upload, and Continue recording (seconds), how long to stream after it. Cooldown (seconds) and Captures per session keep a journey the user repeats from recording again and again.
  5. Save the rule.
The rule dialog's Triggers tab: a recording trigger with a tap step and a navigation step, the replay lookback, how long to continue recording, the cooldown and the captures per session

Steps match in order, and events in between that match no step are ignored. Progress is kept on the device, so a journey still counts when the app restarts within the session. When a trigger fires, the session lists it on the Sessions page as a recording reason, with the steps that matched.

On Android the Event of a step is Tap, Hover (a mouse entering a view, on ChromeOS or in desktop mode; never a finger), Navigation or Log (a console line: System.out, Traceway.log, Logcat with the Gradle plugin, or a captureMessage). A trigger can also live in the app, in the collection document, with the same fields the dashboard writes:

TracewayOptions(
    token = BuildConfig.TRACEWAY_TOKEN,
    screenCapture = true,
    collection = mapOf(
        "triggers" to listOf(
            mapOf(
                "id" to "checkout-abandoned",
                "name" to "Opened checkout, then went back",
                "steps" to listOf(
                    mapOf("match" to mapOf("event" to mapOf("type" to "navigation", "value" to "/CheckoutActivity"))),
                    mapOf("match" to mapOf("event" to mapOf("type" to "click", "value" to "#back")), "withinSeconds" to 60),
                ),
                "actions" to listOf(
                    mapOf("type" to "capture", "replay" to true, "lookbackSeconds" to 30, "durationSeconds" to 120),
                ),
                "cooldownSeconds" to 60,
                "maxPerSession" to 3,
            ),
        ),
    ),
)

The trigger reference has every field, and Recording triggers walks through the builder.

Name the views a trigger can match

A tap step matches a view by a CSS-like selector. Give the views a journey goes through a stable name:

<!-- #pay, or MaterialButton#pay -->
<com.google.android.material.button.MaterialButton
    android:id="@+id/pay"
    android:text="Pay now" />
// ImageButton[label="Delete"]
deleteButton.contentDescription = "Delete"
 
// In Compose: #checkout-form
Column(Modifier.testTag("checkout-form")) { CheckoutForm() }

You rarely write a selector by hand: every tap is recorded with the selector of the view that handled it, and the session's Actions list shows it, ready to paste into a step. Ids and test tags survive copy changes, translations and R8, which renames classes in a minified build. The whole syntax is in Naming views.

Name your screens

A navigation step matches the path of the screen on top, and so do the screen names on issues and taps. Activities (/CheckoutActivity) and AndroidX fragments (/CartFragment) are screens with no code. A single-activity Compose app is one screen to Android until you hand its NavController to the SDK:

import com.tracewayapp.traceway.navigation.trackNavigation
 
val nav = rememberNavController()
LaunchedEffect(nav) { Traceway.trackNavigation(nav) }
NavHost(nav, startDestination = "orders") {
    composable("orders") { Orders() }
    composable("orders/{id}") { OrderDetail() } // the screen /orders/8841, route /orders/:id
}
  • A screen no NavController shows names itself: Modifier.tracewayScreen("/orders/$id", route = "/orders/:id") on its root.
  • Any other router calls Traceway.recordNavigation("/orders/8841", route = "/orders/:id"); Traceway.setRoute("/orders/:id") names the current screen's route template.

The details are in Naming screens.

Step 5: Capture one user or device from the dashboard

// After sign-in: captures can now target this user.
Traceway.setAttribute("user.id", user.id)
 
// This installation, for a capture of one device (service.instance.id).
// Null for a moment right after init, until the SDK has read it.
val instanceId = Traceway.getInstanceId()
 
// Ask for settings now instead of at the next poll.
Traceway.refreshConfig()

When one user reports a problem, record that user's next sessions without a release. A capture uploads what the device holds from its lookback, then streams breadcrumbs and replay until it expires.

  1. Make the user findable: set the user.id attribute once they sign in (code above). A capture can also target one installation by its instance id, or one session.
  2. Start the capture in one of three places:
    • on a session page, Capture this device (or Capture this session);
    • on an issue's event, Capture device, Capture user or Capture session;
    • on the Data Collection page, New Capture, for any attribute value.
  3. In the New Capture dialog, check the Target and Value, pick how long it runs (For: 15 minutes to 24 hours) and how much of the past to Include (Nothing earlier, Last minute, Last 10 minutes or Last hour), leave Record session replay on, and click New Capture.
The New Capture dialog: the target and its value, how long the capture runs, how much earlier data to include, and the Record session replay switch

A capture lasts at most 24 hours, and a project has at most 20 active at a time. The Captures list on the Data Collection page shows each one's progress, from delivered to the device to data received; cancel one there. Its lookback is uploaded once per installation, and the records sent while it runs carry its id (traceway.capture.ids). Replay uploaded for it counts in the session's replay budget, like error clips.

When the app picks it up. An Android app polls at start, every 5 minutes (every 60 seconds while a capture targets it), every time it returns to the foreground, and about 2 seconds after setAttribute. To start a capture on your own test device at once, send the app to the background and bring it back.

Step 6: Change collection remotely with Data Collection rules

A rule changes what the SDK collects on the devices it applies to, without a release. Every setting on this page has a field in a rule.

  1. Open Data Collection in the project's sidebar. The page lists the rules, in the order they apply, and the active captures.
The Data Collection page: the rules in the order they apply, each with its conditions and what it changes, and below them the active captures
  1. Click New Rule and give it a Name.
  2. On Applies to, choose the devices: Add condition for an attribute such as service.version, user.id or os.name, and Roll out to a share of them. Every condition has to match. A rule with no conditions applies to every device.
The rule dialog's Applies to tab: a condition on the app version and a rollout percentage
  1. On Signals, set what to change. For replay: Session replay (Off, Buffer or Stream), Replay images (Off, Wi‑Fi only or Always) and Healthy session sample (%). Inherit leaves a setting as the SDK defaults and the earlier rules have it.
The rule dialog's Signals tab: a mode for each signal, then Session replay, Replay images, Sessions, Performance metrics and the healthy session sample
  1. On Triggers, add recording triggers (Step 4). The JSON tab shows the rule as the settings document it sends, for the fields the form does not have, such as replay.sessionSampleRate and replay.maskAllInputs.
  2. Click New Rule. Devices pick it up at their next poll.

Rules apply in their order on the page: a later rule replaces the fields an earlier one set. Preview shows which rules a device matches and the settings it receives. The document a rule holds is the same one the app's collection option takes, so a policy can move between the app and the dashboard unchanged. See the settings reference for every field.

Replay type (replay.captureMode) is a Flutter setting: an Android app always records a wireframe.

Check that it works

Start the app with debug = true, so Logcat shows what the SDK does under the tag Traceway, and send a test error:

import kotlin.concurrent.thread
 
Traceway.captureException(RuntimeException("Test error from Traceway"))
thread { Traceway.flush() } // flush blocks; on the main thread it waits 2 s at most

Then look at what arrived:

  1. Open Issues: the test error has a Session Replay card with the clip of the seconds before it.
  2. Open Sessions and the session: the player plays the replay, and its header says Wireframe replay. A session recorded by a trigger lists it under Recording triggers, with the steps that matched.
A session page: the wireframe replay with its player controls, and the recording triggers that recorded the session
  1. If a rule or a capture should be in effect, open Logs and filter by the events the SDK reports about itself: traceway.config.applied (a settings document was applied), traceway.trigger.fired (a trigger fired) and traceway.capture.started (a capture started on the device).
  2. On the session's Overview, Failed replay uploads counts replay segments that never arrived and Diagnostic events dropped what the session budget cut. The session's own records (session.start, traceway.session.update) carry traceway.replay.images, the image policy the session started with, and traceway.replay.image_bytes, the picture bytes it uploaded; find them in Logs too.

To try it without the dashboard, start the app with remoteConfig off and a collection document that holds a capture trigger, or with recordAllSessions on.

What replay does not record

  • Compose images and colors. Compose screens are recorded from their semantics, which hold no pixels: images are placeholders, and since Compose does not expose its surface colors, a filled button takes the theme's primary color and other buttons and fields a neutral look.
  • Native and custom views. WebView, SurfaceView, TextureView, video and maps are labelled placeholders, and views that draw themselves (charts, a custom onDraw) are dashed outlines.
  • Taps in popups (menus, dropdowns) on Android 9 and later. The replay shows those windows, but Android no longer lets the SDK reach them, so tap steps cannot match inside them. Taps in dialogs and bottom sheets are recorded.
  • Class names in minified builds. R8 renames classes; a renamed class is named by its nearest superclass that kept its name. Ids, test tags and text are not renamed.
  • Budget. A session uploads at most 50 MiB and 10,000 events of replay, across its error clips and captures, and at most 4 MiB of pictures, each counted once when it is first uploaded. Past that, the SDK stops uploading replay for the session and reports it in a traceway.collection.health record.
  • Destination. Replay always goes to Traceway. With no token (standalone), nothing is recorded.
  • Wireframe, not pixels. The wireframe rebuilds what the app shows as HTML in the browser. Text is drawn in the browser's font, so lines may break a little differently, and views that draw themselves are outlines.

When it fails

SymptomCauseFix
Nothing arrives at allThe Application class is not registered in the manifest, or the token is empty (no TRACEWAY_TOKEN in local.properties or the environment)Add android:name to <application>; with debug = true, Logcat says why Traceway.init returned null
An issue has no replayscreenCapture is off, the clip ration (one per 5 seconds, 20 per session) was used up, or the session's replay budget is spentTurn screenCapture on; check Failed replay uploads on the session's Overview
Images are grey boxesThe effective policy is off, or wifi on a metered network, the image is masked, or it is a Compose imageCheck Replay images in your rules and replayImages
A Compose element is not maskedandroid:tag belongs to viewsUse Modifier.tracewayMask() or Modifier.testTag("traceway-mask")
A trigger never firesThe selector names a class R8 renamed, the tap was in a popup menu, or the Compose screens are not trackedCopy the selector from the session's Actions; prefer ids and test tags; call Traceway.trackNavigation
A capture never startsThe device has not polled since, or the target value is wrongBring the app back to the foreground, or call refreshConfig(); check getInstanceId()
The poll is answered 403The token belongs to a backend projectUse the token of the project you created for this app