Capturing Exception Call Stacks in Python Applications with Sidekick
What is the Sidekick?
Sidekick is an open-source live application debugger that lets you troubleshoot your applications while they keep on running. It is like Chrome DevTools for your and built for everyone who needs extra information from their applications.
Why do we use the Sidekick while exception call stacks capture?
When your product runs in development or production environments, it can probably encounter and throw some errors. In such a cases, it can be difficult to debug these errors. Despite that, Sidekick allows you to easily capture and debug them.
Sidekick currently collects error call stacks in both Python and Node.js applications. In this article I’ll be explaining Sidekicks Error Stack Collection for Python applications.
Let’s try it in action!
Install Python and Pip
Firstly, we need to make sure that the following tools are installed and versions are correct in the system we will use:
We have prepared a Flask project that we will use for the tutorial. First, lets clone it from GitHub.
Install the Requirements
Set Environment Variables for the Sidekick
Next, make sure the following environment variables are set correctly for the project and the Sidekick tool to work correctly. You can either EXPORT those variables or create a .env file. Check docs for more info.
Everything is ready! Let’s start the application
Lets run our application with the following command.
Error Call Stack Capturing
In this section, we will talk about capturing error call stacks via the Sidekick. When we complete all the steps above, your Flask application will be up and running.
First, we have added some error-throwing code snippets inside the project. In the project, these errors are thrown in case of an invalid username and password while the user logs into the system.
As you see, we will throw an error while username and password are not satisfied the requirements. To go to login page, please enter the url on web browser:
Now you can see the login screen. Here, we will try an invalid username and then an invalid password.
As seen in the examples above, submitting an incorrect username or password should produce two different error messages. We will now capture these error messages with the Sidekick.
When we submit the inputs above, the application will throw an error for each case. Now, let’s go to the Sidekick screen and see if it catches these errors.
BINGO! We got it! The error results were informed by Sidekick, as you can see. In addition, Sidekick can show the types of errors. As seen in this example, there are two error types that are “Exception” and “ValueError”. As seen here, the values of the variables in the method appear as you click on the errors.
To summarize my post, I briefly talked about catching error call stacks in Python and how to use Sidekick to do this action easily and quickly. Apart from the Flask framework used here, it also works in Sidekick, FastAPI, Django etc. frameworks. In addition, you can easily use Sidekick’s features and advantages through your IDE via PyCharm and Visual Studio Code extensions.
With Sidekick ErroR Stack Collection, developers can now activate automatic error stack collection and start collecting exception call stacks from their running applications without stopping them. A great addition to Sidekick Actions that will help you boost your developer productivity even more.
Sidekick is open-source and brings almost no overhead to your applications. Visit runsidekick.com to meet your new live application debugger.
Please let us know your invaluable ideas because they will guide us on our path to discovering the future of application observability. You can get in touch with us through Twitter, and join our Discord community.