dartastic_get_it_otel

OpenTelemetry instrumentation for package:get_it.

final getIt = GetIt.instance;

// App startup: track DI bootstrap cost
getIt.tracedRegisterSingletonAsync<DatabaseService>(() async {
  return DatabaseService(await openDatabase('app.db'));
});
getIt.tracedRegisterSingletonAsync<AuthService>(() async {
  return AuthService(await FirebaseAuth.instance);
});

await getIt.tracedAllReady();

// Test teardown / hot reload
await getIt.tracedReset();

Spans:

  • get_it register_async DatabaseService — covers the async factory's run time, parented to whatever span you're in
  • get_it all_ready GetIt — the total bootstrap wait
  • get_it reset GetIt
  • get_it get_async <T> — for getAsync<T>() resolution
  • get_it unregister <T>

All carry di.system = get_it, di.operation, di.type.

Why no sync get<T>() wrap?

Synchronous resolution is sub-microsecond on the hot path. A span per getIt<Foo>() would produce gigabytes of low-value trace data. Use the async variants when you want visibility, or wrap individual call sites yourself if you have a specific service whose lookup cost matters.

Suppression: runWithoutGetItInstrumentationAsync.

License

Apache 2.0

Libraries

otel_get_it
OpenTelemetry instrumentation for package:get_it.