azure-functionsazure-application-insightssqldependency

Azure Function + Application Insights - not tracking SQL Queries


We have an Http Triggered Azure Function (.NET Core 3.1). For whatever reason we can't get the detailed SQL Dependency Tracking working, all we see is: tcp:ourdbserver.database.windows.net,1433 | TestDB.

It doesn't work both when debugging locally and when deployed to Azure. We've installed the latest ApplicationInsights nuget package (see below):

enter image description here

And in the StartUp we opt-in to SQL Text collection as suggested by Microsoft docs here:

enter image description here

Could anyone please shed some light on what we are missing?

UPDATE:

This is what we have in the host.json:

{
  "version": "2.0",
  "logging": {
    "applicationInsights": {
      "samplingExcludedTypes": "Request",
      "samplingSettings": {
        "isEnabled": true
      }
    }
  }
}

And here is what gets outputted into the Debug console when debugging locally:

ApplicationInsightsLoggerOptions
{
  "SamplingSettings": {
    "EvaluationInterval": "00:00:15",
    "InitialSamplingPercentage": 100.0,
    "MaxSamplingPercentage": 100.0,
    "MaxTelemetryItemsPerSecond": 20.0,
    "MinSamplingPercentage": 0.1,
    "MovingAverageRatio": 0.25,
    "SamplingPercentageDecreaseTimeout": "00:02:00",
    "SamplingPercentageIncreaseTimeout": "00:15:00"
  },
  "SamplingExcludedTypes": null,
  "SamplingIncludedTypes": null,
  "SnapshotConfiguration": null,
  "EnablePerformanceCountersCollection": true,
  "HttpAutoCollectionOptions": {
    "EnableHttpTriggerExtendedInfoCollection": true,
    "EnableW3CDistributedTracing": true,
    "EnableResponseHeaderInjection": true
  },
  "LiveMetricsInitializationDelay": "00:00:15",
  "EnableLiveMetrics": true,
  "EnableDependencyTracking": true
}

Solution

  • You need to configure dependencyTrackingOptions.enableSqlCommandTextInstrumentation in the host.json file:

    {
      "logging": {
        "applicationInsights": {
          "dependencyTrackingOptions": {
            "enableSqlCommandTextInstrumentation": true
          }
        }
      }
    }