【Azure 应用程序见解】在Docker中运行的ASP.NET Core应用如何开启Application Insights的Profiler Trace呢?

简介: 【Azure 应用程序见解】在Docker中运行的ASP.NET Core应用如何开启Application Insights的Profiler Trace呢?

问题描述

使用Azure Application Insights收集AKS中ASP.NET Core应用的监控数据,自动收集请求的Trace情况,用于分析单个请求在应用内部的耗时及处理事件情况,参考Application Insights的文档,功能“Profiler Trace”可以追踪请求详情,但是在中国区的Application Insights中,确没有发现Profiler Trace功能。这里需要如何在Docker文件中配置呢?

 

 

期望结果 实际结果

 

 

 

 

 

那这里需要如何设置才能查看到Profiler Trace呢?

 

问题解决

根据示例的Docker代码,需要在构建镜像时候配置正确的Application Insights Connect String。而在文档中使用的是APPINSIGHTS_INSTRUMENTATIONKEY的方式,所以这里需要修改为APPLICATIONINSIGHTS_CONNECTION_STRING, 并且需要在其中必须包含Profiler 的Endpoint: ProfilerEndpoint=https://profiler.monitor.azure.cn/ 。

FROM mcr.microsoft.com/dotnet/sdk:3.1 AS build-env
WORKDIR /app
# Copy everything and build
COPY . ./
# Adding a reference to hosting startup package
RUN dotnet add package Microsoft.ApplicationInsights.Profiler.AspNetCore -v 2.*
# Restore & publish the app
RUN dotnet publish -c Release -o out
# Build runtime image
FROM mcr.microsoft.com/dotnet/aspnet:3.1
# Create an argument to allow docker builder to passing in application insights key.
# For example: docker build . --build-arg APPINSIGHTS_CONNECTION_STRING=YOUR_APPLICATIONINSIGHTS_INSTRUMENTATION_CONNECTION_STRING
ARG APPINSIGHTS_CONNECTION_STRING
# Making sure the argument is set. Fail the build of the container otherwise.
RUN test -n "$APPINSIGHTS_CONNECTION_STRING"
# Light up Application Insights and Service Profiler
ENV APPLICATIONINSIGHTS_CONNECTION_STRING $APPINSIGHTS_CONNECTION_STRING
ENV ASPNETCORE_HOSTINGSTARTUPASSEMBLIES Microsoft.ApplicationInsights.Profiler.AspNetCore
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "EnableServiceProfilerForContainerApp.dll"]

APPLICATIONINSIGHTS_CONNECT_STRING格式如下:

InstrumentationKey=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx;EndpointSuffix=applicationinsights.azure.cn;IngestionEndpoint=https://chinaeast2-0.in.applicationinsights.azure.cn/;ProfilerEndpoint=https://profiler.monitor.azure.cn/

 

参考资料

Enable Service Profiler for containerized ASP.NET Core applicationhttps://github.com/microsoft/ApplicationInsights-Profiler-AspNetCore/tree/main/examples/EnableServiceProfilerForContainerApp

Profile production applications in Azure with Application Insights:https://docs.microsoft.com/en-us/azure/azure-monitor/app/profiler-overview#view-profiler-data

相关文章
|
20天前
|
开发框架 JavaScript 前端开发
【App Service】解决 .NET Profiler 报告打开后无数据加载的问题
【App Service】解决 .NET Profiler 报告打开后无数据加载的问题
|
20天前
|
开发框架 .NET 开发工具
【Azure 应用服务】App Service 的.NET Version选择为.NET6,是否可以同时支持运行ASP.NET V4.8的应用呢?
【Azure 应用服务】App Service 的.NET Version选择为.NET6,是否可以同时支持运行ASP.NET V4.8的应用呢?
|
21天前
|
Linux C# C++
【Azure App Service For Container】创建ASP.NET Core Blazor项目并打包为Linux镜像发布到Azure应用服务
【Azure App Service For Container】创建ASP.NET Core Blazor项目并打包为Linux镜像发布到Azure应用服务
|
30天前
|
开发框架 .NET API
如何在 ASP.NET Core Web Api 项目中应用 NLog 写日志?
如何在 ASP.NET Core Web Api 项目中应用 NLog 写日志?
|
7天前
|
开发框架 前端开发 JavaScript
ASP.NET MVC 教程
ASP.NET 是一个使用 HTML、CSS、JavaScript 和服务器脚本创建网页和网站的开发框架。
20 7
|
5天前
|
存储 开发框架 前端开发
ASP.NET MVC 迅速集成 SignalR
ASP.NET MVC 迅速集成 SignalR
16 0
|
29天前
|
开发框架 前端开发 .NET
ASP.NET MVC WebApi 接口返回 JOSN 日期格式化 date format
ASP.NET MVC WebApi 接口返回 JOSN 日期格式化 date format
29 0
|
30天前
|
开发框架 前端开发 安全
ASP.NET MVC 如何使用 Form Authentication?
ASP.NET MVC 如何使用 Form Authentication?
|
1月前
|
开发框架 .NET
Asp.Net Core 使用X.PagedList.Mvc.Core分页 & 搜索
Asp.Net Core 使用X.PagedList.Mvc.Core分页 & 搜索
79 0
|
4月前
|
开发框架 前端开发 .NET
ASP.NET CORE 3.1 MVC“指定的网络名不再可用\企图在不存在的网络连接上进行操作”的问题解决过程
ASP.NET CORE 3.1 MVC“指定的网络名不再可用\企图在不存在的网络连接上进行操作”的问题解决过程
145 0