{"id":5568,"library":"applicationinsights","title":"Azure Application Insights Legacy Python SDK","description":"This is the *legacy* Python SDK for sending telemetry to Azure Application Insights. It allows applications to send custom events, metrics, and traces directly to Application Insights. For new applications, it is strongly recommended to use the OpenTelemetry-based `azure-monitor-opentelemetry-distro` package. The `applicationinsights` package is currently at version 0.11.10 and receives minimal updates, primarily maintenance.","status":"maintenance","version":"0.11.10","language":"python","source_language":"en","source_url":"https://github.com/Microsoft/ApplicationInsights-Python","tags":["azure","application-insights","telemetry","monitoring","legacy"],"install":[{"cmd":"pip install applicationinsights","lang":"bash","label":"Install legacy SDK"}],"dependencies":[{"reason":"Used for HTTP communication with Application Insights ingestion endpoints.","package":"requests","optional":false},{"reason":"Used for structured logging integration.","package":"python-json-logger","optional":false}],"imports":[{"symbol":"TelemetryClient","correct":"from applicationinsights import TelemetryClient"},{"symbol":"logging","correct":"import logging\nfrom applicationinsights.logging import enable"}],"quickstart":{"code":"import os\nfrom applicationinsights import TelemetryClient\n\n# For legacy SDK, use Instrumentation Key\n# Find your Instrumentation Key in your Application Insights resource in Azure Portal.\nINSTRUMENTATION_KEY = os.environ.get('APPINSIGHTS_INSTRUMENTATIONKEY', 'YOUR_LEGACY_INSTRUMENTATION_KEY')\n\nif not INSTRUMENTATION_KEY or INSTRUMENTATION_KEY == 'YOUR_LEGACY_INSTRUMENTATION_KEY':\n    print(\"Warning: APPINSIGHTS_INSTRUMENTATIONKEY not set. Telemetry will not be sent.\")\n    exit()\n\nclient = TelemetryClient(INSTRUMENTATION_KEY)\n\n# Track an event\nclient.track_event('MyLegacyPythonEvent', {'custom_property': 'value1'})\n\n# Track a metric\nclient.track_metric('MyLegacyMetric', 123.45)\n\n# Track a trace message\nclient.track_trace('This is a legacy trace message', properties={'level': 'INFO'})\n\n# Ensure telemetry is sent before application exits\nclient.flush()\nprint(\"Legacy telemetry sent.\")","lang":"python","description":"Initializes the legacy `TelemetryClient` with an Instrumentation Key and sends a basic event, metric, and trace. Remember to set the `APPINSIGHTS_INSTRUMENTATIONKEY` environment variable or replace the placeholder."},"warnings":[{"fix":"For new projects, install `azure-monitor-opentelemetry-distro` (e.g., `pip install azure-monitor-opentelemetry-distro`) and follow its documentation for OpenTelemetry-based setup. Migrating existing `applicationinsights` code requires significant changes.","message":"This `applicationinsights` package is the *legacy* Python SDK for Azure Application Insights. For all new development and recommended usage, developers should use the `azure-monitor-opentelemetry-distro` package, which is based on OpenTelemetry and offers broader instrumentation and future compatibility.","severity":"breaking","affected_versions":"All versions of `applicationinsights` (legacy SDK) vs. `azure-monitor-opentelemetry-distro` (modern SDK)"},{"fix":"Ensure you are using the correct identifier for your chosen SDK. For this legacy SDK, provide the Instrumentation Key. For the modern SDK, provide the Connection String.","message":"The legacy `applicationinsights` SDK uses an 'Instrumentation Key' for authentication. The modern OpenTelemetry-based SDK (`azure-monitor-opentelemetry-distro`) uses a 'Connection String'. These are distinct values and not interchangeable.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always include `client.flush()` at appropriate points, such as before exiting a script or at the end of a request handler in a web application. For long-running applications, consider using a periodic flush or a background thread.","message":"Telemetry sent via `TelemetryClient` is buffered in memory. If your application exits abruptly or runs for a short period, you must explicitly call `client.flush()` to ensure all buffered telemetry is sent to Application Insights before termination.","severity":"gotcha","affected_versions":"All versions"},{"fix":"It is recommended to use Python 3.7 or newer. For new applications, use the `azure-monitor-opentelemetry-distro` with a supported Python version.","message":"Support for Python 3.6 was dropped in the related OpenTelemetry-based SDK (v1.0.0b6). While this specific legacy package (0.11.10) might still work with Python 3.6, its maintenance status means future compatibility with older Python versions is not guaranteed, and it's unlikely to receive updates for new Python releases.","severity":"deprecated","affected_versions":"< 0.11.10 for Python 3.6"}],"env_vars":null,"last_verified":"2026-05-23T06:58:33.434Z","next_check":"2026-07-08T00:00:00.000Z","problems":[{"fix":"Install the package using pip: 'pip install applicationinsights'.","cause":"The 'applicationinsights' package is not installed in the Python environment.","error":"ModuleNotFoundError: No module named 'applicationinsights'"},{"fix":"Use 'LogsQueryClient' from 'azure.monitor.query' instead: 'from azure.monitor.query import LogsQueryClient'.","cause":"The 'ApplicationInsightsDataClient' class is not available in the 'azure.monitor.query' module.","error":"ImportError: cannot import name 'ApplicationInsightsDataClient' from 'azure.monitor.query'"},{"fix":"Ensure the Application Insights client is properly initialized with a valid instrumentation key before use.","cause":"Attempting to call a function or method that is None, possibly due to incorrect initialization of the Application Insights client.","error":"TypeError: 'NoneType' object is not callable"},{"fix":"Verify that the instrumentation key is correct and properly formatted as a GUID.","cause":"The provided instrumentation key is invalid or incorrectly formatted.","error":"ValueError: Invalid instrumentation key"},{"fix":"Update the 'applicationinsights' package to the latest version using pip: 'pip install --upgrade applicationinsights'.","cause":"The 'TelemetryClient' object does not have a 'track_event' method, possibly due to using an outdated version of the 'applicationinsights' package.","error":"AttributeError: 'TelemetryClient' object has no attribute 'track_event'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"0.11.10","cli_name":"","cli_version":null,"type":"library","homepage":"https://learn.microsoft.com/en-us/azure/azure-monitor/app/app-insights-overview","github":"https://github.com/Microsoft/ApplicationInsights-Python","docs":null,"changelog":null,"pypi":"https://pypi.org/project/applicationinsights/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["azure","observability"],"base_url":null,"auth_type":null,"install_checks":{"last_tested":"2026-05-23","tag":null,"tag_description":null,"installed_version":"0.11.10","pypi_latest":"0.11.10","is_stale":false,"results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"applicationinsights","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.14,"mem_mb":4.7,"disk_size":"18.4M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"applicationinsights","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":1.5,"import_time_s":0.1,"mem_mb":4.7,"disk_size":"19M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"applicationinsights","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.19,"mem_mb":5.2,"disk_size":"20.3M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"applicationinsights","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":1.6,"import_time_s":0.17,"mem_mb":5.2,"disk_size":"21M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"applicationinsights","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.15,"mem_mb":5,"disk_size":"12.2M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"applicationinsights","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":1.4,"import_time_s":0.15,"mem_mb":5,"disk_size":"13M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"applicationinsights","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.14,"mem_mb":5.2,"disk_size":"11.9M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"applicationinsights","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":1.4,"import_time_s":0.14,"mem_mb":5.2,"disk_size":"12M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"applicationinsights","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.13,"mem_mb":4.6,"disk_size":"17.9M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"applicationinsights","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":1.8,"import_time_s":0.12,"mem_mb":4.6,"disk_size":"18M"}]},"_links":{"self":"https://checklist.day/api/registry/applicationinsights","v1":"https://checklist.day/v1/registry/applicationinsights","v1_install":"https://checklist.day/v1/registry/applicationinsights/install","v1_imports":"https://checklist.day/v1/registry/applicationinsights/imports","v1_compatibility":"https://checklist.day/v1/registry/applicationinsights/compatibility","v1_quickstart":"https://checklist.day/v1/registry/applicationinsights/quickstart","docs":"https://checklist.day/docs"}}