ASP.NET 웹 사이트용 Application Insights 구성

이 절차에서는 Azure Monitor 서비스의 Azure Application Insights 기능으로 원격 분석을 보내도록 ASP.NET 웹앱을 구성합니다. 이 절차는 사용자 고유의 IIS 서버 온-프레미스 또는 클라우드에서 호스트되는 ASP.NET 앱에서 작동합니다.

참고 항목

다음 설명서는 Application Insights 클래식 API를 사용합니다. Application Insights에 대한 장기 플랜은 OpenTelemetry를 사용하여 데이터를 수집하는 것입니다. 자세한 내용은 .NET, Node.js, Python 및 Java 애플리케이션에 대해 Azure Monitor OpenTelemetry 사용을 참조하세요.

참고 항목

2025년 3월 31일에 계측 키 수집에 대한 지원이 종료됩니다. 계측 키 수집은 계속 작동하지만 더 이상 기능에 대한 업데이트 또는 지원을 제공하지 않습니다. 연결 문자열로 전환하여 새로운 기능을 활용합니다.

필수 조건

ASP.NET 웹 사이트에 Application Insights를 추가하려면 다음을 수행해야 합니다.

Important

계측 키보다 연결 문자열을 사용하는 것이 좋습니다. 새 Azure 지역에서는 계측 키 대신 연결 문자열을 사용해야 합니다.

연결 문자열은 원격 분석 데이터와 연결할 리소스를 식별합니다. 또한 연결 문자열을 통해 리소스가 원격 분석의 대상으로 사용할 엔드포인트를 수정할 수 있습니다. 연결 문자열을 복사하여 애플리케이션의 코드 또는 "APPLICATIONINSIGHTS_CONNECTION_STRING" 환경 변수에 추가해야 합니다.

기본 ASP.NET 웹앱 만들기

  1. Visual Studio 2019를 엽니다.
  2. 파일>>프로젝트를 선택합니다.
  3. ASP.NET 웹 애플리케이션(.NET Framework) C#을 선택합니다.
  4. 프로젝트 이름을 입력하고 만들기를 선택합니다.
  5. MVC>만들기를 선택합니다.

자동으로 Application Insights 추가

이 섹션에서는 템플릿 기반 ASP.NET 웹앱에 Application Insights를 자동으로 추가하는 방법을 안내합니다. Visual Studio의 ASP.NET 웹앱 프로젝트 내에서:

  1. 프로젝트>Application Insights 원격 분석 추가>Application Insights Sdk(로컬)>다음>완료>닫기를 선택합니다.

  2. ApplicationInsights.config 파일을 엽니다.

  3. 닫는 </ApplicationInsights> 태그 앞에 Application Insights 리소스에 대한 연결 문자열이 포함된 선을 추가합니다. 새로 만든 Application Insights 리소스의 개요 창에서 연결 문자열을 찾습니다.

    <ConnectionString>Copy connection string from Application Insights Resource Overview</ConnectionString>
    
  4. 프로젝트>NuGet 패키지 관리>업데이트를 선택합니다. 그런 다음, 각 Microsoft.ApplicationInsights NuGet 패키지를 안정적인 최신 릴리스로 업데이트합니다.

  5. IIS Express를 선택하여 애플리케이션을 실행합니다. 기본 ASP.NET 앱이 열립니다. 사이트의 페이지를 탐색할 때 원격 분석이 Application Insights로 전송됩니다.

수동으로 Application Insights 추가

이 섹션에서는 템플릿 기반 ASP.NET 웹앱에 Application Insights를 수동으로 추가하는 과정을 안내합니다. 이 섹션에서는 ASP.NET Framework의 표준 MVC 웹앱 템플릿을 기반으로 하는 웹앱을 사용한다고 가정합니다.

  1. 다음 NuGet 패키지 및 해당 종속성을 프로젝트에 추가합니다.

  2. 경우에 따라 ApplicationInsights.config 파일이 자동으로 만들어집니다. 파일이 이미 있는 경우 4단계로 건너뜁니다.

    자동으로 만들어지지 않으면 직접 만들어야 합니다. ASP.NET 애플리케이션의 루트 디렉터리에서 ApplicationInsights.config라는 새 파일을 만듭니다.

  3. 다음 XML 구성을 새로 만든 파일에 복사합니다.

    <?xml version="1.0" encoding="utf-8"?>
    <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.BuildInfoConfigComponentVersionTelemetryInitializer, Microsoft.AI.WindowsServer" />
        <Add Type="Microsoft.ApplicationInsights.Web.WebTestTelemetryInitializer, Microsoft.AI.Web" />
        <Add Type="Microsoft.ApplicationInsights.Web.SyntheticUserAgentTelemetryInitializer, Microsoft.AI.Web">
          <!-- Extended list of bots:
                search|spider|crawl|Bot|Monitor|BrowserMob|BingPreview|PagePeeker|WebThumb|URL2PNG|ZooShot|GomezA|Google SketchUp|Read Later|KTXN|KHTE|Keynote|Pingdom|AlwaysOn|zao|borg|oegp|silk|Xenu|zeal|NING|htdig|lycos|slurp|teoma|voila|yahoo|Sogou|CiBra|Nutch|Java|JNLP|Daumoa|Genieo|ichiro|larbin|pompos|Scrapy|snappy|speedy|vortex|favicon|indexer|Riddler|scooter|scraper|scrubby|WhatWeb|WinHTTP|voyager|archiver|Icarus6j|mogimogi|Netvibes|altavista|charlotte|findlinks|Retreiver|TLSProber|WordPress|wsr-agent|http client|Python-urllib|AppEngine-Google|semanticdiscovery|facebookexternalhit|web/snippet|Google-HTTP-Java-Client-->
          <Filters>search|spider|crawl|Bot|Monitor|AlwaysOn</Filters>
        </Add>
        <Add Type="Microsoft.ApplicationInsights.Web.ClientIpHeaderTelemetryInitializer, Microsoft.AI.Web" />
        <Add Type="Microsoft.ApplicationInsights.Web.AzureAppServiceRoleNameFromHostNameHeaderInitializer, 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" />
      </TelemetryInitializers>
      <TelemetryModules>
        <Add Type="Microsoft.ApplicationInsights.DependencyCollector.DependencyTrackingTelemetryModule, Microsoft.AI.DependencyCollector">
          <ExcludeComponentCorrelationHttpHeadersOnDomains>
            <!-- 
            Requests to the following hostnames will not be modified by adding correlation headers.         
            Add entries here to exclude additional hostnames.
            NOTE: this configuration will be lost upon NuGet upgrade.
            -->
            <Add>core.windows.net</Add>
            <Add>core.chinacloudapi.cn</Add>
            <Add>core.cloudapi.de</Add>
            <Add>core.usgovcloudapi.net</Add>
          </ExcludeComponentCorrelationHttpHeadersOnDomains>
          <IncludeDiagnosticSourceActivities>
            <Add>Microsoft.Azure.EventHubs</Add>
            <Add>Azure.Messaging.ServiceBus</Add>
          </IncludeDiagnosticSourceActivities>
        </Add>
        <Add Type="Microsoft.ApplicationInsights.Extensibility.PerfCounterCollector.PerformanceCollectorModule, Microsoft.AI.PerfCounterCollector">
          <!--
          Use the following syntax here to collect additional performance counters:
    
          <Counters>
            <Add PerformanceCounter="\Process(??APP_WIN32_PROC??)\Handle Count" ReportAs="Process handle count" />
            ...
          </Counters>
    
          PerformanceCounter must be either \CategoryName(InstanceName)\CounterName or \CategoryName\CounterName
    
          NOTE: performance counters configuration will be lost upon NuGet upgrade.
    
          The following placeholders are supported as InstanceName:
            ??APP_WIN32_PROC?? - instance name of the application process  for Win32 counters.
            ??APP_W3SVC_PROC?? - instance name of the application IIS worker process for IIS/ASP.NET counters.
            ??APP_CLR_PROC?? - instance name of the application CLR process for .NET counters.
          -->
        </Add>
        <Add Type="Microsoft.ApplicationInsights.Extensibility.PerfCounterCollector.QuickPulse.QuickPulseTelemetryModule, Microsoft.AI.PerfCounterCollector" />
        <Add Type="Microsoft.ApplicationInsights.WindowsServer.AppServicesHeartbeatTelemetryModule, Microsoft.AI.WindowsServer" />
        <Add Type="Microsoft.ApplicationInsights.WindowsServer.AzureInstanceMetadataTelemetryModule, Microsoft.AI.WindowsServer">
          <!--
          Remove individual fields collected here by adding them to the ApplicationInsighs.HeartbeatProvider 
          with the following syntax:
    
          <Add Type="Microsoft.ApplicationInsights.Extensibility.Implementation.Tracing.DiagnosticsTelemetryModule, Microsoft.ApplicationInsights">
            <ExcludedHeartbeatProperties>
              <Add>osType</Add>
              <Add>location</Add>
              <Add>name</Add>
              <Add>offer</Add>
              <Add>platformFaultDomain</Add>
              <Add>platformUpdateDomain</Add>
              <Add>publisher</Add>
              <Add>sku</Add>
              <Add>version</Add>
              <Add>vmId</Add>
              <Add>vmSize</Add>
              <Add>subscriptionId</Add>
              <Add>resourceGroupName</Add>
              <Add>placementGroupId</Add>
              <Add>tags</Add>
              <Add>vmScaleSetName</Add>
            </ExcludedHeartbeatProperties>
          </Add>
    
          NOTE: exclusions will be lost upon upgrade.
          -->
        </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 entries here to filter out additional handlers: 
    
            NOTE: handler configuration will be lost upon NuGet upgrade.
            -->
            <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" />
      </TelemetryModules>
      <ApplicationIdProvider Type="Microsoft.ApplicationInsights.Extensibility.Implementation.ApplicationId.ApplicationInsightsApplicationIdProvider, Microsoft.ApplicationInsights" />
      <TelemetrySinks>
        <Add Name="default">
          <TelemetryProcessors>
            <Add Type="Microsoft.ApplicationInsights.Extensibility.PerfCounterCollector.QuickPulse.QuickPulseTelemetryProcessor, Microsoft.AI.PerfCounterCollector" />
            <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>
            <!--
              Adjust the include and exclude examples to specify the desired semicolon-delimited types. (Dependency, Event, Exception, PageView, Request, Trace)
            -->
          </TelemetryProcessors>
          <TelemetryChannel Type="Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel.ServerTelemetryChannel, Microsoft.AI.ServerTelemetryChannel" />
        </Add>
      </TelemetrySinks>
      <!-- 
        Learn more about Application Insights configuration with ApplicationInsights.config here: 
        http://go.microsoft.com/fwlink/?LinkID=513840
      -->
      <ConnectionString>Copy connection string from Application Insights Resource Overview</ConnectionString>
    </ApplicationInsights>
    
  4. 닫는 </ApplicationInsights> 태그 앞에 Application Insights 리소스에 대한 연결 문자열을 추가합니다. 새로 만든 Application Insights 리소스의 개요 창에서 연결 문자열을 찾습니다.

    <ConnectionString>Copy connection string from Application Insights Resource Overview</ConnectionString>
    
  5. ApplicationInsights.config 파일과 동일한 프로젝트 수준에서 AiHandleErrorAttribute.cs라는 새 C# 파일이 있는 ErrorHandler라는 폴더를 만듭니다. 파일의 내용은 다음과 같습니다.

    using System;
    using System.Web.Mvc;
    using Microsoft.ApplicationInsights;
    
    namespace WebApplication10.ErrorHandler //namespace will vary based on your project name
    {
        [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = true, AllowMultiple = true)] 
        public class AiHandleErrorAttribute : HandleErrorAttribute
        {
            public override void OnException(ExceptionContext filterContext)
            {
                if (filterContext != null && filterContext.HttpContext != null && filterContext.Exception != null)
                {
                    //If customError is Off, then AI HTTPModule will report the exception
                    if (filterContext.HttpContext.IsCustomErrorEnabled)
                    {   
                        var ai = new TelemetryClient();
                        ai.TrackException(filterContext.Exception);
                    } 
                }
                base.OnException(filterContext);
            }
        }
    }
    
  6. App_Start 폴더에서 FilterConfig.cs 파일을 열어 샘플과 일치하도록 변경합니다.

    using System.Web;
    using System.Web.Mvc;
    
    namespace WebApplication10 //Namespace will vary based on project name
    {
        public class FilterConfig
        {
            public static void RegisterGlobalFilters(GlobalFilterCollection filters)
            {
                filters.Add(new ErrorHandler.AiHandleErrorAttribute());
            }
        }
    }
    
  7. Web.config가 이미 업데이트된 경우 이 단계를 건너뜁니다. 그러지 않으면 파일을 다음과 같이 업데이트합니다.

    <?xml version="1.0" encoding="utf-8"?>
    <!--
      For more information on how to configure your ASP.NET application, please visit
      https://go.microsoft.com/fwlink/?LinkId=301880
      -->
    <configuration>
      <appSettings>
        <add key="webpages:Version" value="3.0.0.0" />
        <add key="webpages:Enabled" value="false" />
        <add key="ClientValidationEnabled" value="true" />
        <add key="UnobtrusiveJavaScriptEnabled" value="true" />
      </appSettings>
      <system.web>
        <compilation debug="true" targetFramework="4.7.2" />
        <httpRuntime targetFramework="4.7.2" />
        <!-- Code added for Application Insights start -->
        <httpModules>
          <add name="TelemetryCorrelationHttpModule" type="Microsoft.AspNet.TelemetryCorrelation.TelemetryCorrelationHttpModule, Microsoft.AspNet.TelemetryCorrelation" />
          <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" />
        </httpModules>
        <!-- Code added for Application Insights end -->
      </system.web>
      <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
          <dependentAssembly>
            <assemblyIdentity name="Antlr3.Runtime" publicKeyToken="eb42632606e9261f" />
            <bindingRedirect oldVersion="0.0.0.0-3.5.0.2" newVersion="3.5.0.2" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" />
            <bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="0.0.0.0-1.6.5135.21930" newVersion="1.6.5135.21930" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="1.0.0.0-5.2.7.0" newVersion="5.2.7.0" />
          </dependentAssembly>
          <!-- Code added for Application Insights start -->
          <dependentAssembly>
            <assemblyIdentity name="System.Memory" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-4.0.1.1" newVersion="4.0.1.1" />
          </dependentAssembly>
          <!-- Code added for Application Insights end -->
        </assemblyBinding>
      </runtime>
      <system.codedom>
        <compilers>
          <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701" />
          <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+" />
        </compilers>
      </system.codedom>
      <system.webServer>
        <validation validateIntegratedModeConfiguration="false" />
        <!-- Code added for Application Insights start -->
        <modules>
          <remove name="TelemetryCorrelationHttpModule" />
          <add name="TelemetryCorrelationHttpModule" type="Microsoft.AspNet.TelemetryCorrelation.TelemetryCorrelationHttpModule, Microsoft.AspNet.TelemetryCorrelation" preCondition="managedHandler" />
          <remove name="ApplicationInsightsWebTracking" />
          <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" preCondition="managedHandler" />
        </modules>
        <!-- Code added for Application Insights end -->
      </system.webServer>
    </configuration>
    
    

이제 서버 쪽 애플리케이션 모니터링을 성공적으로 구성했습니다. 웹앱을 실행하면 원격 분석이 Application Insights에 표시되기 시작합니다.

클라이언트쪽 모니터링을 추가 합니다.

이전 섹션에서는 서버 쪽 모니터링을 자동 및 수동으로 구성하는 방법에 대한 지침을 제공했습니다. 클라이언트 쪽 모니터링을 추가하려면 클라이언트 쪽 JavaScript SDK를 사용합니다. 페이지 HTML의 닫는 </head> 태그 앞에 JavaScript JavaScript(웹) SDK 로더 스크립트를 추가하여 웹 페이지의 클라이언트 쪽 트랜잭션을 모니터링할 수 있습니다.

각 HTML 페이지의 헤더에 JavaScript(웹) SDK 로더 스크립트를 수동으로 추가할 수 있지만 대신 기본 페이지에 JavaScript(웹) SDK 로더 스크립트를 추가하는 것이 좋습니다. 해당 작업은 JavaScript(웹) SDK 로더 스크립트를 사이트의 모든 페이지에 삽입합니다.

이 문서에서 템플릿 기반 ASP.NET MVC 앱의 경우 _Layout.cshtml 파일을 편집해야 합니다. 이 파일은 보기>공유에서 찾을 수 있습니다. 클라이언트 쪽 모니터링을 추가하려면 _Layout.cshtml을 열고 클라이언트 쪽 JavaScript SDK 구성에 대한 문서의 JavaScript(웹) SDK 로더 스크립트 기반 설정 지침을 따릅니다.

자주 묻는 질문

이 섹션에서는 일반적인 질문에 대한 답변을 제공합니다.

SDK를 어떻게 제거할 수 있나요?

Application Insights를 제거하려면 애플리케이션의 API에서 NuGet 패키지 및 참조를 제거해야 합니다. Visual Studio에서 NuGet 패키지 관리자를 사용하여 NuGet 패키지를 제거할 수 있습니다.

  1. 추적 컬렉션을 사용하는 경우 먼저 NuGet 패키지 관리자를 사용하여 Microsoft.ApplicationInsights.TraceListener 패키지를 제거하지만 종속성은 제거하지 않습니다.
  2. NuGet 패키지 관리자를 사용하고 NuGet 패키지 관리자 옵션 컨트롤 내에서 제거 옵션을 사용하여 Microsoft.ApplicationInsights.Web 패키지를 제거하고 해당 종속성을 제거합니다.
  3. Application Insights를 완전히 제거하려면 프로젝트에 추가한 모든 API 호출과 함께 추가된 코드나 파일을 확인하고 수동으로 삭제합니다. 자세한 내용은 Application Insights SDK를 추가할 때 생성되는 항목을 참조하세요.

Application Insights SDK를 추가할 때 생성되는 항목

프로젝트에 Application Insights를 추가하면 파일이 만들어지며 일부 파일에는 코드가 추가됩니다. NuGet 패키지를 제거한다고 해서 파일 및 코드가 항상 삭제되는 것은 아닙니다. Application Insights를 완전히 제거하려면 프로젝트에 추가한 모든 API 호출과 함께 추가된 코드나 파일을 확인하고 수동으로 삭제해야 합니다.

Visual Studio ASP.NET 프로젝트에 Application Insights 원격 분석을 추가하면 다음 파일이 추가됩니다.

  • ApplicationInsights.config
  • AiHandleErrorAttribute.cs

다음과 같은 코드 조각이 추가됩니다.

  • [프로젝트 이름].csproj

     <ApplicationInsightsResourceId>/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/Default-ApplicationInsights-EastUS/providers/microsoft.insights/components/WebApplication4</ApplicationInsightsResourceId>
    
  • Packages.config

    <packages>
    ...
    
      <package id="Microsoft.ApplicationInsights" version="2.12.0" targetFramework="net472" />
      <package id="Microsoft.ApplicationInsights.Agent.Intercept" version="2.4.0" targetFramework="net472" />
      <package id="Microsoft.ApplicationInsights.DependencyCollector" version="2.12.0" targetFramework="net472" />
      <package id="Microsoft.ApplicationInsights.PerfCounterCollector" version="2.12.0" targetFramework="net472" />
      <package id="Microsoft.ApplicationInsights.Web" version="2.12.0" targetFramework="net472" />
      <package id="Microsoft.ApplicationInsights.WindowsServer" version="2.12.0" targetFramework="net472" />
      <package id="Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel" version="2.12.0" targetFramework="net472" />
    
      <package id="Microsoft.AspNet.TelemetryCorrelation" version="1.0.7" targetFramework="net472" />
    
      <package id="System.Buffers" version="4.4.0" targetFramework="net472" />
      <package id="System.Diagnostics.DiagnosticSource" version="4.6.0" targetFramework="net472" />
      <package id="System.Memory" version="4.5.3" targetFramework="net472" />
      <package id="System.Numerics.Vectors" version="4.4.0" targetFramework="net472" />
      <package id="System.Runtime.CompilerServices.Unsafe" version="4.5.2" targetFramework="net472" />
    ...
    </packages>
    
  • Layout.cshtml

    프로젝트에 Layout.cshtml 파일이 있는 경우에는 아래 코드가 추가됩니다.

    <head>
    ...
        <script type = 'text/javascript' >
            var appInsights=window.appInsights||function(config)
            {
                function r(config){ t[config] = function(){ var i = arguments; t.queue.push(function(){ t[config].apply(t, i)})} }
                var t = { config:config},u=document,e=window,o='script',s=u.createElement(o),i,f;for(s.src=config.url||'//az416426.vo.msecnd.net/scripts/a/ai.0.js',u.getElementsByTagName(o)[0].parentNode.appendChild(s),t.cookie=u.cookie,t.queue=[],i=['Event','Exception','Metric','PageView','Trace','Ajax'];i.length;)r('track'+i.pop());return r('setAuthenticatedUserContext'),r('clearAuthenticatedUserContext'),config.disableExceptionTracking||(i='onerror',r('_'+i),f=e[i],e[i]=function(config, r, u, e, o) { var s = f && f(config, r, u, e, o); return s !== !0 && t['_' + i](config, r, u, e, o),s}),t
            }({
                instrumentationKey:'00000000-0000-0000-0000-000000000000'
            });
    
            window.appInsights=appInsights;
            appInsights.trackPageView();
        </script>
    ...
    </head>
    
  • ConnectedService.json

    {
      "ProviderId": "Microsoft.ApplicationInsights.ConnectedService.ConnectedServiceProvider",
      "Version": "16.0.0.0",
      "GettingStartedDocument": {
        "Uri": "https://go.microsoft.com/fwlink/?LinkID=613413"
      }
    }
    
  • FilterConfig.cs

            public static void RegisterGlobalFilters(GlobalFilterCollection filters)
            {
                filters.Add(new ErrorHandler.AiHandleErrorAttribute());// This line was added
            }
    

문제 해결

전용 문제 해결 문서를 참조하세요.

Visual Studio 2019의 현재 버전에 알려진 문제가 있습니다. .NET Framework 기반 앱에서 계측 키 또는 연결 문자열을 사용자 비밀에 저장할 수 없습니다. 이 버그를 해결하려면 키를 applicationinsights.config 파일에 하드 코드해야 합니다. 이 문서는 사용자 비밀을 사용하지 않고 이 문제를 완전히 방지하도록 설계되었습니다.

애플리케이션 호스트와 수집 서비스 간의 연결 테스트

Application Insights SDK 및 에이전트는 수집 엔드포인트에 대한 REST 호출로 수집하기 위해 원격 분석을 보냅니다. PowerShell 또는 curl 명령의 원시 REST 클라이언트를 사용하여 웹 서버 또는 애플리케이션 호스트 컴퓨터에서 수집 서비스 엔드포인트로의 연결을 테스트할 수 있습니다. Azure Monitor Application Insights에서 누락된 애플리케이션 원격 분석 문제 해결을 참조하세요.

오픈 소스 SDK

코드를 읽고 기여합니다.

최신 업데이트 및 버그 수정에 대해서는 릴리스 정보를 참조하세요.

릴리스 정보

버전 2.12 이상: .NET SDK(ASP.NET, ASP.NET Core 및 로깅 어댑터 포함)

서비스 업데이트에는 주요 Application Insights 개선 사항도 요약되어 있습니다.

다음 단계

  • 가상 트랜잭션을 추가하여 가용성 모니터링을 통해 전 세계에서 웹 사이트를 사용할 수 있는지 테스트합니다.
  • 샘플링을 구성하면 원격 분석 트래픽과 데이터 스토리지 비용을 줄이는 데 도움이 됩니다.