'Application Insights SDK C# - Log full telemetry and dependencies only on requests that have failed

We're trying to cut down the costs of our Application Insights instance, currently we don't have Adaptive Sampling enabled as we find it often doesn't record a dependency that is required so doesn't give us a full picture, especially when a request has failed.

So my thinking was to only log the Request without any dependencies if the request was successful, and log all the Dependencies if the Request was not successful.

I thought this would be fairly easy using the TelemetryProcessor Filter functionality. However, as far as I can see there is no link within the SDK between the telemetry i.e. I cannot see how a Request telemetry links to the Dependency telemetry, meaning I cannot stop the SDK logging the Dependency as I cannot check if the Request was successful.

The WebAPI is running .Net6, C# using Microsoft.ApplicationInsights.AspNetCore 2.20.0

Has anyone else had this problem or can think of a solution? Many thanks



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source