โ† All posts
GUIDE August 9, 2026 ยท 9 min read

Monitoring Flutter apps end-to-end with Sentrinel

SR
Sentrinel Team
Product & engineering

A step-by-step guide to adding real-time monitoring, error tracking, and distributed tracing to your Flutter application.

Why Monitor Your Flutter App?

When your mobile app talks to a backend, problems can originate on either side. A user reports "the app is slow" โ€” but is it the network, the API, or the database? Without connected telemetry, you're guessing.

Sentrinel gives you:

Prerequisites

  1. A Sentrinel account (free at sentrinel.dev)
  2. A Flutter project (Dart SDK >=3.0.0)
  3. A backend already monitored by Sentrinel (optional but recommended for full traces)

Step 1: Add the Package

Add to your pubspec.yaml:

dependencies:
  sentrinel:
    git:
      url: https://github.com/Zaga-ltd/sentinel_packages.git
      path: sentrinel_flutter

Run:

flutter pub get

Step 2: Create an API Key

  1. Go to app.sentrinel.dev
  2. Click Connect on your app (or create a new one)
  3. Click Create API Key
  4. Copy the key โ€” and if you lose it, Copy key on the keys table gets it back rather than making you mint a replacement

Step 3: Initialize in main.dart

import 'package:flutter/material.dart';
import 'package:sentrinel/sentrinel.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  Sentrinel.init(
    serverUrl: 'https://api.sentrinel.dev',
    appName: 'my-flutter-app',
    env: kReleaseMode ? 'prod' : 'dev',
    apiKey: const String.fromEnvironment('SENTRINEL_API_KEY'),
    // Your own backends: they receive traceparent and the user/install
    // headers. Third-party APIs get nothing.
    tracePropagationTargets: ['api.example.com'],
  );

  runApp(const MyApp());
}

Until someone signs in, each install is its own consumer, guest:<install id> โ€” no need to invent guest ids. When they sign in (and at launch, when a saved session is restored), say who it is; on sign-out, say nobody:

Sentrinel.identify(user.id);
Sentrinel.identify(null);

Building a Flutter app rather than a Dart CLI? Skip the manual wiring and use the sentrinel_flutter package โ€” see Full configuration below.

Tip: Use --dart-define to pass the API key at build time:

flutter run --dart-define=SENTRINEL_API_KEY=snt_mobile_your_key_here

Step 4: Wrap Your HTTP Client

Replace your http.Client with Sentrinel.httpClient():

import 'package:sentrinel/sentrinel.dart';
import 'package:http/http.dart' as http;

// Before:
final client = http.Client();

// After:
final client = Sentrinel.httpClient();

Every request through this client is now automatically recorded.

Using Dio?

Route Dio through the same client with the Dio team's dio_compatibility_layer, which turns any package:http client into a Dio adapter:

import 'package:dio/dio.dart';
import 'package:dio_compatibility_layer/dio_compatibility_layer.dart';
import 'package:sentrinel/sentrinel.dart';

final dio = Dio()..httpClientAdapter = ConversionLayerAdapter(Sentrinel.httpClient());

Step 5: Capture Errors

Run your app inside Sentrinel.guard, and hand Flutter's own handlers over โ€” Flutter catches build/layout/paint errors before any zone sees them:

import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';
import 'package:sentrinel/sentrinel.dart';

void main() => Sentrinel.guard(() {
      WidgetsFlutterBinding.ensureInitialized();
      Sentrinel.init(/* ... */);
      FlutterError.onError = (d) =>
          Sentrinel.flutterErrorHandler(d.exception, d.stack, silent: d.silent);
      PlatformDispatcher.instance.onError = (e, s) {
        Sentrinel.platformErrorHandler(e, s);
        return true;
      };
      runApp(const MyApp());
    });

These are reported as unhandled errors, sent within about a second โ€” not as crashes. A Flutter app keeps running after a throwing build method or an unawaited future's error, so they mark the session errored. Reserve captureError(e, s, fatal: true) for the moment the app is really about to die: that one is written to disk first and counts as a crash.

For caught errors in your code:

try {
  await api.submitPost(post);
} catch (e, stack) {
  Sentrinel.captureError(e, stack, path: 'submit_post');
  rethrow;
}

Background isolates need one extra argument

A zone handler covers the isolate it runs on. Isolate.spawn does not inherit it, and does not inherit the error listeners either โ€” so a worker that dies prints to stderr and reports nothing. Pass the port:

import 'dart:isolate';

await Isolate.spawn(parseLargePayload, bytes, onError: isolateErrorPort);

Easy to miss, because the failure mode is silence: a crashed background job looks exactly like one that never ran.

Step 6: Add Context

Who the user is goes through identify (Step 3). Everything else you want on every record โ€” tier, locale, screen โ€” goes on the context:

Sentrinel.setContext({
  'tier': user.subscriptionTier,
  'locale': Localizations.localeOf(context).languageCode,
});

// On logout
Sentrinel.clearContext();
Sentrinel.identify(null);

Step 7: End the Session on Background

The OS kills backgrounded apps without notice, and the next flush may never come. Tell Sentrinel when the app leaves and returns โ€” it ends the session with its duration, flushes, and resumes the same session if the user is back within 30 seconds. (sentrinel_flutter does this for you.)

class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
  @override
  void initState() {
    super.initState();
    WidgetsBinding.instance.addObserver(this);
  }

  @override
  void didChangeAppLifecycleState(AppLifecycleState state) {
    if (state == AppLifecycleState.resumed) {
      Sentrinel.onForeground();
    } else if (state == AppLifecycleState.paused ||
        state == AppLifecycleState.detached) {
      Sentrinel.onBackground();
    }
  }

  @override
  void dispose() {
    WidgetsBinding.instance.removeObserver(this);
    super.dispose();
  }
}

Step 8: Structured Logs

Write structured logs that appear in the Sentrinel dashboard:

Sentrinel.info('User signed in', category: 'auth', attributes: {
  'method': 'google',
});

Sentrinel.warn('Cache miss', category: 'cache', attributes: {
  'key': 'feed_v2',
});

Sentrinel.error('Payment failed', category: 'billing', attributes: {
  'orderId': order.id,
  'reason': 'insufficient_funds',
});

Full Example

import 'dart:async';
import 'package:flutter/material.dart';
import 'package:sentrinel/sentrinel.dart';
import 'package:http/http.dart' as http;

void main() => Sentrinel.guard(() {
      WidgetsFlutterBinding.ensureInitialized();

      Sentrinel.init(
        serverUrl: 'https://api.sentrinel.dev',
        appName: 'my-app',
        env: kReleaseMode ? 'prod' : 'dev',
        apiKey: const String.fromEnvironment('SENTRINEL_API_KEY'),
        tracePropagationTargets: ['api.example.com'],
      );
      FlutterError.onError = (d) =>
          Sentrinel.flutterErrorHandler(d.exception, d.stack, silent: d.silent);
      PlatformDispatcher.instance.onError = (e, s) {
        Sentrinel.platformErrorHandler(e, s);
        return true;
      };

      runApp(const MyApp());
    });

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
  @override
  void initState() {
    super.initState();
    WidgetsBinding.instance.addObserver(this);
  }

  @override
  void didChangeAppLifecycleState(AppLifecycleState state) {
    if (state == AppLifecycleState.resumed) {
      Sentrinel.onForeground();
    } else if (state == AppLifecycleState.paused) {
      Sentrinel.onBackground();
    }
  }

  @override
  void dispose() {
    WidgetsBinding.instance.removeObserver(this);
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: Center(
          child: ElevatedButton(
            onPressed: () async {
              final client = Sentrinel.httpClient();
              final res = await client.get(
                Uri.parse('https://api.example.com/posts'),
              );
              // Process response...
            },
            child: const Text('Load Posts'),
          ),
        ),
      ),
    );
  }
}

Distributed Tracing

When your Flutter app calls a backend listed in tracePropagationTargets, the SDK sends a traceparent header. This connects the mobile request to the server-side trace โ€” you can see the full journey from tap to database query in one timeline.

The list is the one piece of configuration: it is empty by default, so trace ids and user ids never go to a third-party API you happen to call. Name your own hosts, and use the same appName on both sides.

What You Get in the Dashboard

After integrating, you'll see:


Full configuration โ€” collect everything

The steps above give you the basics. To collect every signal โ€” HTTP requests, crashes, release health, performance frames, structured logs, context, and distributed tracing โ€” use this complete configuration:

import 'package:flutter/material.dart';
import 'package:sentrinel_flutter/sentrinel_flutter.dart';

void main() => SentrinelFlutter.run(
  options: SentrinelOptions(
    serverUrl: 'https://api.sentrinel.dev',
    appName: 'my-app',
    env: 'prod',
    apiKey: const String.fromEnvironment('SENTRINEL_API_KEY'),
    release: '1.4.2',              // critical for release health
    tracePropagationTargets: ['api.example.com'],  // your backends only
    flushInterval: Duration(seconds: 30),
  ),
  app: () => runApp(const MyApp()),
);

// Backgrounding is handled for you: the session ends with its duration and
// everything is flushed before the OS can kill the app.

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      // Navigation tracking + breadcrumbs
      navigatorObservers: [SentrinelNavigatorObserver()],
      home: Scaffold(
        body: Center(
          child: ElevatedButton(
            onPressed: () async {
              final client = Sentrinel.httpClient();
              final res = await client.get(
                Uri.parse('https://api.example.com/posts'),
              );
            },
            child: const Text('Load Posts'),
          ),
        ),
      ),
    );
  }
}

What each piece gives you

Setup step What it enables Dashboard page
SentrinelFlutter.run() with release Crash-free rate per release Release Health
SentrinelNavigatorObserver() Screen navigation breadcrumbs Issues (breadcrumb trail)
Sentrinel.httpClient() + tracePropagationTargets HTTP request recording + traceparent to your backends Traffic, Traces, Request Logs
Automatic lifecycle tracking Session ended and flushed on background, so an OS kill is not abnormal Release Health
Sentrinel.identify(user.id) Requests, errors, logs and events filed under the person Consumers, Users
Sentrinel.setContext({...}) Tier/locale/screen on every record Request Logs (Details tab)
Sentrinel.info/warn/error(...) Structured logs Logs
Sentrinel.captureError(...) Caught exceptions with stack traces Issues

Capturing errors

// Uncaught errors are caught for you by SentrinelFlutter.run โ€” reported as
// unhandled errors, not crashes, because the app keeps running.

// Caught errors
try {
  await api.submitPost(post);
} catch (e, stack) {
  Sentrinel.captureError(e, stack, path: 'submit_post');
  rethrow;
}

Identity and context

// After sign-in, and at launch when a saved session is restored
Sentrinel.identify(user.id);
Sentrinel.setContext({
  'tier': user.subscriptionTier,
  'locale': Localizations.localeOf(context).languageCode,
});

// On sign-out โ€” back to guest:<install id>
Sentrinel.identify(null);
Sentrinel.clearContext();

Structured logs

Sentrinel.info('User signed in', category: 'auth', attributes: {
  'method': 'google',
});

Sentrinel.warn('Cache miss', category: 'cache', attributes: {
  'key': 'feed_v2',
});

Sentrinel.error('Payment failed', category: 'billing', attributes: {
  'orderId': order.id,
  'reason': 'insufficient_funds',
});

Custom breadcrumbs

Sentrinel.addBreadcrumb('tapped pay', category: 'ui', data: {'amount': 42});

Backend setup (for connected traces)

For the full mobile โ†’ backend trace to work, your backend also needs the Sentrinel plugin. Here's the Elysia config that pairs with the Flutter setup:

import { Elysia } from "elysia";
import { sentrinelPlugin } from "@sentrinel/plugin";

new Elysia()
  .use(sentrinelPlugin({
    serverUrl: "http://localhost:3001",
    appName: "my-api",
    env: "prod",
    apiKey: process.env.SENTRINEL_API_KEY,
    version: process.env.GIT_SHA,
    requestLogging: {
      enabled: true,
      sampleRate: 1.0,
      slowRequestThresholdMs: 500,
      logRequestHeaders: true,
      logRequestBody: true,
      logResponseBody: true,
    },
    logCapture: { enabled: true, minLevel: "debug" },
    logging: { minLevel: "debug", echo: true },
  }))
  .get("/", () => "hello")
  .listen(3000);

Put the backend's host in the app's tracePropagationTargets and the Flutter SDK sends it traceparent, x-sentrinel-consumer and x-sentrinel-device โ€” the backend continues the same trace and files the request under the same person and install as the phone did.

For the complete reference covering every option, every signal, and every dashboard page โ€” see FULL_CONFIG.md.

Since this was written

The Flutter SDK now covers the questions a mobile team actually asks after a release. Each of these is in the mobile guide; the short version:

Is this release crashing? Pass release: to init and every session and crash is recorded against the version. Crash-free sessions and crash-free users, per release, against the previous one.

Sentrinel.init(
  serverUrl: 'https://api.sentrinel.dev',
  apiKey: 'snt_mobile_โ€ฆ',
  appName: 'shop-app',
  env: 'prod',
  release: '2.4.1+318',
);

The crash survives the crash. A fatal error is written to disk before the call returns, sent at once, and removed from disk only once the server has it โ€” if the process dies first, the next launch delivers it, with the last twenty-five breadcrumbs that led to it. Framework and zone errors, which a Flutter app survives, are reported as unhandled errors within a second and mark the session errored rather than crashed.

Start-up and frames. Start-to-first-frame, and slow and frozen frames, per session and per release.

What people did. track, screen and identify feed funnels, retention and top screens โ€” deliberately separate from logs, and with an anonymous id that persists on disk so a user is the same user across launches:

Sentrinel.screen('Cart');
Sentrinel.track('checkout_started', properties: {'cart_value': 42});
Sentrinel.identify('user_42');

A mobile key. The key in your bundle is public, so issue a Mobile app key: it can send only what a phone sends, and a leaked one cannot post a replay, reach the database collector, or read anything. Keys issued before kinds existed keep working as they were. Why keys are bound to one integration.

The longer treatment is Release health for Flutter.

Next Steps