File tree Expand file tree Collapse file tree 2 files changed +13
-2
lines changed Expand file tree Collapse file tree 2 files changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -111,14 +111,15 @@ func (c *Cube) dispatch() error {
111
111
// Start starts recording an HTTP request.
112
112
func (c * Cube ) Start (r * http.Request , w http.ResponseWriter ) (request * CubeRequest ) {
113
113
request = & CubeRequest {
114
+ ID : RequestID (r , w ),
114
115
Time : time .Now (),
115
116
AppID : c .AppID ,
116
117
AppName : c .AppName ,
117
118
Host : r .Host ,
118
119
Path : r .URL .Path ,
119
120
Method : r .Method ,
120
121
UserAgent : r .UserAgent (),
121
- RemoteIP : realIP (r ),
122
+ RemoteIP : RealIP (r ),
122
123
}
123
124
request .ClientID = request .RemoteIP
124
125
atomic .AddInt64 (& c .activeRequests , 1 )
Original file line number Diff line number Diff line change @@ -11,7 +11,17 @@ const (
11
11
rfc3339Micro = "2006-01-02T15:04:05.000000Z07:00"
12
12
)
13
13
14
- func realIP (r * http.Request ) string {
14
+ // RequestID returns the request ID from the request or response.
15
+ func RequestID (r * http.Request , w http.ResponseWriter ) string {
16
+ id := r .Header .Get ("X-Request-ID" )
17
+ if id == "" {
18
+ id = w .Header ().Get ("X-Request-ID" )
19
+ }
20
+ return id
21
+ }
22
+
23
+ // RealIP returns the real IP from the request.
24
+ func RealIP (r * http.Request ) string {
15
25
ra := r .RemoteAddr
16
26
if ip := r .Header .Get ("X-Forwarded-For" ); ip != "" {
17
27
ra = strings .Split (ip , ", " )[0 ]
You can’t perform that action at this time.
0 commit comments