ApplicationInsights-dotnet icon indicating copy to clipboard operation
ApplicationInsights-dotnet copied to clipboard

Data is being sampled even though sampling is disabled

Open Stardox opened this issue 4 years ago • 25 comments

Environment

  • AI SDK: Microsoft.ApplicationInsights.AspNetCore 2.13.1
  • .NET version: .NET Core 3.1
  • Type: ASP.NET Core web application
  • The application is hosted within Azure as an App Service

The problem

Occasionally when reviewing App Insights logs of my Web App through Azure portal I notice that some of the entries within given telemetry operation are missing or that the whole telemetry operation is missing completely. By telemetry operation I mean all entries in the context of incoming HTTP request.

This behavior seems to be related to following message bubble which appears on top of App Insights window in Azure:

Data received from your application is being sampled to reduce the volume of telemetry data retained; only sampled documents will be returned. The sampling may be applied by the Application Insights SDK or on ingestion by Application Insights. Click to learn more.

The message points to following documentation which I have walked through already and disabled the sampling both in the SDK and also in portal.

SDK configuration

This is how I have configured the AI Telemetry Client within my Startup.cs class:

var aiOptions = new ApplicationInsightsServiceOptions
{
    EnableAdaptiveSampling = false,
    EnableQuickPulseMetricStream = false,
    InstrumentationKey = ikGoesHere
};
aiOptions.RequestCollectionOptions.TrackExceptions = true;
services.AddApplicationInsightsTelemetry(aiOptions);

AI configuration through portal

image

image

image

I need to retain all telemetry data (even though it is only for couple of days) for diagnostic purposes. How can I achieve that?

Stardox avatar Apr 24 '20 13:04 Stardox

@Stardox , SDK and Server configuration looks fine. Could you please execute the following query and check if data is sampled.

union requests,dependencies,pageViews,browserTimings,exceptions,traces
| where timestamp > ago(1d)
| summarize RetainedPercentage = 100/avg(itemCount) by bin(timestamp, 1h), itemType

Ref: [Knowing whether sampling is in operation] (https://docs.microsoft.com/en-us/azure/azure-monitor/app/sampling#knowing-whether-sampling-is-in-operation)

rajkumar-rangaraj avatar Apr 24 '20 14:04 rajkumar-rangaraj

@rajkumar-rangaraj, for majority of results the RetainedPercentage is 100. However I also see entries where the percentage is ~91, ~68 or ~75 just to name few.

Not sure if this is relevant, but my App Insights resource is in South Central US region.

Stardox avatar Apr 27 '20 04:04 Stardox

@Stardox , If RetainedPercentage is not equal to 100 in any of the row, then we consider data as sampled. This could also happen if multiple app logging to the same AI component. Could you please validate that only one app is logging data to this component.

rajkumar-rangaraj avatar Apr 27 '20 19:04 rajkumar-rangaraj

I'm having this same issue. Data sampling is set to 100% (all data) and with the above query I'm seeing retained percentage at ~53, ~48, ~60, etc.

graham-saunders avatar May 06 '20 16:05 graham-saunders

@rajkumar-rangaraj, there is only one application creating log entries in my AI component.

But even if there were multiple, then theoretically speaking, it would only affect this retained percentage report - It should not simply drop / ignore telemetry entries, right?

Stardox avatar May 12 '20 07:05 Stardox

@rajkumar-rangaraj/@cijothomas , Getting the same issue as others here.

Have ensured that only one application is creating log entries in AppInsights component, but data keeps getting sampled. Any ideas on how to get all the data retained ?

Huss-Dev avatar Sep 29 '20 16:09 Huss-Dev

@Stardox Did you by any chance find a solution to this issue. Would help if you could share your experience.

Thanks in advance

Huss-Dev avatar Sep 29 '20 16:09 Huss-Dev

@Stardox @Huss-Dev @rajkumar-rangaraj Try disabling this setting. As I understand it, this can help as it disables the SDK on the Azure service side, which overrides the SDK on the application side (with its settings).

image

DiscipleDV avatar Dec 29 '20 20:12 DiscipleDV

We are facing the same issue, it would be great if anyone can share about the root cause of issue.

chertpong avatar Feb 03 '21 03:02 chertpong

If you believe data is being sampled at the ingestion side, despite turning it off, please open support ticket with Azure.

If the SDK is sampling, despite configuring it to do otherwise, please reply here, and we can investigate. Please share a minimal repro for this behaviour.

cijothomas avatar Feb 08 '21 23:02 cijothomas

Hello, we're also facing the same issue here regarding an azure function deployed. The percentage reported by the above query is 100%, though a lot of traces logged by our function are missing. Sampling is disabled in host.json and relevant sampling setting in portal is at 100%.

Any info/help is appreciated

jsoumelidis avatar Mar 10 '21 08:03 jsoumelidis

Seeing same issue with Azure Functions v3, I have in the host.json. { "version": "2.0", "logging": { "fileLoggingMode": "always", "logLevel": { "default": "Trace" }, "applicationInsights": { "samplingSettings": { "isEnabled": false, "maxTelemetryItemsPerSecond": 20000 } } } } the telemetryclient is based on default: new TelemetryClient(TelemetryConfiguration.CreateDefault());

SavaNDragos avatar Mar 19 '21 09:03 SavaNDragos

Please raise Azure functions issue in Azure functions runtime repo, as Functions uses a custom enablement of application insights sdk.

cijothomas avatar Mar 19 '21 18:03 cijothomas

This issue is stale because it has been open 300 days with no activity. Remove stale label or this will be closed in 7 days. Commenting will instruct the bot to automatically remove the label.

github-actions[bot] avatar Jan 14 '22 00:01 github-actions[bot]

@Stardox @Huss-Dev @rajkumar-rangaraj Try disabling this setting. As I understand it, this can help as it disables the SDK on the Azure service side, which overrides the SDK on the application side (with its settings).

image

This solution worked in my case. Once the InterOP with Application Insights was disabled the correct settings got applied.

Huss-Dev avatar Jan 15 '22 03:01 Huss-Dev

We also face this issue:

  • in Azure AppInsights: Sampling: All Data 100%
  • in code: no AppInsights code is added (ASP.NET Core 3.1)
  • in App Service > App Insights blade: Interop is Off

still for lots of requests the itemCount = 1000, or 2000. Rounded off to this value, very strange.

andywarrens avatar Sep 06 '22 13:09 andywarrens

We also face this issue:

  • in Azure AppInsights: Sampling: All Data 100%
  • in code: no AppInsights code is added (ASP.NET Core 3.1)
  • in App Service > App Insights blade: Interop is Off

still for lots of requests the itemCount = 1000, or 2000. Rounded off to this value, very strange.

If you haven't added ApplicationInsights code in your application, but you have enabled ApplicationInsights from AppService portal (https://docs.microsoft.com/en-us/azure/azure-monitor/app/azure-web-apps-net-core?tabs=Windows%2Cwindows) then it will have sampling. This is independent of the Ingestion sampling.

cijothomas avatar Sep 06 '22 15:09 cijothomas

@cijothomas but what kind of sampling is enabled? How does it work?

I have a feeling that for a particular request, the itemCount is way too high. I expect it to be called around 20-50 times a day. But in reality it's 10.000 (total records is 13, sum(itemCount) ~ 10.000)

andywarrens avatar Sep 06 '22 20:09 andywarrens

https://docs.microsoft.com/en-us/azure/azure-monitor/app/sampling

cijothomas avatar Sep 06 '22 23:09 cijothomas

Thanks! I've read that page before but I'm still not sure which sampling I have enabled. Because Adaptive and Fixed-rate are configured in code, it seems I have Ingestion Sampling enabled. But then the docs say:

It discards some of the telemetry that arrives from your app, at a sampling rate that you set.

But the only place where I can set it, it's set to All data 100%. So I wonder if my deduction is correct. These are the only settings I could find in my App Service related to Application Insights: image

andywarrens avatar Sep 07 '22 08:09 andywarrens

not sure which sampling I have enabled.

You haven't enabled anything explicitly. When you enable auto-instrumentation (from app service's Application Insights blade - https://docs.microsoft.com/en-us/azure/azure-monitor/app/azure-web-apps), it enables Application Insights with a default setting. (it includes sampling as well). There is not much control one has if you chose auto-instrumentation. If you want to have full control, then you need to use the SDK based instrumentation.

cijothomas avatar Sep 07 '22 15:09 cijothomas

Aha. Thanks for that explanation. It would be great if the docs would add an overview of those default settings.

andywarrens avatar Sep 08 '22 14:09 andywarrens

Aha. Thanks for that explanation. It would be great if the docs would add an overview of those default settings.

Please share the feedback in the docs page itself, so it won't get lost in this repo.

cijothomas avatar Sep 08 '22 14:09 cijothomas

Do you mean a pull request on this repo (update this file), or the Github button on the bottom of the Sampling page you shared?

andywarrens avatar Sep 12 '22 08:09 andywarrens

image This ^, at the bottom of the doc

cijothomas avatar Sep 12 '22 16:09 cijothomas

This issue is stale because it has been open 300 days with no activity. Remove stale label or this will be closed in 7 days. Commenting will instruct the bot to automatically remove the label.

github-actions[bot] avatar Jul 10 '23 00:07 github-actions[bot]