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

OpenTelemetry.Extensions.AzureMonitor - Add sampleRate attribute to SamplingResult. #623

Merged

Conversation

rajkumar-rangaraj
Copy link
Contributor

Changes

Please provide a brief description of the changes here.

On successful sampling, add sampleRate attribute to SamplingResult.

TODO

  • Update CHANGELOG.md in a follow up PR.

For significant contributions please make sure you have completed the following items:

  • [ ] Appropriate CHANGELOG.md updated for non-trivial changes
  • [ ] Design discussion issue #

Copy link
Member

@cijothomas cijothomas left a 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

@utpilla utpilla added the comp:extensions.azuremonitor Things related to OpenTelemetry.Extensions.AzureMonitor label Sep 6, 2022
@@ -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)
Copy link
Contributor

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?

Copy link
Contributor Author

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?

Copy link
Contributor

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
{

}

Copy link
Contributor Author

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.

Copy link
Contributor

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

Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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.

@rajkumar-rangaraj
Copy link
Contributor Author

LGTM with a changelog

As specified in description TODO, want add changelog in a follow up PR as this project does not have any entry earlier.

@codecov
Copy link

codecov bot commented Sep 7, 2022

Codecov Report

Merging #623 (1ac5a2b) into main (0adee5a) will not change coverage.
The diff coverage is n/a.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #623   +/-   ##
=======================================
  Coverage   77.76%   77.76%           
=======================================
  Files         170      170           
  Lines        5163     5163           
=======================================
  Hits         4015     4015           
  Misses       1148     1148           

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp:extensions.azuremonitor Things related to OpenTelemetry.Extensions.AzureMonitor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants