Azure Function + Application Insights - 不跟踪 SQL 查询
Azure Function + Application Insights - not tracking SQL Queries
我们有一个 Http 触发的 Azure 函数 (.NET Core 3.1)。无论出于何种原因,我们无法获得详细的 SQL 依赖性跟踪,我们看到的是:tcp:ourdbserver.database.windows.net,1433 | TestDB
.
在本地调试和部署到 Azure 时都不起作用。我们已经安装了最新的 ApplicationInsights nuget 包(见下文):
并且在 StartUp 中我们选择加入 SQL Microsoft 文档建议的文本收集 here:
任何人都可以阐明我们缺少的东西吗?
更新:
这就是我们在 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 中的日志记录部分以允许 Information
级别的日志(请注意,我在上面发布的现有配置中添加了 logLevel)。如果您不指定,默认情况下它是警告。如注释 here, dependencies are logged with Information level. Also note excludedTypes (not samplingExcludedTypes) should be inside samplingSettings as per documentation.
中所述
{
"version": "2.0",
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Dependency;Request"
}
},
"logLevel": {"default": "Information"}
}
}
您需要在 host.json 文件中配置 dependencyTrackingOptions.enableSqlCommandTextInstrumentation:
{
"logging": {
"applicationInsights": {
"dependencyTrackingOptions": {
"enableSqlCommandTextInstrumentation": true
}
}
}
}
我们有一个 Http 触发的 Azure 函数 (.NET Core 3.1)。无论出于何种原因,我们无法获得详细的 SQL 依赖性跟踪,我们看到的是:tcp:ourdbserver.database.windows.net,1433 | TestDB
.
在本地调试和部署到 Azure 时都不起作用。我们已经安装了最新的 ApplicationInsights nuget 包(见下文):
并且在 StartUp 中我们选择加入 SQL Microsoft 文档建议的文本收集 here:
任何人都可以阐明我们缺少的东西吗?
更新:
这就是我们在 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 中的日志记录部分以允许 Information
级别的日志(请注意,我在上面发布的现有配置中添加了 logLevel)。如果您不指定,默认情况下它是警告。如注释 here, dependencies are logged with Information level. Also note excludedTypes (not samplingExcludedTypes) should be inside samplingSettings as per documentation.
{
"version": "2.0",
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Dependency;Request"
}
},
"logLevel": {"default": "Information"}
}
}
您需要在 host.json 文件中配置 dependencyTrackingOptions.enableSqlCommandTextInstrumentation:
{
"logging": {
"applicationInsights": {
"dependencyTrackingOptions": {
"enableSqlCommandTextInstrumentation": true
}
}
}
}