Azure Application Insights Client (Legacy)

0.1.1 · abandoned · verified Sat Apr 11

This is the legacy Python client library for sending telemetry to Microsoft Azure Application Insights. It was last updated in October 2018 (version 0.1.1) and has since been superseded by `opencensus-ext-azure` and more recently by `azure-monitor-opentelemetry-exporter` for modern Azure Monitor integration. This package is no longer actively maintained.

Warnings

Install

Imports

Quickstart

Demonstrates how to initialize the legacy `TelemetryClient` and send basic event, metric, and trace telemetry. Note that this library is deprecated.

import os
from applicationinsights import TelemetryClient

# Get your Application Insights Instrumentation Key from environment variable
# For Azure Portal: Application Insights -> Overview -> Essentials -> Instrumentation Key
instrumentation_key = os.environ.get('APPINSIGHTS_INSTRUMENTATION_KEY', 'YOUR_INSTRUMENTATION_KEY')

if not instrumentation_key or instrumentation_key == 'YOUR_INSTRUMENTATION_KEY':
    print("WARNING: APPINSIGHTS_INSTRUMENTATION_KEY environment variable not set or placeholder used.")
    print("Please set it to run this example.")
else:
    client = TelemetryClient(instrumentation_key)

    # Track a simple event
    client.track_event('TestEvent', properties={'key': 'value'})

    # Track a metric
    client.track_metric('TestMetric', 42.0)

    # Track a trace message
    client.track_trace('This is a test trace message.', properties={'level': 'INFO'})

    # Flush the telemetry buffer (important for short-lived scripts)
    client.flush()
    print("Telemetry sent using legacy client.")

view raw JSON →