Where I’m working now we have a rather complicated internal structure to our rather large web application and it’s sometime super hard to track down the problem – especially if a request triggers an API call.
I’ve modified our frontend configuration to pass a X-Trace-ID and all our logging/servers to include that trace id in any given request
set $tid $pid-$msec-$remote_addr-$connection-$request_id;
if ($http_x_trace_id) {
set $tid $http_x_trace_id;
}
proxy_set_header X-Trace-ID $tid;
fastcgi_param HTTP_X_TRACE_ID $tid;
Except when it comes to error logs, if anything goes wrong with a proxied request, we’re out of luck – well not any more :D
diff -dur nginx-1.11.6.org/src/http/ngx_http_request.c nginx-1.11.6/src/http/ngx_http_request.c
--- nginx-1.11.6.org/src/http/ngx_http_request.c2016-11-16 01:11:47.000000000 +1000
+++ nginx-1.11.6/src/http/ngx_http_request.c2016-12-05 21:18:16.000000000 +1000
@@ -118,6 +118,10 @@
offsetof(ngx_http_headers_in_t, content_type),
ngx_http_process_header_line },
+ { ngx_string("X-Trace-ID"),
+ offsetof(ngx_http_headers_in_t, x_trace_id),
+ ngx_http_process_header_line },
+
{ ngx_string("Range"), offsetof(ngx_http_headers_in_t, range),
ngx_http_process_header_line },
@@ -3656,5 +3660,11 @@
buf = p;
}
+ if (r->headers_in.x_trace_id) {
+ p = ngx_snprintf(buf, len, ", trace_id: \"%V\"",
+ &r->headers_in.x_trace_id->value);
+ buf = p;
+ }
+
return buf;
}
diff -dur nginx-1.11.6.org/src/http/ngx_http_request.h nginx-1.11.6/src/http/ngx_http_request.h
--- nginx-1.11.6.org/src/http/ngx_http_request.h2016-11-16 01:11:47.000000000 +1000
+++ nginx-1.11.6/src/http/ngx_http_request.h2016-12-05 21:33:07.000000000 +1000
@@ -185,6 +185,7 @@
ngx_table_elt_t *content_length;
ngx_table_elt_t *content_range;
ngx_table_elt_t *content_type;
+ ngx_table_elt_t *x_trace_id;
ngx_table_elt_t *range;
ngx_table_elt_t *if_range;
Apply this patch to nginx-1.11.6 and X-Trace-ID will appear in your logs if it’s available
your_ip_is_blacklisted_by sbl.spamhaus.org