-
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
fix(tracing): ensure sampling decisions apply to correct trace ID #13275
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Codewise - looks good 👍
... but I'm missing a lot of context
Kong generates a temporary trace ID when spans are created, this trace ID can be overwritten if tracing headers are passed in the request. Before this change, the global sampling rate from kong.conf was applied to the temporary trace ID, which was only valid for traces created by Kong, and not in distributed tracing scenarios. This commit ensures the sampling decision is only taken once, after headers have been read, when the trace id is final. This ensures Kong's sampling decision matches that of other tracing systems and therefore guarantees that traces are not broken when sampling rates are set to the same values.
I removed a small part of the diff (one less change to the tracer). Initially I also wanted to ensure the sampler is only ran once, and removed it on span creation so that the sampling decision is only taken by the OTel plugin. On second thought I realized that could be breaking for any users who rely on the PDK's logic and are not using the OTel plugin, so I reduced the scope of this PR. All we want to fix this is that, during the access phase, both the local (plugin) and the global (kong.conf) sampling rates are taken into account (with precedence on the plugin) to take the sampling decision. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM after offline discussion
Co-authored-by: Qi <add_sp@outlook.com>
Successfully created cherry-pick PR for |
Summary
Kong generates a temporary trace ID when spans are created, this trace ID can be overwritten if tracing headers are passed in the request. Before this change, the global sampling rate from kong.conf was applied to the temporary trace ID, which was only valid for traces created by Kong, and not in distributed tracing scenarios.
This commit ensures the sampling decision always happens during the OTel plugin's access phase, so that it is done after headers have been read, when the trace id is final. This ensures Kong's sampling decision matches that of other tracing systems, to prevent broken traces.
Checklist
changelog/unreleased/kong
orskip-changelog
label added on PR if changelog is unnecessary. README.mdIssue reference
KAG-4785