Use Application Insights with Python 3 (including bottles)

TL;DR Application Insights, which can be called New Relic for Azure, doesn't have much information, so I'll write it.

GitHub Microsoft/ApplicationInsights-Python: Application Insights SDK for Python https://github.com/Microsoft/ApplicationInsights-Python

You can find out how to use it by reading GitHub. .. .. .. It's lonely just to say that, so it's easy to use below.

Installation method

You only need to install pip. $ pip install applicationinsights

How to use

In GitHub's README, client telemetry and server-side processing are combined, which is difficult to understand, but it is possible to monitor in two categories: monitoring when sending a request from a client and monitoring on the server side receiving a request. is.

INSTRUMENTATION KEY No matter how you use it, you will need the INSTRUMENTATION KEY. The INSTRUMENTATION KEY is located in a property inside the Azure Application Insights blade. キャプチャ.PNG

As the server side

Request for the time being

Basically, any WSGI application can be easily incorporated. Of course, it was possible in the environment of Python's lightweight framework bottle + uWSG.

from applicationinsights.requests import WSGIApplication
from bottle import route, run, default_app, get, post, request, static_file
~ Abbreviation ~
if __name__ == '__main__':
    #From the command"python index.py"When started with
    run(host='0.0.0.0', port=8080, debug=True)
else:
    #When started from uWSGI
    application = WSGIApplication('<INSTRUMENTATION KEY>', default_app())

It will be displayed like this. キャプチャ.PNG

Logging

I will try it from now on

exception

I will try it from now on

As a client side

I will try it from now on

Recommended Posts

Use Application Insights with Python 3 (including bottles)
Use mecab with Python3
Use DynamoDB with Python
Use Python 3.8 with Anaconda
Use python with docker
Use Trello API with python
Use Twitter API with Python
Use TUN / TAP with Python
[Mac OS] Use Kivy with PyCharm! [Python application development]
Web application with Python + Flask ② ③
Use subsonic API with python3
Web application with Python + Flask ④
Python: How to use async with
Use PointGrey camera with Python (PyCapture2)
Use vl53l0x with Raspberry Pi (python)
Use NAIF SPICE TOOLKIT with Python
Monitor Python application performance with Dynatrace ♪
Use rospy with virtualenv in Python3
How to use FTP with Python
Use Windows 10 speech synthesis with Python
Use OpenCV with Python 3 in Window
Use PostgreSQL with Lambda (Python + psycopg2)
Application development with Docker + Python + Flask
Python application: Data cleansing # 2: Data cleansing with DataFrame
Use smbus with python3 under pyenv environment
Use Amazon Simple Notification Service with Python
[Python] Use string data with scikit-learn SVM
[Introduction to Python] Let's use foreach with Python
Use PIL and Pillow with Cygwin Python
Use cryptography library cryptography with Docker Python image
[Python] A quick web application with Bottle!
Run a Python web application with Docker
Use C ++ functions from python with pybind11
Use selenium phantomjs webdriver with python unittest
Until you can use opencv with python
Use Python and MeCab with Azure Functions
[Introduction to Udemy Python3 + Application] 23. How to use tuples
Statistics with python
Use additional Python packages with Serverless Framework (v1.x)
I made a GUI application with Python + PyQt5
Python with Go
Specify the Python executable to use with virtualenv
Use logger with Python for the time being
Twilio with Python
Integrate with Python
Python> Run with run-time arguments> Use import argparse
Use multiple versions of python environment with pyenv
Wrap C with Cython for use from Python
Play with 2016-Python
AES256 with python
Tested with Python
python starts with ()
Serverless application with AWS SAM! (APIGATEWAY + Lambda (Python))
The easiest way to use OpenCV with python
Use various rabbimq features with pika in python
I want to use Temporary Directory with Python2
with syntax (Python)
How to use tkinter with python in pyenv
Bingo with python
Zundokokiyoshi with python
Use Python in Anaconda environment with VS Code