public static TelemetryConfiguration ConfigureWithSampling(this TelemetryConfiguration configuration,
                                                                   AdaptiveSamplingWorker worker)
        {
            // Automatically collect dependency calls
            var dependencies = new DependencyTrackingTelemetryModule();

            dependencies.Initialize(configuration);
            // Automatically correlate all telemetry data with request
            configuration.TelemetryInitializers.Add(new OperationCorrelationTelemetryInitializer());


            // Build telemetry processing pipeline
            configuration.TelemetryProcessorChainBuilder
            // This telemetry processor will be executed
            // first for all telemetry items to calculate the size and # of items
            .Use((next) =>
            {
                return(new TelemetryRecordSizeProcessor(next, size => worker.OnCollectedItems(size)));
            })
            // This is a standard fixed sampling processor that'll let only 10%
            .Use((next) =>
            {
                return(new SamplingTelemetryProcessor(next)
                {
                    IncludedTypes = "Dependency",
                    SamplingPercentage = 10,
                });
            })
            // This is a standard adaptive sampling telemetry processor
            // that will sample in/out any telemetry item it receives
            .Use((next) =>
            {
                var settings = new SamplingPercentageEstimatorSettings
                {
                    MaxTelemetryItemsPerSecond        = 1,                       // Default: 5 calls/sec
                    SamplingPercentageIncreaseTimeout = TimeSpan.FromSeconds(1), // Default: 2 min
                    SamplingPercentageDecreaseTimeout = TimeSpan.FromSeconds(1), // Default: 30 sec
                    EvaluationInterval        = TimeSpan.FromSeconds(1),         // Default: 15 sec
                    InitialSamplingPercentage = 25,                              // Default: 100%
                };

                var adaptiveSamplingProcessor = new AdaptiveSamplingTelemetryProcessor(settings, new AdaptiveSamplingPercentageEvaluatedCallback(AdaptiveSamplingEvaluated), next)
                {
                    ExcludedTypes = "Event",   // Exclude custom events from being sampled
                };

                return(adaptiveSamplingProcessor);
            })
            // This telemetry processor will be executed ONLY when telemetry is sampled in
            .Use((next) =>
            {
                return(new TelemetryRecordSizeProcessor(next, size => worker.OnSentItems(size)));
            })
            .Build();

            return(configuration);
        }
Exemplo n.º 2
0
 public AggressivelySampleFastDependencies(ITelemetryProcessor next)
 {
     // Next TelemetryProcessor in the chain
     _next = next;
     this.samplingProcessor = new AdaptiveSamplingTelemetryProcessor(next)
     {
         ExcludedTypes = "Event",                                     // exclude custom events from being sampled
         MaxTelemetryItemsPerSecond        = 1,                       // default: 5 calls/sec
         SamplingPercentageIncreaseTimeout = TimeSpan.FromSeconds(1), // default: 2 min
         SamplingPercentageDecreaseTimeout = TimeSpan.FromSeconds(1), // default: 30 sec
         EvaluationInterval        = TimeSpan.FromSeconds(1),         // default: 15 sec
         InitialSamplingPercentage = 25,                              // default: 100%
     };
 }
Exemplo n.º 3
0
        public void SettingsFromPassedInTelemetryProcessorsAreAppliedToSamplingTelemetryProcessor()
        {
            var nextMock = new Mock <ITelemetryProcessor>();
            var next     = nextMock.Object;
            var adaptiveSamplingProcessor = new AdaptiveSamplingTelemetryProcessor(
                new Channel.Implementation.SamplingPercentageEstimatorSettings
            {
                InitialSamplingPercentage = 25,
            },
                null,
                next);
            var percentageEstimatorProcessor = adaptiveSamplingProcessor.SamplingTelemetryProcessor;

            Assert.AreEqual(25, percentageEstimatorProcessor.SamplingPercentage);
        }
Exemplo n.º 4
0
        public void CurrentSamplingRateResetsOnInitialSamplingRateChange()
        {
            var nextMock = new Mock <ITelemetryProcessor>();
            var next     = nextMock.Object;
            var adaptiveSamplingProcessor = new AdaptiveSamplingTelemetryProcessor(
                new Channel.Implementation.SamplingPercentageEstimatorSettings
            {
                InitialSamplingPercentage = 20,
            },
                null,
                next);

            Assert.AreEqual(20, adaptiveSamplingProcessor.InitialSamplingPercentage);
            Assert.AreEqual(100 / 20, adaptiveSamplingProcessor.SamplingPercentageEstimatorTelemetryProcessor.CurrentSamplingRate);

            // change in InitialSamplingPercentage should change the CurrentSamplingPercentage:
            adaptiveSamplingProcessor.InitialSamplingPercentage = 50;
            Assert.AreEqual(50, adaptiveSamplingProcessor.InitialSamplingPercentage);
            Assert.AreEqual(100 / 50, adaptiveSamplingProcessor.SamplingPercentageEstimatorTelemetryProcessor.CurrentSamplingRate);
        }
 public AggressivelySampleFastDependencies(ITelemetryProcessor next)
 {
     this.next = next;
     this.samplingProcessor = new AdaptiveSamplingTelemetryProcessor(next);
 }
Exemplo n.º 6
0
 /// <summary>
 /// Creates a new instance of ConfigurableAdaptiveSamplingTelemetryProcessor
 /// </summary>
 /// <param name="next">Next telemetry processor in the chain</param>
 public ConfigurableAdaptiveSamplingTelemetryProcessor(ITelemetryProcessor next)
 {
     this.next      = next;
     this.processor = new AdaptiveSamplingTelemetryProcessor(next);
 }