Skip to main content

This project extends the Application Insights API surface to support Python.

Project description

This project extends the Application Insights API surface to support Python. Application Insights is a service that allows developers to keep their application available, performing and succeeding. This Python module will allow you to send telemetry of various kinds (event, trace, exception, etc.) to the Application Insights service where they can be visualized in the Azure Portal.

Requirements

Python 2.7 and Python 3.4 are currently supported by this module.

For opening the project in Microsoft Visual Studio you will need Python Tools for Visual Studio.

Installation

To install the latest release you can use pip.

$ pip install applicationinsights

Usage

Once installed, you can send telemetry to Application Insights. Here are a few samples.

Note: before you can send data to you will need an instrumentation key. Please see the Getting an Application Insights Instrumentation Key section for more information.

Sending a simple event telemetry item

from applicationinsights import TelemetryClient
tc = TelemetryClient()
tc.context.instrumentation_key = '<YOUR INSTRUMENTATION KEY GOES HERE>'
tc.track_event("Test event")

Sending an event telemetry item with custom properties and measurements

from applicationinsights import TelemetryClient
tc = TelemetryClient()
tc.context.instrumentation_key = '<YOUR INSTRUMENTATION KEY GOES HERE>'
tc.track_event('Test event', { 'foo': 'bar' }, { 'baz': 42 })

Sending a trace telemetry item with custom properties

from applicationinsights import TelemetryClient
tc = TelemetryClient()
tc.context.instrumentation_key = '<YOUR INSTRUMENTATION KEY GOES HERE>'
tc.track_trace('Test trace', { 'foo': 'bar' })

Sending a metric telemetry item

from applicationinsights import TelemetryClient
tc = TelemetryClient()
tc.context.instrumentation_key = '<YOUR INSTRUMENTATION KEY GOES HERE>'
tc.track_metric('My Metric', 42)

Sending an exception telemetry item with custom properties and measurements

import sys
from applicationinsights import TelemetryClient
tc = TelemetryClient()
tc.context.instrumentation_key = '<YOUR INSTRUMENTATION KEY GOES HERE>'
try:
    raise Exception('blah')
except:
    tc.track_exception()

try:
    raise Exception("blah")
except:
    tc.track_exception(*sys.exc_info(), properties={ 'foo': 'bar' }, measurements={ 'x': 42 })

Configuring context for a telemetry client instance

from applicationinsights import TelemetryClient
tc = TelemetryClient()
tc.context.instrumentation_key = '<YOUR INSTRUMENTATION KEY GOES HERE>'
tc.context.application.id = 'My application'
tc.context.application.ver = '1.2.3'
tc.context.device.id = 'My current device'
tc.context.device.oemName = 'Asus'
tc.context.device.model = 'X31A'
tc.context.device.type = "Other"
tc.context.user.id = 'santa@northpole.net'
tc.track_trace('My trace with context')

Configuring channel related properties

from applicationinsights import TelemetryClient
tc = TelemetryClient()
# flush telemetry every 30 seconds (assuming we don't hit max_queue_item_count first)
tc.channel.sender.send_interval_in_milliseconds = 30 * 1000
# flush telemetry if we have 10 or more telemetry items in our queue
tc.channel.sender.max_queue_item_count = 10

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

applicationinsights-0.2.0.zip (62.1 kB view details)

Uploaded Source

File details

Details for the file applicationinsights-0.2.0.zip.

File metadata

File hashes

Hashes for applicationinsights-0.2.0.zip
Algorithm Hash digest
SHA256 71669bfd7e28239ab4e6bb80691ac454b3e3d442a5b4622c629761cc9b4f0c89
MD5 11939005420786b5c903caa7875c144b
BLAKE2b-256 6ed4d5b3460c7d42fa2c76c339d8dee249df23b086c131111cae001c7afe5fb3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page