Extending AppInsights Sampling to Specify Telemetry Types

Starting with v.2.0 of .NET AppInsights SDK sampling is enabled by default in ApplicationInsights.config. There are two options available for sampling: SamplingTelemetryProcessor (fixed rate) and AdaptiveSamplingTelemetryProcessor. One limitation of current solution is that customer cannot choose what telemetry types to sample - sampling is applied to all telemetry types except custom metrics. In the upcoming versions of .NET SDK, we will address this problem (there's already an API proposal), however at the meantime here's a what you can do to choose what telemetry types you would like to sample.

  1. Create a telemetry processor, let's call it ConfigurableAdaptiveSamplingTelemetryProcessor. This is the code that you can you can just add to your project .
  2. Replace AdaptiveTelemetryProcessor in your ApplicationInsights.config with ConfigurableAdaptiveSamplingTelemetryProcessor from your assembly. In my case I only would like to sample requests and dependencies, and always sent all other telemetry types:
  <!--
 <Add Type="Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel.AdaptiveSamplingTelemetryProcessor, Microsoft.AI.ServerTelemetryChannel">
   <MaxTelemetryItemsPerSecond>5</MaxTelemetryItemsPerSecond>
 </Add>
 -->
 <Add Type="Microsoft.ApplicationInsights.Samples.ConfigurableAdaptiveSamplingTelemetryProcessor, <YourAssemblyName>">
   <MaxTelemetryItemsPerSecond>5</MaxTelemetryItemsPerSecond>
   <SampledTelemetry>Request;Dependency</SampledTelemetry>
 </Add>

And this is all you need. Possible values for SampledTelemetry are request, dependency, event, exception, pageview, performancecounter, trace, metric. One caveat is that if you specify empty list, no telemetry types will be sampled - but you can change this logic. You can also apply the same approach to customize SamplingTelemetryProcessor (fixed rate).

Looking forward to your feedback - what else would you like to customize in our default sampling functionality?