-
Notifications
You must be signed in to change notification settings - Fork 297
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
OpenTelemetry.Extensions.AzureMonitor - Add sampleRate attribute to SamplingResult. #623
OpenTelemetry.Extensions.AzureMonitor - Add sampleRate attribute to SamplingResult. #623
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.
LGTM with a changelog
@@ -48,8 +59,26 @@ public ApplicationInsightsSampler(float samplingRatio) | |||
/// <returns>Returns whether or not we should sample telemetry in the form of a <see cref="SamplingResult"/> class.</returns> | |||
public override SamplingResult ShouldSample(in SamplingParameters samplingParameters) | |||
{ | |||
if (this.samplingRatio == 0) |
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.
Are we okay with the naive equality comparison for float
?
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 don't see an issue, do you think this could cause an issue?
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.
It depends on the sampler requirements. Do we want to sample and record for this value of sampling ratio 1.0000001
?
float samplingRatio = 1.0000001F;
if (samplingRatio == 1) // <- This is not true
{
}
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.
1.0000001
is an invalid valid. Guard in the constructor - Guard.ThrowIfOutOfRange((double)samplingRatio, min: 0.0, max: 1.0);
should throw an exception.
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.
In general, equality comparison of floating-point values is problematic: https://docs.microsoft.com/en-us/dotnet/api/system.double?view=net-6.0#testing-for-equality
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.
1.0000001
is an invalid valid. Guard in the constructor -Guard.ThrowIfOutOfRange((double)samplingRatio, min: 0.0, max: 1.0);
should throw an exception.
What about 0.9999999F
?
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.
This should not be treated as 1. Tested the behavior in a small test app, it works perfectly. I could understand the problem with float number, but it should not have impact on 0 and 1. As a follow up task we could add tests for this project to validate it.
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.
This should not be treated as 1.
I was essentially asking this.
I know that the current code does not treat it as 1. I just wanted to know if we should be treating 0.9999999F
as 1.0
and 0.00000001F
as 0.0
as when the user provides the samplingRatio, it might have been computed as result of other floating-point operation which might cause precision loss.
src/OpenTelemetry.Extensions.AzureMonitor/ApplicationInsightsSampler.cs
Outdated
Show resolved
Hide resolved
As specified in description TODO, want add changelog in a follow up PR as this project does not have any entry earlier. |
Changes
Please provide a brief description of the changes here.
On successful sampling, add
sampleRate
attribute toSamplingResult
.TODO
CHANGELOG.md
in a follow up PR.For significant contributions please make sure you have completed the following items:
[ ] AppropriateCHANGELOG.md
updated for non-trivial changes[ ] Design discussion issue #