返回技能市场
开发运维 安全

appinsights-instrumentation

@admin/appinsights-instrumentation

Guidance for instrumenting webapps with Azure Application Insights. Provides telemetry patterns, SDK setup, and configuration references. WHEN: how to instrument app, App Insights SDK, telemetry patterns, what is App Insights, Application Insights guidance, instrumentation examples, APM best practices.

admin 热度 452v0.0.1

AppInsights 插桩指南

本技能提供指导与参考材料,用于使用 Azure Application Insights 对 Web 应用进行插桩。

⛔ 正在添加组件?
如果用户想要将 App Insights 添加到其应用,请改为调用 azure-prepare
本技能提供参考材料——azure-prepare 负责协调实际更改。

何时使用此技能

  • 用户询问如何进行插桩(指导、模式、示例)
  • 用户需要 SDK 设置说明
  • azure-prepare 在研究阶段调用此技能
  • 用户希望理解 App Insights 概念

何时改为使用 azure-prepare

  • 用户说“将遥测添加到我的应用”
  • 用户说“添加 App Insights”
  • 用户希望修改其项目
  • 任何更改/添加组件的请求

先决条件

工作区中的应用必须是以下类型之一

  • 托管在 Azure 中的 ASP.NET Core 应用
  • 托管在 Azure 中的 Node.js 应用

指南

收集上下文信息

查明用户尝试添加遥测支持的应用的(编程语言、应用框架、托管)元组。这决定了应用可以如何插桩。阅读源代码以做出有依据的猜测。对任何你不知道的内容与用户确认。你必须始终询问用户应用托管在哪里(例如,在个人计算机上、作为代码的 Azure App Service 中、作为容器的 Azure App Service 中、Azure Container App 中等)。

尽可能优先使用自动插桩

如果应用是托管在 Azure App Service 中的 C# ASP.NET Core 应用,请使用 [自动插桩指南](references/auto.md) 帮助用户自动插桩应用。

手动插桩

通过创建 AppInsights 资源并更新应用代码来手动插桩应用。

创建 AppInsights 资源

使用以下适合环境的选项之一。

  • 将 AppInsights 添加到现有 Bicep 模板。参见 [examples/appinsights.bicep](examples/appinsights.bicep) 以了解需要添加的内容。如果工作区中已有 Bicep 模板文件,这是最佳选项。
  • 使用 Azure CLI。参见 [scripts/appinsights.ps1](scripts/appinsights.ps1) 以了解要执行哪些 Azure CLI 命令来创建 App Insights 资源。

无论你选择哪个选项,都建议用户在一个有意义的资源组中创建 App Insights 资源,以便更容易管理资源。一个合适候选项是包含托管在 Azure 中的应用资源的同一资源组。

修改应用代码

  • 如果应用是 ASP.NET Core 应用,请参阅 [ASPNETCORE 指南](references/aspnetcore.md) 以了解如何修改 C# 代码。
  • 如果应用是 Node.js 应用,请参阅 [NODEJS 指南](references/nodejs.md) 以了解如何修改 JavaScript/TypeScript 代码。
  • 如果应用是 Python 应用,请参阅 [PYTHON 指南](references/python.md) 以了解如何修改 Python 代码。

SDK 快速参考

  • OpenTelemetry Distro:[Python](references/sdk/azure-monitor-opentelemetry-py.md) | [TypeScript](references/sdk/azure-monitor-opentelemetry-ts.md)
  • OpenTelemetry Exporter:[Python](references/sdk/azure-monitor-opentelemetry-exporter-py.md) | [Java](references/sdk/azure-monitor-opentelemetry-exporter-java.md)

平台特定指南

  • Container Apps:[可观测性指南](references/container-apps.md)
qianwen skills install @admin/appinsights-instrumentation