magicRecentHttpEnricher function

String? magicRecentHttpEnricher(
  1. Element element,
  2. RefRegistry refs
)

Enricher: emits magicRecentHttp: <METHOD> <url> <status> <durationMs>ms,... for up to 5 most recent records in TelescopeStore.recentHttp.

Each entry surfaces method, the (optionally truncated) url, statusCode, and durationMs. URLs longer than 40 characters are truncated to a 37-character prefix followed by ... so the snapshot stays bounded.

Returns null when the telescope buffer is empty or the telescope classpath is not present — the TelescopeStore.recentHttp call is wrapped in try/catch so a missing-dep classpath collapses to a graceful null instead of bubbling up.

Implementation

String? magicRecentHttpEnricher(Element element, RefRegistry refs) {
  final List<HttpRequestRecord>? records = _safeReadRecentHttp();
  if (records == null || records.isEmpty) return null;

  final List<String> parts = records
      .map(
        (r) =>
            '${r.method} ${_truncateUrl(r.url)} '
            '${r.statusCode} ${r.durationMs}ms',
      )
      .toList(growable: false);
  return 'magicRecentHttp: ${parts.join(',')}';
}