---
title: Keep sessions with errors
description: Keep sessions with errors
url: https://coralogix.com/docs/user-guides/rum/sdk-installation/flutter/mobile/configuration/sessions-with-errors/
product: ingress
feature: RUM Ingress
feature_id: rum.ingress
feature_identifier: ingress/rum.ingress
last_updated: '2026-12-02'
---

> Documentation index: https://coralogix.com/docs/llms.txt

# Keep sessions with errors

### Keep sessions with errors

Available in 0.23.0 and later. Keep a low `sdkSampler` and still get every session in which an error happens.

With `alwaysTrackSessionsWithErrors: true`, a session that is not sampled in is not dropped. Its events are kept on the device until an error is reported in it. Then everything it kept is sent, and the rest of the session is reported as it happens. A session that ends without an error sends nothing. A crash counts too: the events from before the crash are sent with it on the next launch.

To hold every sampled-in session this way too, set `onlyWithErrorConfig` to `CxSessionWithErrorConfig(enable: true)`. Sessions that `sdkSampler` leaves out behave as before unless `alwaysTrackSessionsWithErrors` is also on.

```Dart
import 'package:cx_flutter_plugin/cx_excludable_instrumentation.dart';
import 'package:cx_flutter_plugin/cx_exporter_options.dart';
import 'package:cx_flutter_plugin/cx_session_with_error_config.dart';

var options = CXExporterOptions(
  // ...other options...
  sdkSampler: 10,
  alwaysTrackSessionsWithErrors: true,
  onlyWithErrorConfig: const CxSessionWithErrorConfig(
    maxRumEvents: 5000,
    instrumentationsToSend: [CXExcludableInstrumentation.mobileVitals],
  ),
);
```

`CxSessionWithErrorConfig` fields:

| Field                  | Type                                | Description                                                                                                                                                                                                  |
| ---------------------- | ----------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| enable                 | `bool`                              | Holds every sampled-in session until an error. Defaults to `false`.                                                                                                                                          |
| maxRumEvents           | `int?`                              | How many events a session keeps while it waits for an error. Past this, what it kept is discarded and it starts again. When not set, the SDK uses `5000`; at most `20000`, and `0` or less uses the default. |
| instrumentationsToSend | `List<CXExcludableInstrumentation>` | Categories sent at once instead of being held. Defaults to empty: a held session sends nothing until it has an error.                                                                                        |

What to expect:

* An event with error severity triggers the session, including a network request that failed with an HTTP error status. `ignoreErrors` and `beforeSend` apply first, so an error they drop does not trigger it.
* While a session is held, `excludeFromSampling` sends nothing early. Use `instrumentationsToSend` for that.
* Session recording does not record in a held session.
* Every event carries `session_context.onlyWithErrorMode` (read-only), `true` in a held session. Events sent from the error on also carry `session_context.hasError: true`. The SDK sets `hasError` after `beforeSend` runs, so it is never present in your callback.
