Closed
Description
- 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++;
}
}