应用程序洞察在本地运行的Azure工作函数中不起作用

f0brbegy  于 2023-01-05  发布在  其他
关注(0)|答案(1)|浏览(137)

我正在尝试让应用洞察在本地.NET 7 Worker Azure Function中工作

public class Tools
{
    public Tools(ILoggerFactory loggerFactory)
    {
        _logger = loggerFactory.CreateLogger<Tools>();
    }
    
    [Function("test-app-insights")]
    public async Task<IActionResult> TestAppInsightsAsync([HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "tools/test-app-insights")]
            HttpRequest req)
    {
        _logger.LogInformation("HELLOFROMNEWFUNCTION");
        await Task.Yield();

        var response = 0;
        var okResponse = new OkObjectResult(response);
        return okResponse;
    }
}

我已添加以下代码来配置服务,但App Insights中未显示任何内容,也未出现任何错误

var appInsightsConnectionString = "MY CONNECTION STRING";

        services.AddApplicationInsightsTelemetryWorkerService((a =>
        {
            a.EnableAdaptiveSampling = false;
            a.ConnectionString = appInsightsConnectionString;
        }));

有人知道我错过了什么吗?
我在host.json的日志记录部分中有这个

"logging": {
    "logLevel": {
      "default": "Information",
      "Microsoft": "Warning",
      "System": "Warning",
      "Host": "Error",
      "Function": "Error",
      "Host.Aggregator": "Information"
    },
    "Serilog": {
      "MinimumLevel": "Information",
      "WriteTo": [
        {
          "Name": "Console",
          "Args": {
            "outputTemplate": "{Timestamp:HH:mm:ss} {Level} | {RequestId} - {Message}{NewLine}{Exception}"
          }
        }
      ]
    },
    "applicationInsights": {
      "samplingSettings": {
        "isEnabled": true
      }
    }
  },

保罗

9jyewag0

9jyewag01#

创建Application Insights示例并复制检测密钥以供以后使用。

  • 创建一个Function App .

  • 创建函数应用程序时启用Application Insights选项。

  • 选择我们在上一步中创建的Application Insights。

  • 确保Application Insights和Function App的区域相同。
  • 启用ApplicationInsights后,InstrumentationKey将自动添加到Application Settings中。

  • 在Visual Studio中,使用.NET 7独立创建函数应用程序。
    我的host.json
{
    "version": "2.0",
    "logging": {
        "applicationInsights": {
            "samplingSettings": {
                "isEnabled": true,
                "excludedTypes": "Request"
            }
        }
    }
}

我的local.settings.json

{

"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated",
"APPINSIGHTS_INSTRUMENTATIONKEY": "Copy from Application Insights "
 }
}

我在Azure Application Insights示例中的跟踪:

相关问题