1

According to the documentation you need to add the following to your applicationInsights.config file to enable full SQL logging:

<Add Type="Microsoft.ApplicationInsights.DependencyCollector.DependencyTrackingTelemetryModule, Microsoft.AI.DependencyCollector">
    <EnableSqlCommandTextInstrumentation>true</EnableSqlCommandTextInstrumentation>
</Add>

But in my ASP.NET app running on .NET Framework 4.7.2 hosted in an Azure App Service I'm enabling/configuring Application Insights via code:

TelemetryConfiguration.Active.DisableTelemetry = false;
TelemetryConfiguration.Active.InstrumentationKey = setting.ApplicationInsightsInstrumentationKey;

How can I enable this setting via code?

P.S.: The settings in the Web App are correctly enabled.

Christoph Fink
  • 22,727
  • 9
  • 68
  • 113

2 Answers2

1

It seems even if AI is enabled via code it picks up the settings from the config file.
I added it to my applicationInsights.config and it seems to work now.

Christoph Fink
  • 22,727
  • 9
  • 68
  • 113
0

In Startup.cs:

public void ConfigureServices(IServiceCollection services) {

    services.AddApplicationInsightsTelemetry(o => { ... });

    services.ConfigureTelemetryModule<DependencyTrackingTelemetryModule>(
        (module, o) => { module.EnableSqlCommandTextInstrumentation = true; }
    );
}

I looks like Microsoft has added the code configuration to their documentation now:

smaglio81
  • 501
  • 1
  • 6
  • 13