Install & Compatibility
Where this runs
tested against v0.11.10 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.156s · 18.4MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 1.6s · import 0.140s · 19MB
16MB installed
● package 16MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
TelemetryClient
✓ from applicationinsights import TelemetryClient
logging
✓ import logging
from applicationinsights.logging import enable
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.
import os
from applicationinsights import TelemetryClient
# For legacy SDK, use Instrumentation Key
# Find your Instrumentation Key in your Application Insights resource in Azure Portal.
INSTRUMENTATION_KEY = os.environ.get('APPINSIGHTS_INSTRUMENTATIONKEY', 'YOUR_LEGACY_INSTRUMENTATION_KEY')
if not INSTRUMENTATION_KEY or INSTRUMENTATION_KEY == 'YOUR_LEGACY_INSTRUMENTATION_KEY':
print("Warning: APPINSIGHTS_INSTRUMENTATIONKEY not set. Telemetry will not be sent.")
exit()
client = TelemetryClient(INSTRUMENTATION_KEY)
# Track an event
client.track_event('MyLegacyPythonEvent', {'custom_property': 'value1'})
# Track a metric
client.track_metric('MyLegacyMetric', 123.45)
# Track a trace message
client.track_trace('This is a legacy trace message', properties={'level': 'INFO'})
# Ensure telemetry is sent before application exits
client.flush()
print("Legacy telemetry sent.")
Debug
Known issues
breakingThis `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.fixFor 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.
affects: All versions of `applicationinsights` (legacy SDK) vs. `azure-monitor-opentelemetry-distro` (modern SDK)
gotchaThe 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.fixEnsure 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.
affects: All versions
gotchaTelemetry 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.fixAlways 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.
affects: All versions
deprecatedSupport 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.fixIt is recommended to use Python 3.7 or newer. For new applications, use the `azure-monitor-opentelemetry-distro` with a supported Python version.
affects: < 0.11.10 for Python 3.6
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'applicationinsights'
The 'applicationinsights' package is not installed in the Python environment.
fixInstall the package using pip: 'pip install applicationinsights'.
ImportError: cannot import name 'ApplicationInsightsDataClient' from 'azure.monitor.query'
The 'ApplicationInsightsDataClient' class is not available in the 'azure.monitor.query' module.
fixUse 'LogsQueryClient' from 'azure.monitor.query' instead: 'from azure.monitor.query import LogsQueryClient'.
TypeError: 'NoneType' object is not callable
Attempting to call a function or method that is None, possibly due to incorrect initialization of the Application Insights client.
fixEnsure the Application Insights client is properly initialized with a valid instrumentation key before use.
ValueError: Invalid instrumentation key
The provided instrumentation key is invalid or incorrectly formatted.
fixVerify that the instrumentation key is correct and properly formatted as a GUID.
AttributeError: 'TelemetryClient' object has no attribute 'track_event'
The 'TelemetryClient' object does not have a 'track_event' method, possibly due to using an outdated version of the 'applicationinsights' package.
fixUpdate the 'applicationinsights' package to the latest version using pip: 'pip install --upgrade applicationinsights'.
Upgrade
Version history
0.11.10latest on PyPI · released Apr 22, 2021
Audit
Dependencies
requestsrequiredUsed for HTTP communication with Application Insights ingestion endpoints.
python-json-loggerrequiredUsed for structured logging integration.