otel_bloc 0.1.0-beta.1
otel_bloc: ^0.1.0-beta.1 copied to clipboard
OpenTelemetry instrumentation for `package:bloc`. A `BlocObserver` subclass that emits short event spans on every bloc event / state change / error, turning your Tempo trace view into a state-machine [...]
Changelog #
All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.
0.1.0-beta.1 - 2026-05-14 #
Renamed #
- Renamed from
dartastic_flutter_bloc_oteltodartastic_bloc_otelto match the riverpod core/overlay pattern. The package only ever depended onbloc(the pure-Dart core thatflutter_blocre-exports); theflutter_prefix was misleading. A new slim Flutter overlay ships under the originaldartastic_flutter_bloc_otelname forflutter_bloc-based apps.
Added #
OTelBlocObserver— aBlocObserverthat emits one short span per Bloc/Cubit lifecycle event (onCreate,onTransitionfor Bloc,onChangefor Cubit,onError,onClose). Each span carries thebloc.*semconv attributes (bloc name + kind, event type, state before/after).onChangeis suppressed forBlocs becauseonTransitionfires immediately after it with strictly more info. Cubits get their ownonChangespans since they don't go through events.onErroris recorded viarecordExceptionthensetStatus(Error), in OTel-spec order.BlocSemantics— typed attribute-key enum implementingOTelSemantic, package-local because OTel has no upstream semantic convention for state-machine frameworks yet.- Constructor flags:
recordLifecycle(defaulttrue),recordTransitions(defaulttrue),recordEventValues(defaultfalse),recordStateValues(defaultfalse),valueAttributeMaxLength(default 256). - Targets
bloc: ^9.0.0. Works with bothflutter_blocapps (which re-exportbloc) and pure-Dartblocapps. - 6 unit tests covering: Bloc add → onCreate + onTransition + onClose (with onChange correctly suppressed), Cubit emit → onChange (with onTransition correctly absent), onError → Error status + exception event, recordEventValues + recordStateValues clipping, recordLifecycle false, recordTransitions false.
- 1 LGTM integration test polls Tempo round-trip.
- Example app produces a single
run-scenariostrace with 16 spans across a Bloc-happy-path, Cubit-happy-path, and a Bloc-error scenario.