developer tip

디버그에서 애플리케이션 인사이트 비활성화

optionbox 2020. 9. 11. 07:54
반응형

디버그에서 애플리케이션 인사이트 비활성화


디버그 구성을 사용할 때 자동으로 애플리케이션 통찰력을 비활성화하고 릴리스에서만 활성화하려면 어떻게해야합니까?
디버그 용으로 만 다른 계측 키를 만들지 않고이 작업을 수행 할 수 있습니까? 코드 전체에 흩어져

있는 trackevent명령문을 디버그 전 처리기 검사 내에 포함하는 것은 이상적인 솔루션이 아닙니다.

나의 현재 솔루션은 설정하는 것입니다 Build ActionApplicationInsights.config에 파일을 None이 프로젝트의 출력 디렉터리에 복사되지 것 때문에, 그러나 이것은 활성 빌드 구성에 따라 자동화 할 수있는 과정이 아니다.

개발자 모드가 있지만 수동으로 변경해야합니다 (구성 파일을 조건부로 설정할 수있는 경우 문제가 해결 된 계측 키도 비움). 참조 http://apmtips.com/blog/2015/02/02/developer-mode/를

참조 : http://blogs.msdn.com/b/visualstudioalm/archive/2015/01/07/application-insights-support-for-multiple-environments-stamps-and-app-versions.aspx


TelemetryConfiguration.DisableTelemetry 속성 사용을 시도 할 수 있습니다 . 이런 식으로 ..

#if DEBUG
            TelemetryConfiguration.Active.DisableTelemetry = true;
#endif

다른 솔루션에 추가로 다음을 추가하는 것이 좋습니다 Global.asax.

protected void Application_Start()
{    
    DisableApplicationInsightsOnDebug();
    // do the other stuff
}

/// <summary>
/// Disables the application insights locally.
/// </summary>
[Conditional("DEBUG")]
private static void DisableApplicationInsightsOnDebug()
{
    TelemetryConfiguration.Active.DisableTelemetry = true;
}

이것의 장점은 구성을 변경할 필요가 없으며 지시문보다 더 잘 이해할 수있는 ReSharper와 같은 일부 도구에서 더 잘 작동한다는 것 #입니다.


ASP.NET Core 프로젝트의 경우 App Insights는 기본적으로 켜져 있으며 실제로 디버그 창에 많은 정보를 기록합니다.

비활성화하려면 "도구-> 옵션-> 프로젝트 및 솔루션-> 웹 프로젝트"로 이동하여 "Asp.Net Core 웹 프로젝트에 대한 로컬 Application Insights 비활성화"를 선택하십시오.

아래는 로컬 앱 인사이트를 비활성화하는 이미지입니다.

영상

이 문제에 대한 자세한 내용은 여기 에서 공식 github 문제를 볼 수 있습니다.


<instrumentationkey>key</instrumentationkey>블록 이벤트가 생성 되지 않고 ApplicationInsights.config를 배포하거나 배포하지 않는 질문에 설명 된대로 . 그런 다음 계측 키를 코드에 넣을 수 있습니다 (제 경우에는 릴리스시에만)

#if !DEBUG
    Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration.Active.InstrumentationKey = "instrumentation key";
#endif

Every TelemetryClient created after this call will have the correct key and will track events so you don't have to change the code in all places. Not calling the method above or leaving the parameter empty will block events because there isn't a key configured.

Basically the ApplicationInsights.config file overrides any code that set the instrumentation key, removing the <instrumentationkey>key</instrumentationkey> inside it will let you use code to configure the key. If you remove the file completely it doesn't work.

Here is the confirm: "If you want to set the key dynamically - for example if you want to send results from your application to different resources - you can omit the key from the configuration file, and set it in code instead."

Reference: https://azure.microsoft.com/en-us/documentation/articles/app-insights-configuration-with-applicationinsights-config/#_instrumentationkey


I have decided to use both approaches. I have moved the InstrumentationKey to the Web.config and it will be replaced by the transformation from Web.Release.config or Web.Debug.config. (don't forget to remove it from the ApplicationInsights.config file). Then I have called this method from the Application_Start()

public static void RegisterTelemetryInstrumentationKey()
{
    if (string.IsNullOrWhiteSpace(WebConfigurationManager.AppSettings["TelemetryInstrumentationKey"])
    {
        TelemetryConfiguration.Active.DisableTelemetry = true;
    }
    else
    {
        TelemetryConfiguration.Active.InstrumentationKey = AppSettings.TelemetryInstrumentationKey;
    }
}

Running an ASP.NET Core 2.1 web application with Visual Studio 2017 (15.9.2) the "Disable local Application Insights for Asp.Net Core web projects" did not clear up the output in my Debug window.

However adding the following to Configure() in Startup.cs did the job;

if (_env.IsDevelopment())
{
    app.UseDeveloperExceptionPage();
    TelemetryConfiguration.Active.DisableTelemetry = true;
    TelemetryDebugWriter.IsTracingDisabled = true;
}

Note that the IsTracingDisabled was the key solution, but I left in DisableTelemetry for good measure! Plus having both lines next to one another is helpful when searching for similar references between .NET Framework & .NET Core projects in the same solution.


I've just had the same issue.

We wanted to control the setting in the web.config so added a DisableAITelemetry key within our app settings:

  <appSettings>
    <add key="DisableAITelemetry" value="true" />
  </appSettings>

With live and demo builds, we won't include a value (so that it defaults to false).

We could then solve it by adding this:

bool disable;
string disableAiTelemetry = ConfigurationManager.AppSettings["DisableAITelemetry"];
bool.TryParse(disableAiTelemetry, out disable);
TelemetryConfiguration.Active.DisableTelemetry = disable;

In an ASP.NET Core application, you can add the following to the Startus.cs to turn off Application Insights in the Development environment:

if (env.IsDevelopment()) {
    TelemetryConfiguration.Active.DisableTelemetry = true;
}

Add this to the constructor, right after the builder.AddApplicationInsightsSettings(); command and you'll no longer see AI logs clogging up your debug console.


일부 다른 솔루션에서는 약간 다른 플레이가 있습니다. 이것을 global.asax에 넣으십시오.

Microsoft.ApplicationInsights.Extensibility.Implementation.TelemetryDebugWriter.IsTracingDisabled = Debugger.IsAttached;

디버거에서 실행할 때 앱 인사이트 디버그 출력을 끄지 만 Ctrl + F5 시나리오에서 허용하고 테스트 서버에 게시 된 디버그 빌드에서 허용합니다.


디버그 로그를 추적하는 것을 방지하는 가장 쉬운 방법은 다음과 같이 간단합니다.

Extensibility.Implementation.TelemetryDebugWriter.IsTracingDisabled = True

Microsoft.ApplicationInsights.AspNetCore 버전 2.1

services.AddApplicationInsightsTelemetry(options =>
{
    options.EnableDebugLogger = false;
});

         public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            #region Disable Application Insights debug informations
#if DEBUG
            TelemetryConfiguration.Active.DisableTelemetry = true;
            TelemetryDebugWriter.IsTracingDisabled = true;
#endif
            #endregion
//...
}

참고 URL : https://stackoverflow.com/questions/32057441/disable-application-insights-in-debug

반응형