How to Log your Errors in Python using Sentry?

In today’s world where everybody is getting indulged in the world of coding Python as a programming language is gaining popularity due to its easy user-friendly syntaxes. Programmers all around the world are emphasizing more towards learning this language and create wonders in the respective domain. But, with easy-to-code provision comes a challenge too!!

Programmers and AI engineers face a lot of problems when it comes to writing many lines of code and handling different types of errors occurring at each stage. Error handling plays a very pivotal role whenever it comes to coding and if programmers are not proficient enough to handle errors, then it creates a lot of difficulties to properly frame the logic.

To handle such errors many tools have been developed both paid and open source. These tools not only help to log the errors in their environment but also provide the freedom to get notified about the same when resolved. Today we will be discussing such a tool called Sentry – Application Monitoring and Error Tracking Software. This is an open-source platform that is very efficient in logging different types of errors with just a few lines of code. The platform supports different programming languages like Python, Java, Php, etc. The installation and working steps to log your respective errors are given below:

Set up Sentry with Python to monitor your project

Note: All the installation and working steps will be as per Python programming language.

• Login to Sentry

Step 1: On your laptop just go to any browser of your choice and type This will take you to the official website of the sentry. Just create an account on the website and you are good to go. There are different ways of signing in to the website for eg: through Gmail, Company mail, Facebook, etc.

Log in to sentry min


• Select Programming Platform

Step 2: Once your account is created you just need to click on I’m Ready and you are good to go to the next step. On the next page, you will see different options to choose from related to the programming language you work on. Select Python from these options and then click on Create Project button below.

Create Project

Select JDK to install


• Install the sentry API through pip

Step 3: Once you have clicked on the Create Project button you will land on a page that will have the instructions to install the sentry API through pip and it will also contain the sentry SDK. Just follow the same steps and voila!

Install Python SDK of Sentry

• Sentry dashboard

Step 4: Once all these things are done the last step is to go to the dashboard of sentry and just explore the different options present in the same. The first project that you have created will open by default. In the dashboard, you will see different options present on the left-hand side like Projects, Issues, Performance, Releases, Dashboard, Discover, etc.

These mainly contain different functionalities of this amazing API and you can take a look at the same and use it as per your use case. There are different integration options present for this API as well that can be found in the settings option like with Microsoft Teams, Github, Slack, and many more. Some of these are paid and some are free. Although for developer purposes sentry is free of cost with limited functionalities and one can upgrade his plan based on the usage. The different pricing for this API is given below:

The different pricing for API

Step 5: Once all the exploration part is done now it is time to look at its working with Python.


• How to use Sentry to Log in Errors

Step 1: Open any Python editor/IDE of your choice and load the library and initialize the sentry SDK.

Open Python editor or IDE and import Sentry SDK

Step 2: After the initialization just types in your desired code and save the Python file in your working directory.

Step 3: Add some random errors to check if the library is working properly or not. Now, open your terminal from the working directory and just type the python name of your file and run the server and wait for the magic to happen.

Checking errors on Python


Step 4: Once the file has run just go to your sentry dashboard and on the issues tab, you will find the error that was created and the respective file name and line where the error occurred.

your sentry dashboard min Python Errors and logn information using sentry

• Additional Information

There are many additional features provided by this library as mentioned earlier as well as integrations with various open-source platforms, sending notifications for the errors, creating a dashboard to visualize the errors in a more graphical and analytical form, and many more. The open-source version is limited to the creation of 7 projects and logging errors in the same and one can upgrade it as per the needs.

• Conclusion

A library providing the feature of error handling is worth to be checked at least once. For a developer, this can be a very handy tool to work on, and therefore would recommend you all to try it out.