-
Notifications
You must be signed in to change notification settings - Fork 4.9k
opentelemetry tracer: implement TraceIDRatioBased and ParentBased samplers #37787
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
Conversation
CC @envoyproxy/api-shepherds: Your approval is needed for changes made to |
e186869
to
b6bfb74
Compare
the warning is not relevant this is the important line Code coverage for source/extensions/tracers/opentelemetry/samplers/trace_id_ratio_based is lower than limit of 96.6 (84.8) /coverage |
Coverage for this Pull Request will be rendered here: https://storage.googleapis.com/envoy-pr/37787/coverage/index.html The coverage results are (re-)rendered each time the CI |
1573f58
to
07cb847
Compare
Thanks for your guidance, dear @phlax. Tests are passing now. |
Thanks for the contribution. Please read the https://github.com/envoyproxy/envoy/blob/main/CONTRIBUTING.md and https://github.com/envoyproxy/envoy/blob/main/EXTENSION_POLICY.md to get more infomation about adding new extensions to see if the new extensions meet the requirement or not. Thanks again! |
07cb847
to
d70cd7e
Compare
Thanks for the links, @wbpcode! I’ve reviewed them and made the necessary adjustments to my PR. However, just to clarify, my PR doesn't add a new extension; rather, it implements two missing samplers for the OpenTelemetry tracer extension. Could you please let me know if that matches your expectations? |
If you get a chance, I'd appreciate any feedback or comments when you have time. No rush, I understand you're busy. |
Sorry for the delay. I skipped messages from community these two days. It's no doubt this add some new extensions. Although these extensions are not top level extensions but sub extensions for opentelmetry. But it doesn't change to much the characteristics. So, at least, we should ensure the current owners of opentelmetry @AlexanderEllis @yanavlasov are willing to maintain these new two extensions. |
/wait-any |
I would appreciate it if you took a look at this when you have a moment. |
Signed-off-by: therealak12 <[email protected]>
Signed-off-by: therealak12 <[email protected]>
uint64_t ratioToThreshold(double ratio) noexcept { | ||
const uint64_t MAX_VALUE = Envoy::ProtobufPercentHelper::fractionalPercentDenominatorToInt( | ||
envoy::type::v3::FractionalPercent::MILLION); | ||
|
||
if (ratio <= 0.0) { | ||
return 0; | ||
} | ||
if (ratio >= 1.0) { | ||
return MAX_VALUE; | ||
} | ||
|
||
return static_cast<uint64_t>(ratio * static_cast<double>(MAX_VALUE)); | ||
} |
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.
I actually didn't get this. If we have used fractionl percent helper here, why not use the envoy.type.v3.FractionalPercent
directly and use evaluateFractionalPercent
to get the decsion?
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.
I refactored the code to use FractionalPercent
and evaluateFractionalPercent
.
Hope it's what you meant!
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.
Hi @wbpcode,
would you mind taking another look at the code?
fd712d3
to
8969d25
Compare
Signed-off-by: therealak12 <[email protected]>
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 overall with only one nit comment. Thanks for the update!!!
api/envoy/extensions/tracers/opentelemetry/samplers/v3/trace_id_ratio_based_sampler.proto
Outdated
Show resolved
Hide resolved
…d_ratio_based_sampler.proto Co-authored-by: code <[email protected]> Signed-off-by: Ahmad Karimi <[email protected]>
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.
Sorry, I forget a comment.
uint64_t traceIdToUint64(const std::string& trace_id) noexcept { | ||
uint8_t buffer[8] = {0}; | ||
for (size_t i = 0; i < 8; ++i) { | ||
std::string byte_string = trace_id.substr(i * 2, 2); | ||
buffer[i] = static_cast<uint8_t>(std::stoul(byte_string, nullptr, 16)); | ||
} | ||
|
||
uint64_t first_8_bytes = 0; | ||
Envoy::safeMemcpyUnsafeSrc(&first_8_bytes, buffer); | ||
|
||
return first_8_bytes; | ||
} |
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.
Sorry, I forget this. Should we check the length of trace id here to ensure the trace id have enough data?
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.
I remember at the time of creating this PR I saw somewhere else in the code checks this.
However, please let me ensure. I'll share the update in this thread.
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.
There were no explicit checks previously, and I assumed the trace ID would always be valid, which, of course, was an unsafe assumption.
The necessary check has now been added.
Signed-off-by: therealak12 <[email protected]>
Signed-off-by: therealak12 <[email protected]>
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 with one nit comment. I think we can land this today or tomorrow. :) Thanks again for all your great contribution.
source/extensions/tracers/opentelemetry/samplers/trace_id_ratio_based/BUILD
Outdated
Show resolved
Hide resolved
…o_based/BUILD Co-authored-by: code <[email protected]> Signed-off-by: Ahmad Karimi <[email protected]>
Thanks for the review! I've addressed your comment - please let me know if you'd like any further adjustments. |
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. Thanks.
Commit Message: implement TraceIDRatioBased and ParentBased samplers
Additional Description:
A previous issue existed for adding opentelemetry samplers to Envoy so I didn't create a new one. The PR at hand implements two of these samplers.
The implementation and testing strategies are inspired by the OTEL's Go and CPP SDKs.
Risk Level: Low
Testing: The PR has unit and integration tests which I've run locally.
Docs Changes:
Release Notes:
Platform Specific Features: