Skip to content

Instantly share code, notes, and snippets.

@lisp-ceo
Created January 6, 2016 00:52
Show Gist options
  • Save lisp-ceo/522676e0df45d30169a2 to your computer and use it in GitHub Desktop.
Save lisp-ceo/522676e0df45d30169a2 to your computer and use it in GitHub Desktop.
Simple nginx lua script to add UUID to each request for end to end request tracking.
# Dependencies
# nginx_lua
# lua uuid module (luarocks install uuid)
http {
# this will be the request id
map $host $request_uuid {
default '';
}
log_format log_with_request_id '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" '
'request_id: $request_uuid';
server {
# your server block here ...
access_log /var/log/nginx.log log_with_request_id;
set_by_lua $request_uuid '
if ngx.var.http_x_request_id == nil then
return uuid()
else
return ngx.var.http_x_request_id
end
';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment