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

Adaptive Sampler not working as expected #2742

Closed
vishweshbankwar opened this issue Feb 3, 2023 · 5 comments
Closed

Adaptive Sampler not working as expected #2742

vishweshbankwar opened this issue Feb 3, 2023 · 5 comments
Labels
Milestone

Comments

@vishweshbankwar
Copy link

vishweshbankwar commented Feb 3, 2023

  • List of NuGet packages and version that you are using:
  • "Microsoft.ApplicationInsights.WorkerService" Version="2.21.0"

Describe the bug

Adaptive sampler when used with activities with Recorded flag set to true (in case of OpenTelemetry this could be set via AlwaysOnSampler) results in high number of telemetry records to be ingested compared to activities with the flag set to false
A clear and concise description of what the bug is.

To Reproduce

internal class Program
    {
        static void Main(string[] args)
        {
            TelemetryConfiguration configuration = TelemetryConfiguration.CreateDefault();
            configuration.TelemetryInitializers.Add(new OperationCorrelationTelemetryInitializer());
            configuration.TelemetryChannel = new CustomChannel();
            configuration.InstrumentationKey = "ikey";
            var telemetryClient = new TelemetryClient(configuration);

            // Sampling
            var builder = configuration.DefaultTelemetrySink.TelemetryProcessorChainBuilder;
            builder.UseAdaptiveSampling();
            builder.Build();

            while (true)
            {
                for (int i = 0; i < 10000; i++)
                {
                    Activity act = new Activity("Parent");
                    // uncomment the following line to see more telemetryitems
                    // act.ActivityTraceFlags |= ActivityTraceFlags.Recorded;
                    act.Start();
                    var startTime = DateTime.UtcNow;
                    var timer = System.Diagnostics.Stopwatch.StartNew();
                    timer.Stop();
                    telemetryClient.TrackDependency("myDependencyType", "myDependencyCall", "myDependencyData", startTime, timer.Elapsed, true);

                    act.Stop();
                }
                telemetryClient.Flush();
                Thread.Sleep(1000);
            }
        }
    }

CustomChannel

internal class CustomChannel : ITelemetryChannel
    {
        public bool? DeveloperMode { get; set; } = true;
        public string EndpointAddress { get; set; } = "endpoint";

        static long telemetryCount = 0;

        public void Dispose()
        {
        }

        public void Flush()
        {
            Console.WriteLine("TelemetryCount: " + telemetryCount);
        }

        public void Send(ITelemetry item)
        {
            telemetryCount++;
        }
    }
@vishweshbankwar
Copy link
Author

For anyone encountering this, the workaround is to use Fixed rate sampling instead of Adaptive.

@vishweshbankwar
Copy link
Author

Beta package is now available with the fix https://www.nuget.org/packages/Microsoft.ApplicationInsights/2.22.0-beta3

@OsmondJiang
Copy link

@vishweshbankwar do you know when will this fix be shipped to a stable version?

@TimothyMothra TimothyMothra added this to the 2.22 milestone Apr 18, 2023
@TimothyMothra
Copy link
Member

Hi @OsmondJiang, we're targeting end of May for the next stable release.

@cijothomas
Copy link
Contributor

Closing as the issue is fixed #2742 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants