Application Insights请求遥测缺少基本路径

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

我有一个ASP.NET Core 2.1 WebApi在反向代理(Azure应用程序网关)后面的Service Fabric节点上运行。

Ulls如下:

照常添加了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将按预期方式添加到“请求遥测”中。

asp.net-core azure-service-fabric azure-application-insights
1个回答
1
投票

根据docs,您需要注册TelemetryInitializer,并调用UseApplicationInsights

.UseKestrel()
    .ConfigureServices(
        services => services
            .AddSingleton<HttpClient>(new HttpClient())
            .AddSingleton<FabricClient>(new FabricClient())
            .AddSingleton<StatelessServiceContext>(serviceContext)
            .AddSingleton<ITelemetryInitializer>((serviceProvider) => FabricTelemetryInitializerExtension.CreateFabricTelemetryInitializer(serviceContext)))
    .UseContentRoot(Directory.GetCurrentDirectory())
    .UseStartup<Startup>()
    .UseApplicationInsights()
    .UseServiceFabricIntegration(listener, ServiceFabricIntegrationOptions.None)
    .UseUrls(url)
    .Build();
    ...
最新问题
© www.soinside.com 2019 - 2024. All rights reserved.