【问题标题】:Azure Function + Application Insights - not tracking SQL QueriesAzure Function + Application Insights - 不跟踪 SQL 查询
【发布时间】:2020-08-28 09:36:37
【问题描述】:

我们有一个 Http 触发的 Azure 函数 (.NET Core 3.1)。无论出于何种原因,我们无法让详细的 SQL 依赖跟踪正常工作,我们所看到的只是:tcp:ourdbserver.database.windows.net,1433 | TestDB。

在本地调试和部署到 Azure 时都不起作用。我们已经安装了最新的 ApplicationInsights nuget 包(见下文):

在 StartUp 中,我们按照 Microsoft 文档 here 的建议选择加入 SQL 文本集合:

谁能解释一下我们缺少什么?

更新:

这就是我们在host.json 中的内容:

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

这是在本地调试时输出到调试控制台的内容:

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
}

【问题讨论】:

  • 您能否从 host.json 发布您的日志记录配置。乍一看,我怀疑这可能是因为 loglevel 过滤器。函数中的依赖跟踪需要启用信息级别日志,如此处突出显示的注释中所述docs.microsoft.com/en-us/azure/azure-functions/…

标签: azure-functions azure-application-insights sqldependency


【解决方案1】:

您需要在host.json文件中配置dependencyTrackingOptions.enableSqlCommandTextInstrumentation:

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

【讨论】:

    【解决方案2】:

    如下更新您在 host.json 中的日志记录部分以允许 Information 级别日志(注意我在您上面发布的现有配置中添加了 logLevel)。默认情况下,如果您未指定,则为警告。如注释here 中所述,依赖项以信息级别记录。另请注意,根据documentation,excludedTypes(不是 samplingExcludedTypes)应该在 samplingSettings 内。

    {
      "version": "2.0",
      "logging": {
        "applicationInsights": {
            "samplingSettings": {
                "isEnabled": true,
                "excludedTypes": "Dependency;Request"
            }
        },
        "logLevel": {"default": "Information"}
      }
    }
    

    【讨论】:

    • 嗯。现在我在本地运行时在调试控制台中看到了 SQL,但在 ApplicationInsights 中仍然没有。
    • 当你在 App Insights 中什么都不说时,你的意思是在本地调试时?
    • 希望您在 localsettings.json 中设置了 APPINSIGHTS_INSTRUMENTATIONKEY 吗?
    • AppInsights InstrumentationKey 设置正确,在本地调试时,所有请求、跟踪和依赖项都会记录在 AppInsights 中。唯一缺少的是 SQL 依赖项中的实际 SQL 命令。
    猜你喜欢
    • 2017-06-28
    • 2021-11-10
    • 1970-01-01
    • 2018-08-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-06
    • 2018-02-10
    相关资源
    最近更新 更多