Skip to content

API overview ​

Everything is imported from one library:

dart
import 'package:otel_zone/otel_zone.dart';

Start at OtelZone. OtelZoneConfig is everything a build knows about its own telemetry before it runs; OtelBridge is what decides which records leave the device.

No hosted API docs

otel_zone is not published to pub.dev (publish_to: 'none'), so there is no pub.dev API page. Every public member has a doc comment in lib/src; dart doc in a checkout renders them into doc/api/, which is git-ignored.

The entry point ​

OtelZone ​

One Talker, one OpenTelemetry SDK, and one guarded zone. Build it once, before runApp, and hold it where the whole app can reach it. Source.

MemberWhat it does
OtelZone(config, {talker, sink, nativeCrashSource, crashScreenSink})creates the talker and the bridge; starts nothing
configthe OtelZoneConfig this build was configured with
talkerthe one log and error sink; exists from construction
bridgethe OtelBridge in front of the OTel logs pipeline
isReadywhether the SDK came up; false before start() and after a failed one
runGuarded(body)runs body in a zone with all four uncaught-error channels wired to reportError
start({serviceVersion, buildId, resourceAttributes})brings up the SDK, drains native crashes, replays the spool; never throws
reportError(error, stackTrace, {context})the single reporting entry point for an error the app caught itself
safely(emit)runs emit only if the SDK is up, and never lets it throw
riverpodObserver({recordValues, recordArguments})the OTel ProviderObserver, or null when the SDK is not up
routeObserver({recordArguments})the OTel NavigatorObserver, or null when the SDK is not up
setEndUser(id) / endUserIdstamps enduser.id on spans and records from now on; null stops it
setCrashScreen(screen) / crashScreennames the screen a native crash would report as otel_zone.crashed.screen
startupSummary(serviceVersion, buildId, {replayed, nativeCrashes})the one line start() logs on success

Guides: Getting started, The guarded zone, Linking to an account, Which screen it died on.

Configuration ​

SymbolKindWhat it is
OtelZoneConfigclasseverything about a build's telemetry known before it runs — all options
RedactortypedefString Function(String input), the scrubber — guide
ExportFloorclassthe severity floor, plus what an unparseable value said — concept
parseLogLevelfunctionthe LogLevel a string names, case- and whitespace-insensitively, or null

ExportFloor members: ExportFloor.parse(name, {fallback}), ExportFloor.of(level), ExportFloor.defaultLevel (warning), level, unrecognised, carries(level), withholdsBreadcrumbs, ExportFloor.priorityOf(level).

Log pipeline building blocks ​

SymbolWhat it is
OtelBridgethe TalkerObserver that applies the floor, emits breadcrumbs, redacts, and forwards only once ready
SpoolingLogRecordExportera LogRecordExporter decorator that writes each batch to disk before sending, and replay()s what is left
RedactingSpanExportera SpanExporter that hands its delegate a scrubbed, read-only view of every span

OtelZone builds all three for you. They are public so they can be tested, and composed by an app that wires its own SDK.

Notable members:

  • OtelBridge({floor, history, loggerName, breadcrumbCount, breadcrumbLineLimit, redact, sink}), ready, carries(level).
  • SpoolingLogRecordExporter({delegate, directory, maxBatches, maxAge, maxBytes, maxAttempts, onWarning}), export, enqueue, replay, handledReports, forgetHandled, and SpoolingLogRecordExporter.replayedAttribute (otel_zone.replayed).
  • RedactingSpanExporter({delegate, redact, onDropped}).

Native crashes ​

SymbolWhat it is
NativeCrashSourceinterface: pending() and acknowledge(ids) — the seam the drain is tested through
PigeonNativeCrashSourcethe default NativeCrashSource, over the plugin's Pigeon channel
NativeCrashDrainturns the previous run's deaths into FATAL records, makes them durable, acknowledges them
NativeCrashReportone death, as the platform reports it (generated)
NativeCrashApithe generated Pigeon client for pending and acknowledge

NativeCrashDrain constants: eventCrash (device.crash), eventAnr (device.anr), crashedServiceVersion, crashedBuildId, crashedScreen. See Native crashes and the Pigeon channel.

The crash screen ​

SymbolWhat it is
CrashScreenSinkinterface: where setCrashScreen's value goes
PigeonCrashScreenSinkthe default sink, over the plugin's Pigeon channel
RecordingCrashScreenSinka test fake that keeps every screen in screens
CrashContextApithe generated Pigeon client for setCrashScreen
normalizeCrashScreentrims a screen, or returns null if it is empty, too long or has a control character
maxCrashScreenBytes64, the longest screen kept, in UTF-8 bytes

Testing ​

SymbolWhat it is
RecordingTalkerObservera TalkerObserver that keeps what it was given in records, oldest first
RecordingCrashScreenSinksee above

See Testing against it.

Released under the MIT License.