Getting Started with CodeLighthouse.io for Python

Start sending real-time error notifications to code owners in less than 15 minutes.

CodeLighthouse
CodeLighthouse
6 min readNov 15, 2020

--

Why CodeLighthouse?

Tired of trying to track down application errors in production? Is your QA process or ticketing system tedious and time-consuming? Do you want your developers to get notified in live time when things go wrong so you can minimize customer impact? If you answered “yes” to any of these, then CodeLighthouse is for you!

We wrote another great post on how CodeLighthouse saves you time and makes your life easier here, or you can visit our web site to find why CodeLighthouse is right for you.

Getting Started

For the purposes of this demonstration, we’re going to use a sample Flask application, but you’re welcome to integrate CodeLighthouse with any of your code! As you’ll see shortly, integrating CodeLighthouse into your applications is easy and frictionless.

To go ahead and get started, you’ll need to sign up for an account at codelighthouse.io. We offer a variety of plans, but for this demo, we’ll be using our free-tier plan:

CodeLighthouse’s pricing plans

You can easily sign up by clicking the big “sign up” button in the top right-hand corner of our website, or by going to codelighthouse.io/signup. Once you put in some basic information, you’ll be redirected to our admin dashboard:

codelighthouse.io/admin

Using the CodeLighthouse SDK

To integrate CodeLighthouse with your applications, you’ll need to install and import our Software Development Kit (SDK). Our Python SDK is hosted on PyPi, and you can find detailed documentation on our documentation page.

Installing with Pip

Installing our SDK with pip couldn’t be easier:

pip install codelighthouse

Of course, if you’re using Pip for your dependency management, you’ll want to add our package to your requirements.txt file:

pip freeze > requirements.txt

Finding your API Key

To configure the SDK, you’ll need two things from your admin panel: your API key and your organization name. Both can be found here:

(Note that we’ve blurred out the API key in this screenshot, but rest assured — yours won’t be)

Go ahead and note both of these down. We recommend copying/pasting the API key straight from your admin panel to avoid typing errors, and we provided a handy link right below it to do exactly that.

Integrating the SDK into your code

For the purposes of this example, we’re using a sample Flask app, but you can use CodeLighthouse with any Python code, regardless of framework.

An example Flask application

As you can probably tell, this code is going to throw an error when we visit the second route. Let’s set up CodeLighthouse so that when an error occurs, we get notified!

Adding CodeLighthouse to our example Flask app

On line 4, we import the SDK. On lines 7–12, we configure it with the organization name we signed up with, and the API key from our admin panel. It’s important to make sure that these two items are correct, otherwise, the SDK will not be able to authenticate to our server correctly. We also added a resource name and a resource group to identify this piece of code, in case we want to use CodeLighthouse with multiple applications or resources.

(Side note: for security reasons, we don’t recommend hard-coding your API key into your application. We recommend storing the API key in an environment variable, and getting it with os.environ.get() . More on this can be found here.)

Now, when an error is thrown in a function decorated with the @lighthouse.error_catcher() decorator, you’ll receive an email notification! This begs the question,

What if I get a lot of errors at once?

We have good news for you — CodeLighthouse has built-in error storm protection! This means that you won’t get notifications for every single error — we’ll notify you on the 1st error of the day, the 10th error of the day, and so forth (on a per-resource basis). Of course, you can go into your admin panel’s error feed to view each individual error.

Time to give it a test run

Go ahead and run that code. Pull up your favorite web browser, and go to http://localhost:5000/hello and you’ll see the programmed message. Let’s say your name is John, and you want to see your customized welcome message. Go to http://localhost:5000/hello/john and — oh no! — there’s an error page caused by the error on line 27 in our example. If you configured your SDK properly, you should shortly receive an email that looks like this:

A CodeLighthouse error notification

Hooray, it works! As an added bonus, you can click the “GO TO ERROR” button, and you’ll be taken to more detailed information about that error in your admin panel.

Updating your notification preferences

Maybe you don’t check your emails, or maybe you want to get your notifications immediately via SMS. Whatever the case, you can change your notification preferences in your admin panel! We currently support email and SMS notifications, and we’re *this* close to finishing building our integrations for Slack and GitHub.

To change your notification preferences, you can go to your notification settings in your admin panel:

Notification settings in the CodeLighthouse admin panel

Collaborate with CodeLighthouse

One of CodeLighthouse’s most powerful features is its collaborative nature. Most of today’s applications are written not by individual contributors, but by teams. We understand that different developers are responsible for different functions in your codebase, so we designed CodeLighthouse around collaboration.

Inviting contributors is easy: navigate to the user management tab in your admin panel, enter a list of comma-separated email addresses, and select “send invites”.

Inviting users to your CodeLighthouse organization

Once your new members receive the invitation, they’ll be able to fill in their information, sign into the portal, and configure their own notification preferences. Each collaborator is free to receive notifications however they want.

(Note that certain pages on the admin panel such as billing are reserved for organization administrators only, and are not visible to collaborators)

Then, you can use their email address in the error_catcher decorator on functions. This way, notifications get sent to whoever is responsible for each particular function. Going back to our example application, it might look something like this:

Configuring function owners for different functions with the CodeLighthouse error catcher

Notice on lines 19 and 25, we’re specifying email addresses for two separate users — if an error is thrown in the first function, a notification will be sent to the user identified by developer1@yourorganization.com , but if it’s thrown in the second function, the notification will be sent to the user identified by developer2@yourorganization.com .

The beauty of this is that you can identify function owners for different parts of your codebase, and instead of your team getting overwhelmed by notifications, each developer only gets error notifications for code that they’re responsible for.

Error feed and visualizations

Another feature that CodeLighthouse provides is the ability to view a feed of all your errors, and a graph for your errors over time. These two features can be found on their own respective tabs in the admin panel. We’re working on building an even more robust set of features and tools here, so make sure to keep an eye out for those in the near future!

Your organization’s error feed

Interested, but still want to know more?

Do you have any questions? Are you looking for tech support, support for another language, or a plan tailored specifically to your organization’s needs? Reach out to us at hello@codelighthouse.io or visit our contact page — we’d love to hear from you!

Edit: the Python SDK has since been updated with additional features! Check out our documentation or this post for more information!

--

--

CodeLighthouse
CodeLighthouse

CodeLighthouse.io is a SaaS startup that notifies your code owners of application errors in live time through your communications channel of choice.