{"kind":"Skill","metadata":{"namespace":"community","name":"appinsights-instrumentation","version":"0.1.0"},"spec":{"description":"Instrument a webapp to send useful telemetry data to Azure App Insights","files":{"LICENSE.txt":"MIT License\n\nCopyright 2025 (c) Microsoft Corporation.\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE\n","SKILL.md":"---\nname: appinsights-instrumentation\ndescription: 'Instrument a webapp to send useful telemetry data to Azure App Insights'\n---\n\n# AppInsights instrumentation\n\nThis skill enables sending telemetry data of a webapp to Azure App Insights for better observability of the app's health.\n\n## When to use this skill\n\nUse this skill when the user wants to enable telemetry for their webapp.\n\n## Prerequisites\n\nThe app in the workspace must be one of these kinds\n\n- An ASP.NET Core app hosted in Azure\n- A Node.js app hosted in Azure\n\n## Guidelines\n\n### Collect context information\n\nFind 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.). \n\n### Prefer auto-instrument if possible\n\nIf the app is a C# ASP.NET Core app hosted in Azure App Service, use [AUTO guide](references/AUTO.md) to help user auto-instrument the app.\n\n### Manually instrument\n\nManually instrument the app by creating the AppInsights resource and update the app's code. \n\n#### Create AppInsights resource\n\nUse one of the following options that fits the environment.\n\n- Add AppInsights to existing Bicep template. See [examples/appinsights.bicep](examples/appinsights.bicep) for what to add. This is the best option if there are existing Bicep template files in the workspace.\n- Use Azure CLI. See [scripts/appinsights.ps1](scripts/appinsights.ps1) for what Azure CLI command to execute to create the App Insights resource.\n\nNo 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.\n\n#### Modify application code\n\n- If the app is an ASP.NET Core app, see [ASPNETCORE guide](references/ASPNETCORE.md) for how to modify the C# code.\n- If the app is a Node.js app, see [NODEJS guide](references/NODEJS.md) for how to modify the JavaScript/TypeScript code.\n- If the app is a Python app, see [PYTHON guide](references/PYTHON.md) for how to modify the Python code.\n","examples/appinsights.bicep":"@description('Location for all resources')\nparam location string = resourceGroup().location\n\n@description('Name for new Application Insights')\nparam name string\n\n// Create Log Analytics Workspace\nresource logAnalyticsWorkspace 'Microsoft.OperationalInsights/workspaces@2022-10-01' = {\n  name: '${name}-workspace'\n  location: location\n  properties: {\n    sku: {\n      name: 'PerGB2018'\n    }\n    retentionInDays: 30\n  }\n}\n\n// Create Application Insights\nresource applicationInsights 'Microsoft.Insights/components@2020-02-02' = {\n  name: name\n  location: location\n  kind: 'web'\n  properties: {\n    Application_Type: 'web'\n    WorkspaceResourceId: logAnalyticsWorkspace.id\n  }\n}\n\noutput connectionString string = applicationInsights.properties.ConnectionString\n","references/ASPNETCORE.md":"## Modify code\n\nMake these necessary changes to the app.\n\n- Install client library\n```\ndotnet add package Azure.Monitor.OpenTelemetry.AspNetCore\n```\n\n- Configure the app to use Azure Monitor\nAn ASP.NET Core app typically has a Program.cs file that \"builds\" the app. Find this file and apply these changes.\n  - Add `using Azure.Monitor.OpenTelemetry.AspNetCore;` at the top\n  - Before calling `builder.Build()`, add this line `builder.Services.AddOpenTelemetry().UseAzureMonitor();`.\n\n\u003e Note: since we modified the code of the app, the app needs to be deployed to take effect.\n\n## Configure App Insights connection string\n\nThe App Insights resource has a connection string. Add the connection string as an environment variable of the running app. You can use Azure CLI to query the connection string of the App Insights resource. See [scripts/appinsights.ps1](scripts/appinsights.ps1) for what Azure CLI command to execute for querying the connection string.\n\nAfter getting the connection string, set this environment variable with its value.\n\n```\n\"APPLICATIONINSIGHTS_CONNECTION_STRING={your_application_insights_connection_string}\"\n```\n\nIf the app has IaC template such as Bicep or terraform files representing its cloud instance, this environment variable should be added to the IaC template to be applied in each deployment. Otherwise, use Azure CLI to manually apply the environment variable to the cloud instance of the app. See [scripts/appinsights.ps1](scripts/appinsights.ps1) for what Azure CLI command to execute for setting this environment variable.\n\n\u003e Important: Don't modify appsettings.json. It was a deprecated way to configure App Insights. The environment variable is the new recommended way.\n","references/AUTO.md":"# Auto-instrument app\n\nUse Azure Portal to auto-instrument a webapp hosted in Azure App Service for App Insights without making any code changes. Only the following types of app can be auto-instrumented. See [supported environments and resource providers](https://learn.microsoft.com/azure/azure-monitor/app/codeless-overview#supported-environments-languages-and-resource-providers).\n\n- ASP.NET Core app hosted in Azure App Service\n- Node.js app hosted in Azure App Service\n\nConstruct a url to bring the user to the Application Insights blade in Azure Portal for the App Service App.\n```\nhttps://portal.azure.com/#resource/subscriptions/{subscription_id}/resourceGroups/{resource_group_name}/providers/Microsoft.Web/sites/{app_service_name}/monitoringSettings\n```\n\nUse the context or ask the user to get the subscription_id, resource_group_name, and the app_service_name hosting the webapp.\n","references/NODEJS.md":"## Modify code\n\nMake these necessary changes to the app.\n\n- Install client library\n```\nnpm install @azure/monitor-opentelemetry\n```\n\n- Configure the app to use Azure Monitor\nA Node.js app typically has an entry file that is listed as the \"main\" property in package.json. Find this file and apply these changes in it.\n  - Require the client library at the top. `const { useAzureMonitor } = require(\"@azure/monitor-opentelemetry\");`\n  - Call the setup method. `useAzureMonitor();`\n\n\u003e Note: The setup method should be called as early as possible but it must be after the environment variables are configured since it needs the App Insights connection string from the environment variable. For example, if the app uses dotenv to load environment variables, the setup method should be called after it but before anything else.\n\u003e Note: since we modified the code of the app, it needs to be deployed to take effect.\n\n## Configure App Insights connection string\n\nThe App Insights resource has a connection string. Add the connection string as an environment variable of the running app. You can use Azure CLI to query the connection string of the App Insights resource. See [scripts/appinsights.ps1] for what Azure CLI command to execute for querying the connection string.\n\nAfter getting the connection string, set this environment variable with its value.\n\n```\n\"APPLICATIONINSIGHTS_CONNECTION_STRING={your_application_insights_connection_string}\"\n```\n\nIf the app has IaC template such as Bicep or terraform files representing its cloud instance, this environment variable should be added to the IaC template to be applied in each deployment. Otherwise, use Azure CLI to manually apply the environment variable to the cloud instance of the app. See what Azure CLI command to execute for setting this environment variable.\n","references/PYTHON.md":"## Modify code\n\nMake these necessary changes to the app.\n\n- Install client library\n```\npip install azure-monitor-opentelemetry\n```\n\n- Configure the app to use Azure Monitor\nPython applications send telemetry via the logger class in Python standard library. Create a module that configures and creates a logger that can send telemetry.\n\n```python\nimport logging\nfrom azure.monitor.opentelemetry import configure_azure_monitor\n\nconfigure_azure_monitor(\n    logger_name=\"\u003cyour_logger_namespace\u003e\"\n)\nlogger = logging.getLogger(\"\u003cyour_logger_namespace\u003e\")\n```\n\n\u003e Note: since we modified the code of the app, it needs to be deployed to take effect.\n\n## Configure App Insights connection string\n\nThe App Insights resource has a connection string. Add the connection string as an environment variable of the running app. You can use Azure CLI to query the connection string of the App Insights resource. See [scripts/appinsights.ps1] for what Azure CLI command to execute for querying the connection string.\n\nAfter getting the connection string, set this environment variable with its value.\n\n```\n\"APPLICATIONINSIGHTS_CONNECTION_STRING={your_application_insights_connection_string}\"\n```\n\nIf the app has IaC template such as Bicep or terraform files representing its cloud instance, this environment variable should be added to the IaC template to be applied in each deployment. Otherwise, use Azure CLI to manually apply the environment variable to the cloud instance of the app. See what Azure CLI command to execute for setting this environment variable.\n\n## Send data\n\nCreate a logger that is configured to send telemetry.\n```python\nlogger = logging.getLogger(\"\u003cyour_logger_namespace\u003e\")\nlogger.setLevel(logging.INFO)\n```\n\nThen send telemetry events by calling its logging methods.\n```python\nlogger.info(\"info log\")\n```\n","scripts/appinsights.ps1":"# Create App Insights resource (3 steps)\n## Add the Application Insights extension\naz extension add -n application-insights\n## Create a Log Analytics workspace\naz monitor log-analytics workspace create --resource-group $resourceGroupName --workspace-name $logAnalyticsWorkspaceName --location $azureRegionName\n## Create the Application Insights resource\naz monitor app-insights component create --app $applicationInsightsResourceName --location $azureRegionName --resource-group $resourceGroupName --workspace $logAnalyticsWorkspaceName\n\n# Query connection string of App Insights\naz monitor app-insights component show --app $applicationInsightsResourceName --resource-group $resourceGroupName --query connectionString --output tsv\n\n# Set environment variable of App Service\naz webapp config appsettings set --resource-group $resourceGroupName --name $appName --settings $key=$value\n\n# Set environment variable of Container App\n# Or update an existing container app\naz containerapp update -n $containerAppName -g $resourceGroupName --set-env-vars $key=$value\n\n# Set environment variable of Function App\naz functionapp config appsettings set --name $functionName --resource-group $ResourceGroupName --settings $key=$value\n"},"import":{"commit_sha":"541b7819d8c3545c6df122491af4fa1eae415779","imported_at":"2026-05-18T20:05:35Z","license_text":"MIT License\n\nCopyright 2025 (c) Microsoft Corporation.\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE\n","owner":"github","repo":"github/awesome-copilot","source_url":"https://github.com/github/awesome-copilot/tree/541b7819d8c3545c6df122491af4fa1eae415779/skills/appinsights-instrumentation"}},"content_hash":[183,40,51,112,14,113,152,113,23,163,200,255,229,133,229,92,216,96,175,149,49,210,177,127,9,245,103,0,33,27,198,201],"trust_level":"unsigned","yanked":false}
