From cd416317e6da2016bc48908b35b891c257ee7b0d Mon Sep 17 00:00:00 2001 From: "Abdulmhsen B. A. A" Date: Tue, 19 Apr 2022 03:16:40 +0300 Subject: [PATCH] Tie webhook and request debug logs to a request_id for better tracking. --- docker/files/cron.sh | 10 +++------- docker/files/nginx.conf | 9 ++++++--- src/Libs/helpers.php | 11 +++++++++-- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/docker/files/cron.sh b/docker/files/cron.sh index 64fd377a..46f8ee04 100755 --- a/docker/files/cron.sh +++ b/docker/files/cron.sh @@ -4,7 +4,7 @@ UID=$(id -u) NOW=$(date +"%Y_%m_%d") WS_UID=${WS_UID:-1000} WS_GID=${WS_GID:-1000} -WS_CRON_DEBUG=${WS_CRON_DEBUG:-'v'} +WS_CRON_DEBUG=${WS_CRON_DEBUG:-v} # check for data path. if [ -z "${WS_DATA_PATH}" ]; then @@ -23,11 +23,7 @@ if [ ! -d "${WS_DATA_PATH}/logs/cron/" ]; then fi if [ 0 == "${UID}" ]; then - OUTPUT=$(runuser -u www-data -- /usr/bin/console scheduler:run -o -${WS_CRON_DEBUG}) + runuser -u www-data -- /usr/bin/console scheduler:run -o -${WS_CRON_DEBUG} >>${LOGFILE} else - OUTPUT=$(/usr/bin/console scheduler:run -o -${WS_CRON_DEBUG}) -fi - -if [ ! -z "${OUTPUT}" ]; then - echo ${OUTPUT} >${LOGFILE} + /usr/bin/console scheduler:run -o -${WS_CRON_DEBUG} >>${LOGFILE} fi diff --git a/docker/files/nginx.conf b/docker/files/nginx.conf index f97f1075..0c093d41 100644 --- a/docker/files/nginx.conf +++ b/docker/files/nginx.conf @@ -23,9 +23,9 @@ http { '' close; } - log_format traceable '[$time_iso8601] response_status: $status - response_text: "$upstream_http_x_status" - request_key: "$http_x_apikey" ' - '- webhook_event: "$upstream_http_x_wh_event" - webhook_event: "$upstream_http_x_wh_type" ' - '- http_request: "$request":$body_bytes_sent - user_ip: $remote_addr - http_host: $http_host - user_agent: "$http_user_agent"'; + log_format traceable '[$time_iso8601] status: $status - text: "$upstream_http_x_status" - apikey: "$http_x_apikey" ' + '- event: "$upstream_http_x_wh_event" - type: "$upstream_http_x_wh_type" - id: "$request_id" ' + '- request: "$request":$body_bytes_sent - ip: $remote_addr - host: $http_host - agent: "$http_user_agent"'; server { listen 80 default_server; @@ -62,6 +62,9 @@ http { set $path_info $fastcgi_path_info; fastcgi_param PATH_INFO $path_info; + # For better request traking. + fastcgi_param X_REQUEST_ID $request_id; + fastcgi_index index.php; include fastcgi.conf; diff --git a/src/Libs/helpers.php b/src/Libs/helpers.php index ceeebbeb..8bd89bf0 100644 --- a/src/Libs/helpers.php +++ b/src/Libs/helpers.php @@ -238,7 +238,11 @@ if (!function_exists('saveWebhookPayload')) { ]; @file_put_contents( - Config::get('tmpDir') . '/webhooks/' . sprintf('webhook.%s.%d.json', $name, time()), + Config::get('tmpDir') . '/webhooks/' . sprintf( + 'webhook.%s.%d.json', + $name, + (string)ag($request->getServerParams(), 'X_REQUEST_ID', time()) + ), json_encode($content, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) ); } @@ -256,7 +260,10 @@ if (!function_exists('saveRequestPayload')) { ]; @file_put_contents( - Config::get('tmpDir') . '/webhooks/' . sprintf('request.%d.json', time()), + Config::get('tmpDir') . '/webhooks/' . sprintf( + 'request.%s.json', + (string)ag($request->getServerParams(), 'X_REQUEST_ID', time()) + ), json_encode($content, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES) ); }