【发布时间】:2020-08-02 22:45:42
【问题描述】:
我有一个 ASP.NET Core 2.1 WebApi 在反向代理(Azure 应用程序网关)后面的 Service Fabric 节点上运行。
网址如下:
- https://mycustomdomain.demo/product/api/controller/action(公开)
- http://myinternalserver:12345/product/api/controller/action(内部)
- https://mycustomdomain.demo/controller/action(应用洞察请求遥测)
Application Insights 照常添加。
public void ConfigureServices(IServiceCollection services)
{
services.AddApplicationInsightsTelemetry();
new ServiceInstanceListener(serviceContext => new HttpSysCommunicationListener(serviceContext, "ServerServiceEndpoint",
(url, listener) =>
{
var endpointConfig = serviceContext.CodePackageActivationContext.GetEndpoint("ServerServiceEndpoint");
return new WebHostBuilder()
.UseHttpSys()
.ConfigureServices(services => services.AddSingleton(serviceContext))
.UseContentRoot(Directory.GetCurrentDirectory())
.UseServiceFabricIntegration(listener, ServiceFabricIntegrationOptions.None)
.UseStartup<Startup>()
.UseUrls($"{url}{endpointConfig.PathSuffix}") // "/product/api"
.Build();
}))
所以endpointConfig.PathSuffix 没有被添加到请求遥测中。我能做些什么来解决这个问题?我更愿意编写自定义遥测初始化程序或处理器。
我尝试将此行添加到我的 WebHostBuilder 中,但行为没有任何改变:
.Configure(app => app.UsePathBase(endpointConfig.PathSuffix))
编辑:PathBase 被 ASP.NET Core 正确识别,但请求遥测中缺少它。如果我设置一个没有 Service Fabric 的独立项目,PathBase 会按预期添加到 Request Telemetry。
【问题讨论】:
标签: asp.net-core azure-service-fabric azure-application-insights