HttpTracker class
Singleton that collects, aggregates and persists HTTP request logs.
Use the interceptors (RuntimeInsightHttpOverrides, RuntimeInsightHttpClient, RuntimeInsightDioInterceptor) or the manual API (startRequest / endRequest) to feed data.
final id = HttpTracker.instance.startRequest('GET', 'https://api.example.com/users');
// ... perform request ...
HttpTracker.instance.endRequest(id, statusCode: 200, responseBytes: 1024);
Constructors
- HttpTracker({int maxLogs = 500})
Properties
- activeCount → int
-
Number of in-flight requests.
no setter
- avgResponseTimeMs → double
-
Average response time in milliseconds for completed requests.
no setter
- completedCount → int
-
Number of completed requests (status 1xx–3xx).
no setter
- enabled ↔ bool
-
Whether HTTP tracking is active. When
false, startRequest and endRequest are no-ops.getter/setter pair - errorRate → double
-
Error rate as a fraction (0.0 – 1.0).
no setter
- failedCount → int
-
Number of failed requests (4xx, 5xx, or exception).
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
-
logs
→ List<
HttpRequestLog> -
All logged requests, most recent first.
no setter
- maxLogs ↔ int
-
Maximum number of log entries kept in the ring buffer and on disk.
getter/setter pair
-
onChange
→ Stream<
void> -
A broadcast stream that fires whenever logs change (new request,
completion, clear, etc.). Useful for rebuilding UI.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- totalCount → int
-
Total number of logged requests (active + completed + failed).
no setter
Methods
-
clearLogs(
) → Future< void> - Clears all in-memory logs and the persisted file.
-
dispose(
) → void - Releases resources.
-
endRequest(
String id, {int? statusCode, int? responseBytes, String? error}) → void - Completes a previously started request.
-
exportFile(
String path) → Future< void> -
Exports the NDJSON log file to
path. -
exportLogsAsJson(
) → String - Exports all logs as a pretty-printed JSON string.
-
flush(
) → Future< void> - Flushes pending writes to disk.
-
init(
) → Future< void> - Loads persisted logs from disk. Called once by RuntimeInsight.enableHttpTracking.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
startRequest(
String method, String url, {int? requestBytes}) → String -
Begins tracking a new HTTP request. Returns a unique
idthat must be passed to endRequest when the response arrives. -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Properties
- instance → HttpTracker
-
Global shared instance.
final