Application insights with manual and auto instrumentation

AzureUser-9588 151 Reputation points
2024-09-20T09:32:46.0666667+00:00

I have two appservice webapplications using application insights, one enabled with auto instrumentation, and the other with manual instrumentation. Both applications are sending a large amount of data to appdependencies table. How to stop collecting data to it from both these webapplications.

Azure Monitor
Azure Monitor
An Azure service that is used to collect, analyze, and act on telemetry data from Azure and on-premises environments.
3,224 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Vinodh247 19,656 Reputation points
    2024-09-22T11:55:21.9766667+00:00

    Hi AzureUser-9588,

    Thanks for reaching out to Microsoft Q&A.

    To stop collecting data in the AppDependencies table for your two app service web applications using application Insights, you can adjust the telemetry collection for both auto-instrumented and manually-instrumented applications.

    For Auto-instrumented Application:

    Auto-instrumentation collects dependency telemetry automatically by default. To stop this, you can disable the collection of dependency telemetry by configuring the applicationinsights.config or directly through the application insights portal settings.

    Steps:

    Applicationinsights.config:

    • Find the 'applicationinsights.config' file in your application.

    Add or modify the following under the '<telemetrymodules>' section to disable dependency tracking:

    <Add Type="Microsoft.ApplicationInsights.DependencyCollector.DependencyTrackingTelemetryModule, Microsoft.AI.DependencyCollector">
       <ExcludeComponentCorrelationHttpHeadersOnDomains>
         <!-- List of domains to exclude from correlation here -->
       </ExcludeComponentCorrelationHttpHeadersOnDomains>
       <EnableDependencyTracking>false</EnableDependencyTracking>
    </Add>
    
    

    Azure portal:

    • Go to the application insights resource for your application.
    • Under settings, select instrumentation settings.
    • Disable the auto-collection of dependencies.

    For manually-instrumented application:

    In manual instrumentation, you control what telemetry is collected by explicitly using the application insights sdk. To stop collecting dependency data:

    Steps:

    1. Modify code to stop dependency tracking:
    • Identify the sections of your code where you are tracking dependencies manually, for ex, using:
    var telemetryClient = new TelemetryClient();
    telemetryClient.TrackDependency(…);
    
    
    • Remove or comment out these lines to stop collecting dependency telemetry.
    1. Disable the 'dependencytrackingtelemetrymodule' programmatically:

    if you're programmatically controlling modules in the code, you can disable the 'dependencytrackingtelemetrymodule' directly:

    var module = TelemetryModules.Instance.Modules.OfType<DependencyTrackingTelemetryModule>().FirstOrDefault();
    if (module != null)
    {
        module.Disable();
    }
    
    

    Additional steps to reduce data volume:

    • Sampling: if you don't want to completely disable dependency collection but want to reduce the amount of data, you can use sampling to limit the volume of telemetry:
    <ApplicationInsights>
        <TelemetryProcessors>
            <Add Type="Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel.AdaptiveSamplingTelemetryProcessor, Microsoft.AI.ServerTelemetryChannel">
                <MaxTelemetryItemsPerSecond>5</MaxTelemetryItemsPerSecond>
            </Add>
        </TelemetryProcessors>
    </ApplicationInsights>
    
    

    This will limit the amount of telemetry sent to application insights, including dependency data.

    By following these steps, you should be able to stop or reduce the dependency telemetry collection for both applications in a controlled manner.

    Note: The code provided above is as is and only for demo., pls modify and change accordingly to suit your requirement.

    Please 'Upvote'(Thumbs-up) and 'Accept' as an answer if the reply was helpful. This will benefit other community members who face the same issue.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.