Azure Application Insights Management Client Library

4.1.0 · active · verified Thu Apr 09

The `azure-mgmt-applicationinsights` library is the Microsoft Azure Application Insights Management Client for Python, providing programmatic access to manage Application Insights resources. It allows you to create, update, delete, and list Application Insights components and related entities. As part of the Azure SDK for Python, it follows a regular release cadence, with the current stable version being 4.1.0.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to authenticate with Azure using `DefaultAzureCredential` and then list all Application Insights components within a specified Azure subscription using `ApplicationInsightsManagementClient`. It's crucial to set the `AZURE_SUBSCRIPTION_ID` environment variable or replace the placeholder.

import os
from azure.identity import DefaultAzureCredential
from azure.mgmt.applicationinsights import ApplicationInsightsManagementClient

# Ensure you have your Azure Subscription ID set as an environment variable or hardcoded.
# For a production environment, use environment variables or Azure Key Vault.
subscription_id = os.environ.get("AZURE_SUBSCRIPTION_ID", "YOUR_SUBSCRIPTION_ID")

if not subscription_id or subscription_id == "YOUR_SUBSCRIPTION_ID":
    raise ValueError("AZURE_SUBSCRIPTION_ID environment variable is required for this example.")

# Authenticate with Azure using DefaultAzureCredential.
# This credential type attempts to authenticate through multiple methods,
# including environment variables (AZURE_CLIENT_ID, AZURE_CLIENT_SECRET, AZURE_TENANT_ID),
# managed identity, Visual Studio Code, Azure CLI, etc.
credential = DefaultAzureCredential()

# Create an Application Insights Management Client
client = ApplicationInsightsManagementClient(credential, subscription_id)

# Example: List all Application Insights components in the subscription
print("Listing all Application Insights components in the subscription...")
try:
    for component in client.components.list():
        print(f"  - Name: {component.name}, Resource Group: {component.resource_group_name}, Location: {component.location}, Kind: {component.kind}")
    print("\nSuccessfully listed Application Insights components.")
except Exception as e:
    print(f"An error occurred: {e}")
    print("Please ensure your AZURE_SUBSCRIPTION_ID is correct and your credentials have 'Reader' role on the subscription.")

view raw JSON →