Nota:
El acceso a esta página requiere autorización. Puede intentar iniciar sesión o cambiar directorios.
El acceso a esta página requiere autorización. Puede intentar cambiar los directorios.
使用适用于 .NET 的 Application Insights Profiler,您可以跟踪托管在 Azure 应用服务的 Linux 环境中实时运行的 ASP.NET Core Web 应用中各个方法所花费的时间。 本文重点介绍了托管在 Linux 中的 Web 应用。 还可以使用 Windows 和 Mac 开发环境进行试验。
在本文中,您可以:
- 在本地计算机上设置在 Linux 上托管的 ASP.NET Core Web 应用程序。
- 使用 Azure 门户创建应用服务。
- 使用本地 Git 将本地 ASP.NET Core 项目部署到 Azure。
- 将探查器添加到 ASP.NET Core Web 应用程序。
注释
请查看 应用洞察 SDK 支持指南,了解我们经典 API SDK 的支持策略。
注意
我们建议新应用程序或客户使用 Azure Monitor OpenTelemetry 发行版来支持 Azure Monitor Application Insights。 Azure Monitor OpenTelemetry 发行版提供与 Application Insights SDK 类似的功能和体验。 可以使用 .NET、Node.js 和 Python 的迁移指南从 Application Insights SDK 进行迁移,但我们仍在努力添加更多功能以实现后向兼容性。
先决条件
- 安装最新的 .NET Core SDK。
- 根据位于入门:安装 Git 的说明安装 Git。
- 查看为 ASP.NET Core Web API 启用 Azure Monitor 探查器示例以了解相关背景。
在本地设置项目
在计算机上打开命令提示符窗口。
创建 ASP.NET Core MVC Web 应用程序:
dotnet new mvc -n LinuxProfilerTest将工作目录切换到项目的根文件夹。
添加 NuGet 包以便收集分析器的跟踪数据:
dotnet add package Azure.Monitor.OpenTelemetry.AspNetCore --prerelease dotnet add package Azure.Monitor.OpenTelemetry.Profiler --prerelease
启用 .NET Profiler
在您首选的代码编辑器中,验证是否已将 Azure Monitor OpenTelemetry Profiler for .NET 的两个包添加到
Program.cs。 添加自定义 Profiler 设置(如果适用)。在项目的
.csproj文件中,验证是否已添加以下行:<ItemGroup> <PackageReference Include="Azure.Monitor.OpenTelemetry.AspNetCore" Version="[1.*-*, 2.0.0)" /> <PackageReference Include="Azure.Monitor.OpenTelemetry.Profiler" Version="[1.*-*, 2.0.0)" /> </ItemGroup>在您的
Program.cs文件中,验证是否已添加以下行:using Azure.Monitor.OpenTelemetry.AspNetCore; using Azure.Monitor.OpenTelemetry.Profiler; /// builder.Services.AddOpenTelemetry() .UseAzureMonitor() // Enable Azure Monitor OpenTelemetry distro for ASP.NET Core .AddAzureMonitorProfiler(); // Add Azure Monitor Profiler保存并提交对本地存储库的更改:
git init git add . git commit -m "first commit"
创建用于托管项目的 Linux Web 应用
在 Azure 门户中,使用 Linux 上的应用服务创建 Web 应用环境。
转到新的 Web 应用资源,然后选择“部署中心”“FTPS 凭据”以创建部署凭据。 记下你的凭据以供稍后使用。
选择“保存”。
选择“设置”选项卡。
在下拉列表中,选择“本地 Git”,以在 Web 应用中设置本地 Git 存储库。
选择“保存”以使用 Git Clone URI 创建 Git 存储库。
部署项目
虽然可以通过多种方式将代码部署到 Azure 应用服务,但最简单的方法是通过本地 Git 进行部署。 详细了解如何从 Git 存储库部署到 Azure。
在命令提示符窗口中,浏览到项目的根文件夹。 添加 Git 远程存储库以指向应用服务上的存储库:
git remote add azure https://<username>@<app_name>.scm.chinacloudsites.cn:443/<app_name>.git- 使用创建部署凭据时所用的用户名。
- 使用通过 Linux 上的应用服务创建 Web 应用时所用的应用名称。
通过将更改推送到 Azure 来部署项目:
git push azure main
添加 Application Insights 来监视 Web 应用
可以在创建应用服务时启用 Application Insights,该服务会自动设置连接字符串。
从 Application Insights 资源复制并粘贴连接字符串,以监视 Web 应用。
故障排除
如果无法在应用中找到踪迹,请考虑按照本 故障排除指南中的步骤进行操作。