Skip to content

Commit c22fa42

Browse files
committed
Better debugging
1 parent 378e65a commit c22fa42

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

parrot/parrot.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -479,9 +479,9 @@ func (p *Server) dynamicHandler(w http.ResponseWriter, r *http.Request) {
479479
return
480480
}
481481

482-
requestID := uuid.New().String()[0:8]
482+
routeCallID := uuid.New().String()[0:8]
483483
dynamicLogger.UpdateContext(func(c zerolog.Context) zerolog.Context {
484-
return c.Str("Request ID", requestID).Str("Route ID", route.ID())
484+
return c.Str("Route Call ID", routeCallID).Str("Route ID", route.ID())
485485
})
486486

487487
requestBody, err := io.ReadAll(r.Body)
@@ -494,12 +494,14 @@ func (p *Server) dynamicHandler(w http.ResponseWriter, r *http.Request) {
494494
}
495495

496496
routeCall := &RouteCall{
497-
RouteID: r.Method + ":" + r.URL.Path,
497+
RouteCallID: routeCallID,
498+
RouteID: r.Method + ":" + r.URL.Path,
498499
Request: &RouteCallRequest{
499-
Method: r.Method,
500-
URL: r.URL,
501-
Header: r.Header,
502-
Body: requestBody,
500+
Method: r.Method,
501+
URL: r.URL,
502+
Header: r.Header,
503+
Body: requestBody,
504+
RemoteAddr: r.RemoteAddr,
503505
},
504506
}
505507
recordingWriter := newResponseWriterRecorder(w)

parrot/recorder.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,25 @@ type Recorder struct {
2020
errChan chan error
2121
}
2222

23-
// RouteCall records that a route was called
23+
// RouteCall records when a route is called, the request and response
2424
type RouteCall struct {
25-
RouteID string `json:"route_id"`
26-
Request *RouteCallRequest `json:"request"`
25+
// RouteCallID is a unique identifier for the route call for help with debugging
26+
RouteCallID string `json:"route_call_id"`
27+
// RouteID is the identifier of the route that was called
28+
RouteID string `json:"route_id"`
29+
// Request is the request made to the route
30+
Request *RouteCallRequest `json:"request"`
31+
// Response is the response from the route
2732
Response *RouteCallResponse `json:"response"`
2833
}
2934

3035
// RouteCallRequest records the request made to a route
3136
type RouteCallRequest struct {
32-
Method string `json:"method"`
33-
URL *url.URL `json:"url"`
34-
Header http.Header `json:"header"`
35-
Body []byte `json:"body"`
37+
Method string `json:"method"`
38+
URL *url.URL `json:"url"`
39+
RemoteAddr string `json:"caller"`
40+
Header http.Header `json:"header"`
41+
Body []byte `json:"body"`
3642
}
3743

3844
// RouteCallResponse records the response from a route

0 commit comments

Comments
 (0)