---
name: appinsights-instrumentation
description: "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."
license: MIT
metadata:
  author: Microsoft
  version: "1.2.2"

---

## 功能说明

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.

## 快速安装

```bash
npx skills add https://github.com/microsoft/azure-skills --skill appinsights-instrumentation
```

### 交给 AI 助手使用

以下是页面提示词的中文转述，命令保持原样。

```text
运行 npx skills use "https://github.com/microsoft/azure-skills" --skill "appinsights-instrumentation"，完整阅读输出并按 Skill 说明操作。必要时先将输出保存到临时文件；相对路径以输出提供的支持文件目录为准。
```

## 补充说明

Guidance for instrumenting webapps with Azure Application Insights. Provides telemetry patterns, SDK setup, and configuration references. WHEN: how to...

---

# AppInsights Instrumentation Guide

This skill provides **guidance and reference material** for instrumenting webapps with Azure Application Insights.

> **⛔ ADDING COMPONENTS?**
>
> If the user wants to **add App Insights to their app**, invoke **azure-prepare** instead.
> This skill provides reference material—azure-prepare orchestrates the actual changes.

## When to Use This Skill

- User asks **how** to instrument (guidance, patterns, examples)
- User needs SDK setup instructions
- azure-prepare invokes this skill during research phase
- User wants to understand App Insights concepts

## When to Use azure-prepare Instead

- User says "add telemetry to my app"
- User says "add App Insights" 
- User wants to modify their project
- Any request to change/add components

## Prerequisites

The app in the workspace must be one of these kinds

- An ASP.NET Core app hosted in Azure
- An Azure Container App
- A Node.js app hosted in Azure
- A Python app hosted in Azure

## Guidelines

### Collect context information

Find out the (programming language, application framework, hosting) tuple of the application the user is trying to add telemetry support in. This determines how the application can be instrumented. Read the source code to make an educated guess. Confirm with the user on anything you don't know. You must always ask the user where the application is hosted (e.g. on a personal computer, in an Azure App Service as code, in an Azure App Service as container, in an Azure Container App, etc.). 

### Prefer auto-instrument if possible

If the app is a C# ASP.NET Core app hosted in Azure App Service, use [AUTO guide](https://github.com/microsoft/azure-skills/blob/main/skills/appinsights-instrumentation/references/auto.md) to help user auto-instrument the app.

### Manually instrument

Manually instrument the app by creating the AppInsights resource and update the app's code. 

#### Create AppInsights resource

Use one of the following options that fits the environment.

- Add AppInsights to existing Bicep template. See [examples/appinsights.bicep](https://github.com/microsoft/azure-skills/blob/main/skills/appinsights-instrumentation/examples/appinsights.bicep) for what to add. This is the best option if there are existing Bicep template files in the workspace.
- Use Azure CLI. See [scripts/appinsights.ps1](https://github.com/microsoft/azure-skills/blob/main/skills/appinsights-instrumentation/scripts/appinsights.ps1) for what Azure CLI command to execute to create the App Insights resource.

No matter which option you choose, recommend the user to create the App Insights resource in a meaningful resource group that makes managing resources easier. A good candidate will be the same resource group that contains the resources for the hosted app in Azure.

#### Modify application code

- If the app is an ASP.NET Core app, see [ASPNETCORE guide](https://github.com/microsoft/azure-skills/blob/main/skills/appinsights-instrumentation/references/aspnetcore.md) for how to modify the C# code.
- If the app is a Node.js app, see [NODEJS guide](https://github.com/microsoft/azure-skills/blob/main/skills/appinsights-instrumentation/references/nodejs.md) for how to modify the JavaScript/TypeScript code.
- If the app is a Python app, see [PYTHON guide](https://github.com/microsoft/azure-skills/blob/main/skills/appinsights-instrumentation/references/python.md) for how to modify the Python code.

## SDK Quick References

- **OpenTelemetry Distro**: [Python](https://github.com/microsoft/azure-skills/blob/main/skills/appinsights-instrumentation/references/sdk/azure-monitor-opentelemetry-py.md) | [TypeScript](https://github.com/microsoft/azure-skills/blob/main/skills/appinsights-instrumentation/references/sdk/azure-monitor-opentelemetry-ts.md)
- **OpenTelemetry Exporter**: [Python](https://github.com/microsoft/azure-skills/blob/main/skills/appinsights-instrumentation/references/sdk/azure-monitor-opentelemetry-exporter-py.md) | [Java](https://github.com/microsoft/azure-skills/blob/main/skills/appinsights-instrumentation/references/sdk/azure-monitor-opentelemetry-exporter-java.md)

## Platform-Specific Guides

- **Container Apps**: [Observability Guide](https://github.com/microsoft/azure-skills/blob/main/skills/appinsights-instrumentation/references/container-apps.md)

## 来源与许可

microsoft/azure-skills 提供此 Skill，适用 MIT。本版本追加了安装和访问入口，并将相对文档链接解析为 GitHub 地址；原始文件可从下方原文入口获取。

```text
MIT License

Copyright 2025 (c) Microsoft Corporation.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE
```

[在 GitHub 查看原文](https://github.com/microsoft/azure-skills/blob/main/skills/appinsights-instrumentation/SKILL.md)

[查看更多详情](https://9527.codes)
