Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug bash: Logging correlation IDs doc does not specify the nginx context #8006

Merged
merged 2 commits into from
Oct 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions app/_hub/kong-inc/correlation-id/overview/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ You can see your correlation ID in the Nginx access log if you edit your Nginx l
To edit your Nginx parameters, do the following:

1. Locate [{{site.base_gateway}}'s template files](/gateway/latest/reference/configuration/#custom-nginx-templates) and make a copy of `nginx_kong.lua`.
1. Add a `log_format` section on the root level of the config file which includes the
1. Add a `log_format` section inside the `http` context of the config file and include the
`$http_Kong_Request_ID` variable.

In the following example, we create a new log format named `customformat`.
Expand All @@ -75,12 +75,18 @@ To edit your Nginx parameters, do the following:
[variables](http://nginx.org/en/docs/http/ngx_http_log_module.html):

```
log_format customformat '$remote_addr - $remote_user [$time_local] '
'"$request" $status $body_bytes_sent '
'"$http_referer" "$http_user_agent" '
'Kong-Request-ID="$http_Kong_Request_ID"';
http {
log_format customformat '$remote_addr - $remote_user [$time_local] '
'"$request" $status $body_bytes_sent '
'"$http_referer" "$http_user_agent" '
'Kong-Request-ID="$http_Kong_Request_ID"';
}
```

{:.note}
> **Note**: The `log_format` directive must be added inside the [HTTP context of the Nginx configuration file](/gateway/latest/production/logging/customize-gateway-logs/).
Otherwise, {{site.base_gateway}} will fail on startup due to invalid configuration.

1. Use your custom log format for the proxy access log phase. Locate the following line:

```
Expand Down Expand Up @@ -110,6 +116,7 @@ To edit your Nginx parameters, do the following:

You should now see Correlation ID entries in the access log.


Learn more in [Custom Nginx templates & embedding Kong](/gateway/latest/reference/configuration/#custom-nginx-templates--embedding-kong).

You can also use this plugin along with one of the [logging plugins](/hub/#logging), or store the ID on your backend.
Loading