install static method
void
install()
Idempotent install. Safe to call multiple times within the same isolate lifetime.
Implementation
static void install() {
// magic's AuthInterceptor writes the bearer token under whatever header
// `auth.token.header` names; the store only knows the default names, so
// a renamed header would reach the agent-facing buffer in the clear.
// Ahead of the guard because a store reset drops the addition while
// this integration stays installed.
CrumbsRedaction.hideRequestHeaders(<String>[
Config.get<String>('auth.token.header', 'Authorization') ??
'Authorization',
]);
if (_installed) return;
_installed = true;
CrumbsPlugin.registerHttpAdapter(MagicHttpFacadeAdapter());
CrumbsPlugin.registerWatcher(MagicModelWatcher());
CrumbsPlugin.registerWatcher(MagicCacheWatcher());
CrumbsPlugin.registerWatcher(MagicEventWatcher());
CrumbsPlugin.registerWatcher(MagicGateWatcher());
CrumbsPlugin.registerWatcher(MagicQueryWatcher());
CrumbsPlugin.registerWatcher(MagicLogWatcher());
// Bridge tapir's `wait_for_network_idle` poll loop to the crumbs
// in-flight count. Tapir keeps a function-pointer indirection so it
// does not need a hard dep on crumbs; we point that pointer at
// the real source as part of the install side-effect.
pendingHttpCountReader = () => CrumbsStore.pendingHttpCount;
// Bridge tapir's `console` + `exceptions` tools to crumbs' recent
// ring-buffer accessors. Project crumbs record shapes into the
// tapir handler envelope (logger/type/stackHead key remap).
recentLogsReader = (ConsoleRequest request) =>
CrumbsStore.recentLogs(limit: request.limit, minLevel: request.minLevel)
.map(
(r) => <String, dynamic>{
'level': r.level,
'message': r.message,
'time': r.time.toIso8601String(),
'logger': r.loggerName,
if (r.error != null) 'error': r.error,
},
)
.toList();
recentExceptionsReader = (ExceptionsRequest request) =>
CrumbsStore.recentExceptions(limit: request.limit)
.map(
(r) => <String, dynamic>{
'type': r.exceptionType,
'message': r.message,
'time': r.time.toIso8601String(),
if (r.stackTrace != null)
'stackHead': r.stackTrace!.split('\n').take(3).join('\n'),
},
)
.toList();
}