otel_bloc 0.2.0
otel_bloc: ^0.2.0 copied to clipboard
OpenTelemetry instrumentation for `package:bloc`. A `BlocObserver` emitting spans on every bloc event, state change and error, turning traces into a state-machine timeline.
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.2.0 - 2026-08-08 #
Changed #
- Dependency floors raised to
dartastic_opentelemetry ^1.1.0-beta.12anddartastic_opentelemetry_api ^1.0.0-rc.1. The previous floors declared compatibility with API versions that predate the semconv enums this package uses and could not actually resolve-and-compile. repositoryURL corrected to the canonicalDartasticorg casing so pub.dev repository verification succeeds.
Renamed #
- Ships as
otel_bloc, the pure-Dart core, matching the core/overlay pattern. The package only ever depended onbloc(the pure-Dart core thatflutter_blocre-exports), so it works for both bloc andflutter_blocapps. A slim Flutter overlay ships separately asotel_flutter_blocforflutter_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 optional integration test verifies the OTLP export round-trip against a local trace backend; it self-skips when no local stack is reachable.
- Runnable
example/main.dartdrives a bloc through an event inside an active parent span so the transition spans nest under it.