otel_bloc 0.3.0
otel_bloc: ^0.3.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.3.0 - 2026-10-11 #
Added #
otelContextTransformer, which runs each Bloc event handler in the OpenTelemetry context that was current when the event was added. A span made current aroundbloc.add(...)now parents the handler's spans (and anything it awaits) and thebloc.transitionspan. Install withBloc.transformer = otelContextTransformer(Bloc.transformer).OTelBlocObserver(propagateContext: ...), defaulttrue: the observer's newonEventhook captures the caller's context for the transformer.
Changed #
- Requires
dartastic_opentelemetry_api >=1.0.0-rc.4 <1.0.0-rc.5. - Breaking: depends on
dartastic_opentelemetry_apionly, no longer on the SDK. The application chooses and initializes the OpenTelemetry SDK. Parameters and fields typed with SDK classes now use the API types (APITracer,APISpan,APILogger, ...); SDK instances are still accepted wherever an API type is expected.
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.