Skip to content

Commit 1a0a3bf

Browse files
committed
feat(api): add logging to root middleware for request tracing
Instruments the root middleware (`routes/_middleware.dart`) with logging to trace the start of the request lifecycle. This includes logging the generation of a unique `RequestId` for each incoming request, improving debuggability and traceability.
1 parent 3d56532 commit 1a0a3bf

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

routes/_middleware.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import 'package:ht_api/src/services/verification_code_storage_service.dart';
1111
import 'package:ht_data_repository/ht_data_repository.dart';
1212
import 'package:ht_email_repository/ht_email_repository.dart';
1313
import 'package:ht_shared/ht_shared.dart';
14+
import 'package:logging/logging.dart';
1415
import 'package:uuid/uuid.dart';
1516

1617
// --- Request ID Wrapper ---
@@ -56,6 +57,8 @@ class RequestId {
5657
}
5758

5859
// --- Middleware Definition ---
60+
final _log = Logger('RootMiddleware');
61+
5962
Handler middleware(Handler handler) {
6063
// This is the root middleware for the entire API. It's responsible for
6164
// providing all shared dependencies to the request context.
@@ -71,8 +74,10 @@ Handler middleware(Handler handler) {
7174
// It depends on the Uuid provider, so it must come after it.
7275
.use((innerHandler) {
7376
return (context) {
77+
_log.info('[REQ_LIFECYCLE] Request received. Generating RequestId...');
7478
final uuid = context.read<Uuid>();
7579
final requestId = RequestId(uuid.v4());
80+
_log.info('[REQ_LIFECYCLE] RequestId generated: ${requestId.id}');
7681
return innerHandler(context.provide<RequestId>(() => requestId));
7782
};
7883
})

0 commit comments

Comments
 (0)