title: Disabling Azure Insights sampling does not work
body: <p>I am working on a Azure Function in .NET Core 3.1. I have noticed that it does not save all of the desired data into the Azure Insights. To be sure, i tried to run my function on a localhost and added logging not only to the AI, but also, every time that i try to log data into the AI, i also created a text file with the data that i wanted to log to. The quantity of created text files is exactly the same as I've expected, while I've got way less entries in AI logs.</p>
  <p>To disable sampling, i tried various configurations of host.json file, the current content of that file is:</p>
  <pre><code>  &quot;version&quot;: &quot;2.0&quot;,
    &quot;functionTimeout&quot;: &quot;-1&quot;,
    &quot;logging&quot;: {
      &quot;fileLoggingMode&quot;: &quot;always&quot;,
      &quot;logLevel&quot;: {
        &quot;default&quot;: &quot;Information&quot;
      },
      &quot;applicationInsights&quot;: {
        &quot;samplingSettings&quot;: {
          &quot;isEnabled&quot;: false,
          &quot;maxTelemetryItemsPerSecond&quot;: 10000,
          &quot;excludedTypes&quot;: &quot;Debug,Trace,Warning,Error,Information,Critical&quot;
        }
      }
    }
  }
  </code></pre>
  <p>(Since setting isEnabled to false didn't help, i also tried to set sufficient quantity of max telemetry items per second, but it didn't help, too)</p>
  <p>And it didn't worked (neither on my local computer and deployed on Azure); i also tried to disable it by code:</p>
  <pre><code>namespace MyAzureFunction
  {
      public class MyStartup : IWebJobsStartup
      {
          public void Configure(IWebJobsBuilder builder)
          {
              var configDescriptor = builder.Services.SingleOrDefault(tc =&gt; tc.ServiceType == typeof(TelemetryConfiguration));
              if (configDescriptor?.ImplementationFactory != null)
              {
                  var aiOptions = new ApplicationInsightsServiceOptions();
                  aiOptions.EnableAdaptiveSampling = false;
  
                  var implFactory = configDescriptor.ImplementationFactory;
                  builder.Services.Remove(configDescriptor);
                  builder.Services.AddSingleton(provider =&gt;
                  {
                      if (implFactory.Invoke(provider) is TelemetryConfiguration config)
                      {
                          var newConfig = TelemetryConfiguration.Active;
                          newConfig.ApplicationIdProvider = config.ApplicationIdProvider;
                          newConfig.InstrumentationKey = config.InstrumentationKey;
                          return newConfig;
                      }
                      return null;
                  });
  
                  builder.Services.AddApplicationInsightsTelemetry(aiOptions);
              }
          }
      }
  </code></pre>
  <p>Also, when i run my function on a localhost, that's what i see in the commandline window:</p>
  <pre><code>[2022-08-24T13:37:55.249Z] {
  [2022-08-24T13:37:55.250Z]   &quot;version&quot;: &quot;2.0&quot;,
  [2022-08-24T13:37:55.252Z]   &quot;functionTimeout&quot;: &quot;-1&quot;,
  [2022-08-24T13:37:55.253Z]   &quot;logging&quot;: {
  [2022-08-24T13:37:55.254Z]     &quot;fileLoggingMode&quot;: &quot;always&quot;,
  [2022-08-24T13:37:55.255Z]     &quot;logLevel&quot;: {
  [2022-08-24T13:37:55.257Z]       &quot;default&quot;: &quot;Information&quot;
  [2022-08-24T13:37:55.258Z]     },
  [2022-08-24T13:37:55.259Z]     &quot;applicationInsights&quot;: {
  [2022-08-24T13:37:55.260Z]       &quot;samplingSettings&quot;: {
  [2022-08-24T13:37:55.262Z]         &quot;isEnabled&quot;: false,
  (...)
  [2022-08-24T13:37:57.043Z] Initializing Host. OperationId: ...
  [2022-08-24T13:37:57.055Z] Host initialization: ConsecutiveErrors=0, StartupCount=1, OperationId=...
  [2022-08-24T13:37:57.087Z] ApplicationInsightsLoggerOptions
  [2022-08-24T13:37:57.089Z] {
  [2022-08-24T13:37:57.089Z]   &quot;SamplingSettings&quot;: null,
  [2022-08-24T13:37:57.090Z]   &quot;SamplingExcludedTypes&quot;: null,
  [2022-08-24T13:37:57.091Z]   &quot;SamplingIncludedTypes&quot;: null,
  [2022-08-24T13:37:57.092Z]   &quot;SnapshotConfiguration&quot;: null,
  </code></pre>
  <p>As you can see, even though it read the host config with sampling turned off, SamplingSettings are null, but i can't find a way to effectively disable it.</p>