Skip to content

Sampling (2.x)

Trask Stalnaker edited this page Jan 20, 2021 · 1 revision

Introduction

Sampling aims to reduce the traffic from the SDK to the server.

When sampling is done, correlated telemetries will either sent or blocked together.

There are two types of Sampling. Fixed and Adaptive which can be configured in the ApplicationInsights.xml

Fixed Sampler

Will allow a fixed rate of telemetries (default is 100%) Will try to sample in all correlated telemetries, by the following order:

User id: The value found in the User Id (in the telemetry's context) Operation id: The value found in the Operation Id (in the telemetry's context) Random

The value that is calculated will be matched against the Sampling Percentage threshold. If the value is greater than the threshold, the telemetry will be sent to the server. Else, it will be discarded.

Attributes that the user can set

IncludeTypes: The telemetry types that will be evaluated for sampling. Default: all Possible values: Event, Trace, PageView, Request, Dependency, Exception

ExcludeTypes: The telemetry types that will not **** be evaluated for sampling. Default: none Possible values: Event, Trace, PageView, Request, Dependency, Exception

SamplingPercentage: A value that should be between 0 to 100

Configuration is done in the ApplicationInsights.xml. For example:

<Sampling>

<Fixed>

`<SamplingPercentage>90</SamplingPercentage>`

</Fixed>

</Sampling>

Adaptive Sampler

The key here is the number of telemetries per second that is set in configuration by the user. The SDK will try to restrict the amount of telemetries per seconds that is sent from the SDK so in Average it matchs the requested number.

Attributes that the user can set

MaxTelemetriesPerSecond: The number of telemetries per second. The SDK will try to match this number in the long run.

EvaluationIntervalInSec: How much time to wait between re-evaluation of the sampling percentage.

MinSamplingPercentage: The minimum percentage the SDK is allowed to set when evaluating the sampling percentage, default is 0

MaxSamplingPercentage: The maximum percentage the SDK is allowed to set when evaluating the sampling percentage, default 100.

IncludeTypes: The telemetry types that will be evaluated for sampling. Default: all Possible values: Event, Trace, PageView, Request, Dependency, Exception

ExcludeTypes: The telemetry types that will **not **be evaluated for sampling. Default: none Possible values: Event, Trace, PageView, Request, Dependency, Exception

<Sampling>

<Adaptive>

`<MaxTelemetriesPerSecond>100</MaxTelemetriesPerSecond>`

`<MovingAverageRatio>0.5</MovingAverageRatio>`

`<EvaluationTimeInSec>120</EvaluationTimeInSec>`

</Adaptive>

</Sampling>