Building Your Startup: Error Logging

Final product image
What You'll Be Creating

This tutorial is part of the Building Your Startup With PHP series on Envato Tuts+. In this series, I'm guiding you through launching a startup from concept to reality using my Meeting Planner app as a real-life example. Every step along the way, I'll release the Meeting Planner code as open-source examples you can learn from. I'll also address startup-related business issues as they arise.

Introduction to Error Logging 

Once Meeting Planner went into alpha release and people began actively using it to schedule meetings, errors would occur that were rarely reported by users. But, in conversations on the phone with people, they'd commonly tell me about problems they ran into.

In today's tutorial, I'll walk you through how I tried two different cloud-based logging services, Rollbar and Sentry, and why I ultimately settled on Sentry for the time being.

If you haven't tried out Meeting Planner yet, go ahead and schedule your first meeting. I do participate in the comment threads below, so tell me what you think! You can also reach me on Twitter @reifman. I'm especially interested if you want to suggest new features or topics for future tutorials.

As a reminder, all of the code for Meeting Planner is written in the Yii2 Framework for PHP. If you'd like to learn more about Yii2, check out our parallel series Programming With Yii2.

Let's begin.

My Experience With Rollbar

Building Startups Logging - Rollbar Home Page

Both Rollbar and Sentry were recommended to me by Alex Makarov, one of the lead volunteer developers behind the Yii Framework. Alex has been very helpful to me expanding my expertise about Yii2 while I'm building Meeting Planner and writing about the benefits of the framework.

Initially, I thought about creating a secondary database connection to log my errors and tracking them manually. But then, I noticed that these services provided a lot of advanced reporting functionality. For example, they count the number of identical errors and report them by severity. At some point, I'll write a more general-purpose Yii2 error logging tutorial for the Yii programming series, but for now, I just dove in.

And, while I got the basics working use some open-source Yii2 plugins (there are several) for Rollbar. I started having production errors that actually were caused by the plugins.

Building Startups Logging - Rolbar Integrate Your PHP Application

Overall, I was very impressed with Rollbar's web user interface and services. But I believe some problem with my configuration and the open-source Yii extension led to new problems. 

Building Startups Logging - Rollbar List of Errors

In other words, people were seeing production errors due to my attempts at recording other errors. It was worsening people's impression of Meeting Planner. Even I was running into newly mysterious production errors—and it was confusing and wasting my time.

In order to optimize their experience and my time, I disabled the error handling temporarily and decided to try using Sentry.

Just to be clear, I think with a better Rollbar Yii2 extension and more careful configuration (which is never documented well with third-party plugins like these), the service would have worked well. I don't want to discourage you from trying it.

Getting Started With Sentry

Sentry is a comparable logging service, though less expensive than Rollbar. Lower cost is often helpful to startups. 

Building Startups Logging - Sentry Home Page

You can see that their first bump in pricing begins at only $29 per month:

Building Startups Logging - Sentry Pricing Page

Signing Up

I went ahead and used the Sign Up form to get started:

Building Startups Logging - Sentry Sign Up Form

Creating a New Project

Within Sentry, I created a new project for Meeting Planner to track bugs within this domain:

Building Startups Logging - Sentry Create a New Project Form

Then, Sentry offers you guides for a number of languages and frameworks (Yii is not included yet, hint to Sentry team!):

Building Startups Logging - Sentry Configure Your Application Guide

Configuring a Yii2 Sentry Plugin

For Meeting Planner, I chose to use the Notamedia Yii2 Sentry extension. I ran into a couple of minor issues that slowed me down.

The First Problem—Not the Plugin's Fault

Firstly, I had trouble finding my unique authorization codes for my site to identify itself to Sentry. Usually, web services make these very easy to find, but it took me about 10 to 15 minutes to find.

Near the bottom of the left-hand menu of the Settings page, there's a Client Keys (DSN) option which displays them:

Building Startups Logging - Sentry Client Keys DSN

I broke the keys into their three parts and placed them in my mp.ini file for all of Meeting Planner's keys:

Within /frontend/config/main.php, I updated the plugin's recommended settings to use my specific variables from mp.ini. They begin below with $config:

The Second Problem

Then, I couldn't get Sentry to capture the error reports. It turned out that the documentation for notamedia's plugin used the URL sentry.com instead of sentry.io. Luckily, I figured that out within just a few minutes and didn't waste too much time.

Sentry Introductory Emails

Sentry does send you an introductory email, but I didn't notice it arrive until later. Still, it's very helpful:

Building Startups Logging - Welcome to Sentry Email

Testing Sentry With Meeting Planner

On one of my controllers in my local environment, I just added the code to actionIndex which would load when I load a page on the site:

Very quickly, bug reports started rolling in from the local and production environment. They land in the Sentry dashboard. 

The Sentry Dashboard

Building Startups Logging - The Sentry Dashboard

Here's an example of the reporting for one of my fake testing bugs, "We have a problem Portland." It shows all the helpful data that Sentry collects for you to make discovering, identifying and debugging production errors easier:

Building Startups Logging - Sample Error Report in Sentry We have a problem Portland

Above, you can see tags related to URLs and the user's browser. Below, the report continues showing you the lines of code that caused the error:

Building Startups Logging - 2nd Segment of Sample Error

It also shows cookies above and headers and user IDs below:

Building Startups Logging - 3rd Segment of Sample Error

It's all very helpful.

Sentry Email Alerts to New Bugs

By default, Sentry also emails you bugs (so you know about them immediately):

Building Startups Error Logging - Sentry Email Bug Report

In fact, very quickly, Sentry showed me that WordPress hacker bots were already pinging for wp-login and wp-admin on my site. Even though they don't exist here, I want to minimize their impacts. So I added a neverland action in the front-end SiteController.php to just end the application execution.

Sentry also found a permission problem that was occurring with caching in my background tasks. This too was helpful.

For now, I'm sold on Sentry, and I look forward to some quick gains from it as it's live in production during the ongoing preview release.

What's Next?

I hope you've enjoyed learning about production error handling and logging.

Watch for upcoming tutorials here in the Building Your Startup With PHP series. I've done a lot of feature development and polishing this year. Now, it's time to get people using Meeting Planner. Soon, I'll write about promotion plans for the preview release—it's another key element of launching your startup.

If you haven't yet, please try out scheduling and share Meeting Planner with your friends. As usual, I'd appreciate it if you share your experience below in the comments, and I'm always interested in your suggestions. You can always reach me on Twitter @reifman directly.

I'm also getting closer to launching the experiment with WeFunder based on the implementation of the SEC's new crowdfunding rules. You can follow our profile there if you'd like. I will also write more about this in a future tutorial.

Related Links

Tags:

Comments

Related Articles