【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

相关文章
|
10月前
|
存储 监控 测试技术
如何将现有的应用程序迁移到Docker容器中?
如何将现有的应用程序迁移到Docker容器中?
723 57
|
7月前
|
开发框架 .NET C#
ASP.NET Core Blazor 路由配置和导航
大家好,我是码农刚子。本文系统介绍Blazor单页应用的路由机制,涵盖基础配置、路由参数、编程式导航及高级功能。通过@page指令定义路由,支持参数约束、可选参数与通配符捕获,结合NavigationManager实现页面跳转与参数传递,并演示用户管理、产品展示等典型场景,全面掌握Blazor路由从入门到实战的完整方案。
604 6
|
缓存 Shell 网络安全
将应用程序打包成Docker镜像时可能遇到哪些问题?
将应用程序打包成Docker镜像时可能遇到哪些问题?
1049 77
|
关系型数据库 MySQL API
|
开发框架 .NET 开发者
简化 ASP.NET Core 依赖注入(DI)注册-Scrutor
Scrutor 是一个简化 ASP.NET Core 应用程序中依赖注入(DI)注册过程的开源库,支持自动扫描和注册服务。通过简单的配置,开发者可以轻松地从指定程序集中筛选、注册服务,并设置其生命周期,同时支持服务装饰等高级功能。适用于大型项目,提高代码的可维护性和简洁性。仓库地址:<https://github.com/khellang/Scrutor>
644 5
|
JSON 数据格式
【Azure Fabric Service】演示使用PowerShell命令部署SF应用程序(.NET)
本文详细介绍了在中国区微软云Azure上使用Service Fabrics服务时,通过PowerShell命令发布.NET应用的全过程。由于Visual Studio 2022无法直接发布应用,需借助PowerShell脚本完成部署。文章分三步讲解:首先在Visual Studio 2022中打包应用部署包,其次连接SF集群并上传部署包,最后注册应用类型、创建实例并启动服务。过程中涉及关键参数如服务器证书指纹和服务端证书指纹的获取,并附带图文说明,便于操作。参考官方文档,帮助用户成功部署并运行服务。
409 73
|
监控 Docker 容器
在Docker容器中运行打包好的应用程序
在Docker容器中运行打包好的应用程序
1116 164
|
Docker 容器
将本地的应用程序打包成Docker镜像
将本地的应用程序打包成Docker镜像
2187 122
|
开发框架 .NET C#
在 ASP.NET Core 中创建 gRPC 客户端和服务器
本文介绍了如何使用 gRPC 框架搭建一个简单的“Hello World”示例。首先创建了一个名为 GrpcDemo 的解决方案,其中包含一个 gRPC 服务端项目 GrpcServer 和一个客户端项目 GrpcClient。服务端通过定义 `greeter.proto` 文件中的服务和消息类型,实现了一个简单的问候服务 `GreeterService`。客户端则通过 gRPC 客户端库连接到服务端并调用其 `SayHello` 方法,展示了 gRPC 在 C# 中的基本使用方法。
444 5
在 ASP.NET Core 中创建 gRPC 客户端和服务器

热门文章

最新文章