send method
Sends an HTTP request and asynchronously returns the response.
Implementers should call BaseRequest.finalize to get the body of the
request as a ByteStream. They shouldn't make any assumptions about the
state of the stream; it could have data written to it asynchronously at a
later point, or it could already be closed when it's returned. Any
internal HTTP errors should be wrapped as ClientExceptions.
Implementation
@override
Future<http.StreamedResponse> send(http.BaseRequest request) async {
final id = const Uuid().v4(), timer = Stopwatch()..start();
final session = reporter._diagnostics.sessionId;
final allowed = reporter._canRecord;
void recordRequest(String name, Map<String, Object?> attributes) {
if (allowed && reporter._diagnostics.sessionId == session) {
reporter.record('network', name, {
...attributes,
if (actionId != null) 'actionId': actionId,
});
}
}
// Only method and host are automatic; path segments can contain personal identifiers.
recordRequest('${request.method} ${request.url.host}', {
'requestId': id,
'phase': 'start',
});
try {
final response = await inner.send(request);
recordRequest('Response headers', {
'phase': 'response',
'requestId': id,
'status': response.statusCode,
'headersElapsedMs': timer.elapsedMilliseconds,
});
return response;
} catch (e) {
recordRequest('Request failed', {
'phase': 'error',
'requestId': id,
'errorType': e.runtimeType.toString(),
'elapsedMs': timer.elapsedMilliseconds,
});
rethrow;
}
}