Adding OTel to Your App
Add OpenTelemetry Dart to a Flutter app or a Dart server in three steps: add the packages, initialize once at startup, and give the build your OTLP endpoint and token. Your traces, logs and metrics arrive in your Observatory.
What you need
- The right Flutter and Dart. Building Your First App lists what each package needs.
- An OTLP token. In the Control Room, open Tokens, choose Generate, then OTLP. It is shown once: keep it in your password manager or CI secrets. For Flutter web, use a Browser OTLP token instead (Browser OTLP).
- Your OTLP endpoint:
https://otlp.<your-org>.fex.flutterrific.io. - Access to FEx Pub for the packages:
dart pub token add https://pub.fex.flutterrific.iowith a Pub token.
A Flutter app
Add the two packages to pubspec.yaml. They are released together and stay on one version:
dependencies:
dartastic_opentelemetry_native:
hosted: https://pub.fex.flutterrific.io
version: 1.22.4
dartastic_opentelemetry_native_flutter:
hosted: https://pub.fex.flutterrific.io
version: 1.22.4Initialize once, before runApp:
import 'package:dartastic_opentelemetry_native/dartastic_opentelemetry_native.dart';
import 'package:dartastic_opentelemetry_native_flutter/dartastic_opentelemetry_native_flutter.dart';
import 'package:flutter/material.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await DOTel.initialize(
serviceName: 'checkout-app',
serviceVersion: '1.4.0',
);
runApp(MaterialApp(
navigatorObservers: [DartasticViewObserver()], // screen views
home: const HomeScreen(),
));
}serviceNamenames your app in the Observatory. Pick a name people recognize; it does not have to be your package name.app.build_idis your app's build identity. The Flutter package sets it for you, from your app's version and build number (Your build id). Crashes and release comparisons group by it.DartasticViewObserverrecords a screen view each time a route is pushed, and how long each screen was open.
Give the build your endpoint and token with --dart-define. A phone app doesn't see your shell's environment, so the defines are how the values reach it. Keep the token out of source control: put it in an environment variable on your machine or in CI, and pass that.
flutter run --release \
--dart-define=OTEL_EXPORTER_OTLP_ENDPOINT=https://otlp.<your-org>.fex.flutterrific.io \
--dart-define=OTEL_EXPORTER_OTLP_HEADERS="authorization=Bearer $FEX_OTLP_TOKEN"These are the standard OpenTelemetry variables. Keep authorization lowercase: it works for every protocol. An OTLP token can only send telemetry to your organization: it reads nothing and changes nothing.
Once DOTel.initialize completes, it records with no further code:
- a session for every visit, on every span and log record;
- taps, and how quickly the app responds to them;
- screen views, through
DartasticViewObserver; - and, as your plan includes them, crashes, frozen UI, jank and vitals.
Your build id
The build id comes from the version and build number each platform reports for your app:
| Your app's version | Android | iOS |
|---|---|---|
version: 1.4.0+27 in pubspec.yaml | 1.4.0+27 | 1.4.0+27 |
version: 1.4.0 in pubspec.yaml | 1.4.0+1 | 1.4.0 |
--build-name=1.4.0 --build-number=27 | 1.4.0+27 | 1.4.0+27 |
Android adds +1 to a version with no build number, because that is Flutter's default build number there. For one build id on every platform, give your version a build number (1.4.0+27).
A Dart server
A Dart server or command-line app needs the one package:
dependencies:
dartastic_opentelemetry_native:
hosted: https://pub.fex.flutterrific.io
version: 1.22.4import 'package:dartastic_opentelemetry_native/dartastic_opentelemetry_native.dart';
Future<void> main() async {
await DOTel.initialize(
serviceName: 'orders-api',
serviceVersion: '2.3.1',
);
// ... start your server ...
}On a server, the same two variables come from the environment:
export OTEL_EXPORTER_OTLP_ENDPOINT=https://otlp.<your-org>.fex.flutterrific.io
export OTEL_EXPORTER_OTLP_HEADERS="authorization=Bearer $FEX_OTLP_TOKEN"
dart run bin/server.dartTelemetry never breaks your app
OpenTelemetry's rule is that telemetry must never throw an error into your code at runtime. FEx follows it everywhere. When something goes wrong inside telemetry (an endpoint that can't be reached, an attribute with a bad value, an export that fails), the error is reported to the OpenTelemetry error handler and logged, and your app keeps running.
To see those reports in your own logging or crash reporting, install your own handler. It works whether you call it before or after DOTel.initialize:
// Before DOTel.initialize: send telemetry's own errors to your logging
// or crash reporting. OTel calls it instead of throwing into your code.
OTelAPI.setErrorHandler((error, stackTrace) {
myLogger.warning('OpenTelemetry: $error', error, stackTrace);
});- Without a handler, the errors are logged with OpenTelemetry's own log (
OTEL_LOG_LEVELsets how much it says). - A handler of your own is the one place an error may be rethrown, for example to fail fast in a test build. In production, log and return.
See it arrive
Run your app and use it for a minute, then open the Observatory's Traces or Logs: your serviceName is there (Observatory).
| What you see | What to do |
|---|---|
| Nothing arrives | Check the endpoint. Run once with --dart-define=OTEL_LOG_LEVEL=debug (or OTEL_LOG_LEVEL=debug on a server): the log says OTelEnv: Parsed 1 header(s) when your token reached the app, with its value hidden. |
| Exports are refused with 401 | The token is wrong, revoked, or from another organization or deployment. Generate a new OTLP token in this organization's Control Room. |
| Flutter web sends nothing | Web needs a Browser OTLP token and your site's origin on it (Browser OTLP). |
How much you send
What your app sends counts toward your plan's ingress, on Cloud and Dedicated alike (Pricing). Traces, metrics and logs are on by default, and with none of these set nothing is sampled away. RUM screen capture is off by default. Each can be set by an environment variable and changed while your app runs. Your app decides when to change one, and calls the setter. There is no remote setting.
| Signal | Environment variable | While your app runs |
|---|---|---|
| Traces, in Dart | OTEL_TRACES_SAMPLER, OTEL_TRACES_SAMPLER_ARG | DOTel.tracesSampler |
| Traces, in the engine | DARTASTIC_ENGINE_SAMPLER, DARTASTIC_ENGINE_SAMPLER_RATIO, DARTASTIC_ENGINE_SAMPLER_ERROR_UP | DOTel.setEngineSampler() |
| Logs | DARTASTIC_LOGS_SAMPLE_RATE | DOTel.logsSampleRate |
| Metrics | DARTASTIC_METRICS_SAMPLE_RATE | DOTel.metricsSampleRate |
| RUM screen capture | DARTASTIC_RUM_SAMPLE_RATE | ReplayCaptureController.setRumSampleRate() |
On phones and the web, an environment variable is a --dart-define, set at build. A value in code beats the environment variable, and a change while your app runs beats both. A bad value goes to the OpenTelemetry error handler by name, and what was in force stays.
- Traces, in the engine: a change takes effect on the next batch. Spans a
tailsampler still holds go through the new sampler at once, so a change never loses them. - Logs: the rate is 0.0 to 1.0, decided by session, so a session is kept or dropped whole and raising the rate only adds sessions. A record of
ERRORor above always goes out, so crashes and severe ANRs always arrive. Screen views and taps are log records, so a session dropped here has none on its timeline. - Metrics: the rate is 0.0 to 1.0 and thins export cycles: at 0.25, one periodic cycle in four sends. Cumulative totals stay right.
DOTel.flushMetricsand shutdown always send, except at 0, which sends nothing. - RUM screen capture: the rate is 0.0 to 1.0, decided by session, and a change takes effect at once. Raising it only adds sessions, and lowering it only removes them. It covers what capture records: sessions, screens and taps are telemetry, and it doesn't touch them. A support recording is never sampled away. If the build and your code both set the rate, they must agree, or capture starts at 0. How much each captured session carries is its fidelity.
RUM fidelity
Fidelity is how much of the screen a replay carries. A replay counts toward your plan's ingress by the bytes it stores, so a lower level uses less of it.
| Fidelity | What a replay shows | A minute adds |
|---|---|---|
| Events | The timeline of screens, taps, network calls, spans, errors and crashes. No picture of the screen. | No replay bytes |
| Outline | A box for each major element. No text and no icons. | 62 KB |
| Wireframe | Text, icons and smaller controls too, each drawn as a box. Text shows as gray bars, and no characters leave the device. | 81 KB |
| Shadow | A real screenshot, blurred into blocks so text can't be read. | 430 KB |
| Pixel | The real screenshot, as the user saw it. | 597 KB |
| Pixel, typed text hidden | The screenshot, with what users type painted over. | 516 KB |
| Pixel, all text hidden | The screenshot, with all text painted over. | 438 KB |
Measured on the Alpine Trails demo app in November 2026. A five-minute Pixel session adds about 3 MB. Your app's screens will differ.
| Setting | Environment variable | While your app runs |
|---|---|---|
| Your app's level | DARTASTIC_RUM_FIDELITY | ReplayCaptureController.setFidelity() |
| One screen's level | None | setFidelity(level, route: '/checkout') |
| The highest level a build may send | DARTASTIC_RUM_FIDELITY_MAX | None |
| Text hidden at Pixel | None | ReplayCaptureController.setMasking() |
| Replay on or off | None | ReplayCaptureController.setMode() |
The levels are events, outline, wireframe, shadow and pixel. Each environment variable here is a --dart-define, set at build.
- Your app's level: if the build and your code both set it, they must agree. If they don't, or a value isn't a level, capture reports it and stays at Events. A support recording can raise the level, and a lower setting on a screen still holds on that screen.
- The highest level: the engine drops any replay record above it, whatever your app or a recording asks for. Use it to certify a build, for example one that can't capture pixels.
- Text hidden at Pixel:
ReplayMasking.textFieldshides what users type, andReplayMasking.allTexthides all text. - Replay on or off: replay is off until your app sets a mode.
ReplayMode.bufferUntilTriggerkeeps frames on the device and uploads them only when something goes wrong, so a session where nothing breaks uploads no replay at all.
Webviews
A web page inside your app, such as a checkout or a help center, can send its errors, requests, web vitals and events into the app's session, marked dartastic.telemetry.source webview. The page never exports, holds a token or sees an endpoint. It posts to your app, which checks every field and sends it through your app's own pipeline. Webview telemetry is a Pro feature.
Name the hosts you trust. A page matches on the exact host or a subdomain of an entry, and an empty list keeps the bridge off.
final bridge = DartasticWebviewBridge(
allowedHosts: ['checkout.example.com', 'example.com'],
serviceName: 'web-checkout',
transport: DartasticWebviewTransport.javaScriptChannel,
);Whatever an allowed page sends rides your app's telemetry credentials, and nothing scrubs it on the server. Your allowedHosts list and the bridge's size limits are the containment.
With webview_flutter (4.9.0 and later)
controller
// Required on Android: without unrestricted JavaScript there is no
// channel and no bridge.
..setJavaScriptMode(JavaScriptMode.unrestricted)
..addJavaScriptChannel(
bridge.channelName,
onMessageReceived: (m) => bridge.handleMessage(m.message),
)
..setNavigationDelegate(NavigationDelegate(
onPageStarted: (url) {
final shim = bridge.shimForUrl(url);
if (shim != null) controller.runJavaScript(shim);
},
// Required on iOS and macOS, and does nothing elsewhere.
onPageFinished: (url) {
final shim = bridge.shimForCommittedPage(url);
if (shim != null) controller.runJavaScript(shim);
},
));
// When the webview goes away:
bridge.notifyPageEnded();With flutter_inappwebview (6.1.5 and later)
Set transport: DartasticWebviewTransport.inAppWebViewHandler on the bridge, and leave JavaScript on.
InAppWebView(
initialUrlRequest: URLRequest(url: WebUri('https://checkout.example.com/')),
// Installed once: it captures from document start, and holds what it
// captures until the page is armed below.
initialUserScripts: UnmodifiableListView([
if (bridge.shimSource case final source?)
UserScript(
source: source,
injectionTime: UserScriptInjectionTime.AT_DOCUMENT_START,
forMainFrameOnly: true,
),
]),
onWebViewCreated: (controller) {
controller.addJavaScriptHandler(
handlerName: bridge.channelName,
callback: (args) =>
bridge.handleMessage(args.isEmpty ? '' : args.first as String),
);
},
onLoadStart: (controller, url) async {
if (url == null) return;
final source = bridge.shimForUrl(url.toString());
if (source != null) {
await controller.evaluateJavascript(source: source);
}
},
// Required on iOS and macOS, and does nothing elsewhere.
onPageCommitVisible: (controller, url) async {
if (url == null) return;
final source = bridge.shimForCommittedPage(url.toString());
if (source != null) {
await controller.evaluateJavascript(source: source);
}
},
)What arrives
- iOS and macOS:
shimForCommittedPage(1.32.0 and later) is required there, and does nothing elsewhere. Without it, a page on those platforms sends only its page span. - webview_flutter on iOS and macOS: errors and requests from before the page finishes loading aren't captured, and a page that never finishes sends only its span. Vitals still arrive, because the browser buffers them. When those matter, use flutter_inappwebview, which captures from document start.
- Web vitals: TTFB and FCP arrive everywhere. LCP, CLS, INP and long tasks arrive where the platform measures them. Android WebView measures all four. On iOS 27, WKWebView reports no CLS or long tasks, and LCP and INP aren't confirmed there. The bridge never makes up a value.
- Taps: a tap on a platform view, such as a webview or a map, is recorded but never counted as a dead or rage tap.