API + 应用程序洞察跟踪

问题描述 投票:0回答:1

我有一个用 dotnet6 编写的 API,托管在 Azure 中,并配置并连接了 Application Insights。我还包含了适用于 .NET 的 AppInsights sdk

我正在努力查看初始 HTTP 调用的依赖关系图。

例如,

API > 调用对象 1 的方法 > 调用对象 2 的方法 > 调用数据库并将结果沿链向上传递,最终返回控制器并传递给调用者。

我通过 DI 使用 ILogger 在整个方法中放置了日志记录语句。我可以在 Application Insights 中看到这些,但只能一个接一个地看到。我想要的是依赖关系图...例如,在应用程序见解中单击原始 HTTP 调用,然后查看触发了哪些关联的日志记录语句。

azure azure-application-insights
1个回答
0
投票

我正在努力查看初始 HTTP 调用的依赖关系图

我已使用 Dotnet 6.0 创建了一个 Web 应用程序,并使用检测密钥配置了 Application Insights。 使用下面的代码,我成功地将依赖项记录到 Application Insights。

程序.cs:

using Microsoft.Extensions.Configuration;
using Microsoft.ApplicationInsights.DependencyCollector;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
builder.Services.AddControllers();

// Access app configuration
var configuration = builder.Configuration;

// Add Application Insights telemetry
builder.Services.AddApplicationInsightsTelemetry(configuration["ApplicationInsights:InstrumentationKey"]);

// Enable dependency tracking
builder.Services.ConfigureTelemetryModule<DependencyTrackingTelemetryModule>((module, o) =>
{
    module.EnableLegacyCorrelationHeadersInjection = true;
});

// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    app.UseSwaggerUI();
}

app.UseHttpsRedirection();
app.UseRouting();
app.UseAuthorization();
app.MapControllers();
app.Run();

appsettings.json:

{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning"
    }
  },
  "AllowedHosts": "*",
  "ApplicationInsights": {
    "InstrumentationKey": "your instrumentation key"
  }
}

enter image description here

在 Application Insights 中,依赖关系图中已成功触发依赖关系。检查如下: 输出:

enter image description here

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.