-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
feat(request-id): add a request ID to logs and error templates #11308
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
samugi
force-pushed
the
feat/correlation-trace-request-id
branch
from
July 27, 2023 16:28
a37e3cc
to
5d39f87
Compare
samugi
force-pushed
the
feat/correlation-trace-request-id
branch
from
July 28, 2023 08:35
5d39f87
to
d466f6b
Compare
samugi
force-pushed
the
feat/correlation-trace-request-id
branch
4 times, most recently
from
July 31, 2023 16:46
ac7b065
to
c356dc1
Compare
samugi
force-pushed
the
feat/correlation-trace-request-id
branch
3 times, most recently
from
August 1, 2023 16:12
f0e69e2
to
384ddb6
Compare
samugi
changed the title
feat(request-id): request trace id
feat(request-id): add a request ID to logs and error templates
Aug 2, 2023
samugi
force-pushed
the
feat/correlation-trace-request-id
branch
3 times, most recently
from
August 8, 2023 11:25
3299bb4
to
34f98cf
Compare
samugi
force-pushed
the
feat/correlation-trace-request-id
branch
from
September 12, 2023 10:52
d9c2a69
to
3bf7bac
Compare
samugi
force-pushed
the
feat/correlation-trace-request-id
branch
2 times, most recently
from
September 12, 2023 14:54
08e888c
to
4f0fd27
Compare
samugi
force-pushed
the
feat/correlation-trace-request-id
branch
from
September 12, 2023 15:58
4f0fd27
to
8462d21
Compare
chronolaw
reviewed
Sep 13, 2023
chronolaw
reviewed
Sep 13, 2023
chronolaw
reviewed
Sep 14, 2023
samugi
force-pushed
the
feat/correlation-trace-request-id
branch
from
September 19, 2023 18:11
845790f
to
c958850
Compare
* Add a request ID (which matches the trace_id or correlation_id when available) to error templates and logs. * Bump lua-kong-nginx-module to version 0.7.0 * Use the new directive `lua_kong_error_log_request_id` introduced in 0.7.0 which adds the request id to the error log output
add unit tests add integration tests to cover zipkin as well make access_log include request_id by default refactoring and log messages
add request id to the default error templates
samugi
force-pushed
the
feat/correlation-trace-request-id
branch
2 times, most recently
from
September 19, 2023 18:43
26cd886
to
d1a9f29
Compare
samugi
force-pushed
the
feat/correlation-trace-request-id
branch
from
September 19, 2023 19:31
d1a9f29
to
e19f787
Compare
samugi
force-pushed
the
feat/correlation-trace-request-id
branch
from
September 19, 2023 21:25
e19f787
to
4b638b9
Compare
setting trace id from propagation allows to set the correct format of trace id depending on the headers format, instead of defauting to hex bump lua-kong-nginx-module to 0.7.1
samugi
force-pushed
the
feat/correlation-trace-request-id
branch
from
September 19, 2023 21:27
4b638b9
to
d280b41
Compare
github-actions
bot
added
the
author/community
PRs from the open-source community (not Kong Inc)
label
Sep 20, 2023
3 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
author/community
PRs from the open-source community (not Kong Inc)
core/logs
core/pdk
core/proxy
core/templates
core/tracing
plugins/correlation-id
size/XXL
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closed in favor of #11624
Summary
Add a request ID (which matches the trace_id or correlation_id when available) to error templates and logs.
Description
Error logs are populated with a unique identifier for the request (random generated 16 Bytes hex), using a format similar to the following:
The ID is stored in the Nginx variable
$kong_request_id
and can be used in theaccess_log
directive.Trace ID
When available, the request ID is replaced by the current request's trace ID. Trace IDs in Kong are generated during the
rewrite
phase, for each request, which means that when tracing is enabled the same request may log different IDs before and after the value is updated during therewrite
phase. In addition to that, in case of distributed tracing (requests incoming to Kong contain headers with tracing information, including the trace ID), the trace ID is updated by the Opentelemetry plugin during theaccess
phase. Whenever the Request ID is updated, a line is printed in the logs to notify about the update event, e.g.:setting request_id to: [new_id] for the current request, request_id: "[old_id]"
Example:
Request that provides the 4bf92f3577b34da6a3ce929d0e0e4736 trace ID via a tracing header:
Logs:
Error templates always display the updated Request ID.
Testing
Error templates & logs
Start Kong using an error template that includes two placeholders for parameters, the first will be populated with the error message, the second with the request ID. The builtin fixtures can be used to test this, similarly to the following example:
Request:
Response:
Access log
Example output:
Checklist
Full changelog
Issue reference
KAG-2034
FTI-4837