microsoft / ApplicationInsights-SDK-Labs

Application Insights experimental projects repository
MIT License
61 stars 48 forks source link

Some Telemetry is sent twice (By WCF package and Web?) #150

Closed sander1095 closed 6 years ago

sander1095 commented 6 years ago

Hello!

I have installed your package, but when I use it I see duplicate requests and exceptions being logged. I believe it might be because I am using an ASP.NET app which I configured AI for (All I did was the default AI configuration) and later on installed this WCF add-on.

Duplicate request:

duplicaterequest

Duplicate exception:

duplicateexception

Dependencies, my own Traces and Metrics are not logged twice! These work just fine!

This is my Application Insights config:

<ApplicationInsights xmlns="http://schemas.microsoft.com/ApplicationInsights/2013/Settings">
    <TelemetryInitializers>
        <Add Type="Microsoft.ApplicationInsights.DependencyCollector.HttpDependenciesParsingTelemetryInitializer, Microsoft.AI.DependencyCollector"/>
        <Add Type="Microsoft.ApplicationInsights.WindowsServer.AzureRoleEnvironmentTelemetryInitializer, Microsoft.AI.WindowsServer"/>
        <Add Type="Microsoft.ApplicationInsights.WindowsServer.AzureWebAppRoleEnvironmentTelemetryInitializer, Microsoft.AI.WindowsServer"/>
        <Add Type="Microsoft.ApplicationInsights.WindowsServer.BuildInfoConfigComponentVersionTelemetryInitializer, Microsoft.AI.WindowsServer"/>
        <Add Type="Microsoft.ApplicationInsights.Web.WebTestTelemetryInitializer, Microsoft.AI.Web"/>
        <Add Type="Microsoft.ApplicationInsights.Web.SyntheticUserAgentTelemetryInitializer, Microsoft.AI.Web">         
            <Filters>search|spider|crawl|Bot|Monitor|AlwaysOn</Filters>
        </Add>
        <Add Type="Microsoft.ApplicationInsights.Web.ClientIpHeaderTelemetryInitializer, Microsoft.AI.Web"/>
        <Add Type="Microsoft.ApplicationInsights.Web.OperationNameTelemetryInitializer, Microsoft.AI.Web"/>
        <Add Type="Microsoft.ApplicationInsights.Web.OperationCorrelationTelemetryInitializer, Microsoft.AI.Web"/>
        <Add Type="Microsoft.ApplicationInsights.Web.UserTelemetryInitializer, Microsoft.AI.Web"/>
        <Add Type="Microsoft.ApplicationInsights.Web.AuthenticatedUserIdTelemetryInitializer, Microsoft.AI.Web"/>
        <Add Type="Microsoft.ApplicationInsights.Web.AccountIdTelemetryInitializer, Microsoft.AI.Web"/>
        <Add Type="Microsoft.ApplicationInsights.Web.SessionTelemetryInitializer, Microsoft.AI.Web"/>
        <Add Type="Microsoft.ApplicationInsights.Wcf.OperationNameTelemetryInitializer, Microsoft.AI.Wcf"/>
        <Add Type="Microsoft.ApplicationInsights.Wcf.OperationCorrelationTelemetryInitializer, Microsoft.AI.Wcf"/>
        <Add Type="Microsoft.ApplicationInsights.Wcf.UserTelemetryInitializer, Microsoft.AI.Wcf"/>
        <Add Type="Microsoft.ApplicationInsights.Wcf.UserAgentTelemetryInitializer, Microsoft.AI.Wcf"/>
        <Add Type="Microsoft.ApplicationInsights.Wcf.ClientIpTelemetryInitializer, Microsoft.AI.Wcf"/>
    </TelemetryInitializers>
    <TelemetryModules>
        <Add Type="Microsoft.ApplicationInsights.DependencyCollector.DependencyTrackingTelemetryModule, Microsoft.AI.DependencyCollector">
            <ExcludeComponentCorrelationHttpHeadersOnDomains>
                <Add>core.windows.net</Add>
                <Add>core.chinacloudapi.cn</Add>
                <Add>core.cloudapi.de</Add>
                <Add>core.usgovcloudapi.net</Add>
                <Add>localhost</Add>
                <Add>127.0.0.1</Add>
            </ExcludeComponentCorrelationHttpHeadersOnDomains>
            <IncludeDiagnosticSourceActivities>
                <Add>Microsoft.Azure.EventHubs</Add>
                <Add>Microsoft.Azure.ServiceBus</Add>
            </IncludeDiagnosticSourceActivities>
        </Add>
        <Add Type="Microsoft.ApplicationInsights.WindowsServer.AppServicesHeartbeatTelemetryModule, Microsoft.AI.WindowsServer"/>
        <Add Type="Microsoft.ApplicationInsights.WindowsServer.AzureInstanceMetadataTelemetryModule, Microsoft.AI.WindowsServer">
        </Add>
        <Add Type="Microsoft.ApplicationInsights.WindowsServer.DeveloperModeWithDebuggerAttachedTelemetryModule, Microsoft.AI.WindowsServer"/>
        <Add Type="Microsoft.ApplicationInsights.WindowsServer.UnhandledExceptionTelemetryModule, Microsoft.AI.WindowsServer"/>
        <Add Type="Microsoft.ApplicationInsights.WindowsServer.UnobservedExceptionTelemetryModule, Microsoft.AI.WindowsServer">
            <!--</Add>
    <Add Type="Microsoft.ApplicationInsights.WindowsServer.FirstChanceExceptionStatisticsTelemetryModule, Microsoft.AI.WindowsServer">-->
        </Add>
        <Add Type="Microsoft.ApplicationInsights.Web.RequestTrackingTelemetryModule, Microsoft.AI.Web">
            <Handlers>
                <Add>Microsoft.VisualStudio.Web.PageInspector.Runtime.Tracing.RequestDataHttpHandler</Add>
                <Add>System.Web.StaticFileHandler</Add>
                <Add>System.Web.Handlers.AssemblyResourceLoader</Add>
                <Add>System.Web.Optimization.BundleHandler</Add>
                <Add>System.Web.Script.Services.ScriptHandlerFactory</Add>
                <Add>System.Web.Handlers.TraceHandler</Add>
                <Add>System.Web.Services.Discovery.DiscoveryRequestHandler</Add>
                <Add>System.Web.HttpDebugHandler</Add>
            </Handlers>
        </Add>
        <Add Type="Microsoft.ApplicationInsights.Web.ExceptionTrackingTelemetryModule, Microsoft.AI.Web"/>
        <Add Type="Microsoft.ApplicationInsights.Web.AspNetDiagnosticTelemetryModule, Microsoft.AI.Web"/>
        <Add Type="Microsoft.ApplicationInsights.Wcf.RequestTrackingTelemetryModule, Microsoft.AI.Wcf"/>
        <Add Type="Microsoft.ApplicationInsights.Wcf.ExceptionTrackingTelemetryModule, Microsoft.AI.Wcf"/>
    </TelemetryModules>
    <ApplicationIdProvider Type="Microsoft.ApplicationInsights.Extensibility.Implementation.ApplicationId.ApplicationInsightsApplicationIdProvider, Microsoft.ApplicationInsights"/>
    <TelemetryProcessors>
        <Add Type="Microsoft.ApplicationInsights.Extensibility.AutocollectedMetricsExtractor, Microsoft.ApplicationInsights"/>
        <Add Type="Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel.AdaptiveSamplingTelemetryProcessor, Microsoft.AI.ServerTelemetryChannel">
            <MaxTelemetryItemsPerSecond>5</MaxTelemetryItemsPerSecond>
            <ExcludedTypes>Event</ExcludedTypes>
        </Add>
        <Add Type="Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel.AdaptiveSamplingTelemetryProcessor, Microsoft.AI.ServerTelemetryChannel">
            <MaxTelemetryItemsPerSecond>5</MaxTelemetryItemsPerSecond>
            <IncludedTypes>Event</IncludedTypes>
        </Add>
    </TelemetryProcessors>
    <TelemetryChannel Type="Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel.ServerTelemetryChannel, Microsoft.AI.ServerTelemetryChannel"/>

<!-- 
    Learn more about Application Insights configuration with ApplicationInsights.config here: 
    http://go.microsoft.com/fwlink/?LinkID=513840

    Note: If not present, please add <InstrumentationKey>Your Key</InstrumentationKey> to the top of this file.
  --></ApplicationInsights>

These are my Application Insights packages:

 <package id="Microsoft.ApplicationInsights" version="2.6.4" targetFramework="net471" />
  <package id="Microsoft.ApplicationInsights.Agent.Intercept" version="2.4.0" targetFramework="net471" />
  <package id="Microsoft.ApplicationInsights.DependencyCollector" version="2.6.4" targetFramework="net471" />
  <package id="Microsoft.ApplicationInsights.NLogTarget" version="2.6.4" targetFramework="net471" />
  <package id="Microsoft.ApplicationInsights.PerfCounterCollector" version="2.6.4" targetFramework="net471" />
  <package id="Microsoft.ApplicationInsights.Wcf" version="0.28.0-build06820" targetFramework="net471" />
  <package id="Microsoft.ApplicationInsights.Web" version="2.6.4" targetFramework="net471" />
  <package id="Microsoft.ApplicationInsights.WindowsServer" version="2.6.4" targetFramework="net471" />
  <package id="Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel" version="2.6.4" targetFramework="net471" />
  <package id="Microsoft.AspNet.TelemetryCorrelation" version="1.0.3" targetFramework="net471" />

I am using a ASP.NET 4.7.1 application that has just 1 endpoint, which is for WCF. It is hosted on an Azure Virtual Machine (Windows 2016 Datacenter, I believe?)

Can you tell me how I can stop the duplication of telemetry, if it is better to use the WCF version of some telemetry packages in the AppInsights Config (where possible) and how to set this all up? I'd prefer to lose no data at all, I still want to use all the benefits I can use with Application Insights and also this add-on for WCF!

Thank you very much!

sander1095 commented 6 years ago

Might be related to https://github.com/Microsoft/ApplicationInsights-dotnet-server/issues/924

sander1095 commented 6 years ago

Deleting the Web package fixed my issue with requests being logged multiple twice.

The duplicate exception was caused by my own code; IErrorHandler.HandleError(Exception error) would log it and so would some other code. This has been fixed :)

Thank you for this package!