Andrew Tamura

San Francisco, CA USA

Best Practices for using Sentry with Node.js

I’ve used Sentry since 2010, way back when it still had Starcraft inspired logos and when you had to host it yourself. Now Raven has clients for all the popular languages including Node.js and hosted Sentry is the de facto way to get started. I’ve spent the last 15 months working on a Node.js codebase at Mixmax. Here are some of the best practices I’ve picked up for identifying code bugs with Sentry and Raven.

Use the same Raven configuration wrapper for each project

Raven automatically configures itself from environment variables, but a wrapper module will come in handy to implement the rest of the tips in this post.

Monkey patch Raven to log to console for local development

It’s cumbersome for all the engineers on your team to use the Sentry web interface when developing locally. Even worse would be to have an isLocal condition everytime you log an exception with Raven. Instead of poluting your Sentry with useless artifacts from local development just leave the SENTRY_DSN environment variable unset for local development.

Raven’s dataCallback will fire even if Raven isn’t configured with a Sentry DSN. Unfortunately Raven doesn’t pass back the original Error object to the dataCallback. Monkey patching the captureException function is one way to print the original exception. Note: this monkey patch won’t be necessary once raven-node integrates with console.error

Use the culprit property to identify the same Errors from different code paths

It is very common to use a module in multiple code paths. Unfortunately, the default Sentry view doesn’t expose the different code paths. In order to see which codepaths are affected, you need to go into the Sentry event and view the stack trace. Consider the given code

Functions foo and bar both call the thowsException function. However in Sentry it isn’t obvious which code paths have thrown this exception.

image

Set the culprit property to a unique string when logging exceptions from shared modules. This will help identify which line of code the error was caused by.

image

Add server context as Sentry Tags 

Your web application is probably deployed across many servers. Sometimes the problem isn’t your code, but rather some property of your server. Some third party API’s will rate limit or blacklist clients based on IP addresses. Adding the public IP address (if applicable) and the server ID may help identify exceptions that are caused by some property of your server.

How do you use Raven in your node.js codebases? Comment on Hacker News.

A Practical Guide to Passwords

Passwords are one of the most frustrating aspects of the internet. Despite the ubiquity of “Login with Facebook”, “Login with Google, or any of the other "Login with _blank_” services, passwords are still a pain to deal with. For every password that I don’t have to set using a “Login with _blank_”, there are at least five passwords that require manual login (typing in your password as opposed to using your Facebook or Google credentials). Being able to work effectively with dozens of services that require manual logins is essential to surviving the internet. I notice a lot of my friends and family (I’m talking about you Mom) struggle with managing passwords. Here are my tips for effectively dealing with passwords:

Write Down Your Password

Remembering your password is the worst part of having a password. At the end of the day, even with web browsers that save cookies, Facebook login, and an excellent memory, you still have to remember your password to type it in. The solution is simple, write them down. Don’t rely solely on your brain to memorize your password. Write it somewhere so that you can easily access it when you need to. But wait, isn’t it a HUGE security risk to write down your password? Yes, it is a huge security risk, but it is also very practical. Write them down somewhere safe with limited access, e.g. a post-it that you keep in your wallet, in your diary, or in a password manager. 

Password managers are excellent tools to help you securely write down your passwords. I’ve been using AgileBits’ 1Password for a few years now and think it’s great. 1Password integrates with your desktop web browser so it can autofill your password when you login. There are many other password managers, just pick one and use it. 

Use a Secure Password

Passwords should be secure! Yes, you can get away with using an insecure password (e.g. password) and nothing bad will happen to you (probably). But you really shouldn’t. But now you are going to complain that secure passwords are too hard to memorize (e.g. P@ssw0rd!) Nowadays, this is not necessarily the case! Passwords are often unfairly judged as having an inverse proportional relationship between security and ease of memorization. That is, when a password is secure, it is hard to memorize and when it is easy to memorize it is not secure. With modern internet services, you are able to choose a password that is secure and easy to memorize. This XKCD comic illustrates the type of password that I’m talking about. 

My preference for strong password generation follows this criteria:

Following this criteria, you might end up with a password that resembles this:

Sphinx#Wood#Happy#4

This password is far more secure than P@ssw0rd1 and is a lot easier to remember! There are various websites that can help you generate a strong password of this style. A few points of consideration however some websites have a limit on the length of the password. I’ve seen upper limits of 8-20 chars. My passwords are usually greater than 20 chars long, so I generate two passwords, one that is full length (more secure) and a second that is short (less secure). Yes, it’s a pain in the ass. But memorizing two passwords isn’t that hard in the grand scheme of life. 

Can you use the same password for all your logins? Yes you can, but it’s definitely not recommended. If one service leaks your password, then ALL your other accounts may be at risk. Now, this is a “practical” guide and managing a different password for each login is certainly not practical. So reuse your passwords at your own risk. 

Notes

Some services require you to rotate your passwords periodically. I think this is such a good idea that I rotate ALL my passwords periodically. Even the most secure passwords do not last forever. I consider password rotation to be part of my regularly scheduled internet maintenance. Rotating all my passwords would be impossible without the assistance of a password manager. 

So there you have it. Two easy steps to becoming a more informed and assertive internet citizen: write down your passwords and choose secure and easily memorizable passwords. 

How to Plan a Tomales Bay Bioluminescence Viewing Camping Trip

Viewing the bioluminescence at Tomales Bay is a fun weekend trip. It’s a nice mixture of kayaking, camping, and experiencing a natural phenomenon. This guide covers some of the key steps for planning a trip to Tomales Bay. 

Step 1: Reserve a campsite via recreation.gov

Bioluminescence viewing can only be done during the correct season on a dark night. Try to schedule the trip for a new moon so that there is minimal light at night. During peak season (summer) you may have to schedule many weeks in advance.

There are plenty of campsites at Tomales Bay. The ones that we’re interested in are the “boat-in” campsites. These campsites are only accessible via boat (or kayak). On the recreation.gov website, view the campsites at “Point Reyes National Seashore Campground”. Look for the “BOAT-IN A” or “BOAT-IN B” sites. These two permits are the ones that you need to book. The only difference is the number of people in your party. “A” permits are up to 6 people and “B” are up to 14 people. The “A2” and “B2” permits are last minute reservations not available online. Follow the directions on the website to make your reservation. Once you have your reservation booked you can then make kayak reservations.

Note: the BOAT-IN permits are not for a specific campsite, but rather it is for a first-come first-serve availability for a group of campsites. Marshall Beach and Tomales Beach are the two campsites that have toilets. There are a handful of other beach campsites that are available to you with this permit. 

Step 2: Make kayak reservations

I’ve used Blue Waters Kayaking twice now and I’m always blown away by how helpful and accommodating they are. Call them reserve your kayaks in advance. During peak season kayaks are hard to come by. Plan early! 

Step 3: Plan your camping trip

I’m always surprised at how wet and sandy I get when I go to Tomales Bay. The next time I go I’m going to wear only sandals (damp/wet sand + shoes is the worse). You will get very wet in the open kayaks, so wear swim apparel when you are in the kayaks. Blue Water Kayak will let you borrow wetsuits. Aside from the wet and sandy elements, basic camping planning applies to this trip. 

Step 4: Pick up your campsite permit (day of)

Before getting into the kayaks you need to stop by the Bear Valley Visitor Center (just outside of Point Reyes Station) to actually pick up your campsite permit and campfire permit. Don’t forget to pick up your permit!

Step 5: Getting to the campsite

You can pack your gear into/onto the kayaks to get it to the campsite. Alternatively, you can pay Blue Water Kayak to motorboat your gear in. I’ve done it both ways and I prefer to pack it on the kayaks; it’s cheaper and more flexible as far as timing. 

Tomales Beach campsite is about 60 minutes away via kayak from Blue Waters Marshall location. If you launch from Inverness it’ll be more than 150 minutes. The campsites are first come first serve, so get there as early as you can so that you get your choice of campsite. 

Step 6: Enjoy!

Drinking Part 1: Why I Stopped Drinking

With the exception of one pint of my friend’s homebrew in December, I haven’t had a drink since late November 2012. I’ve politely turned down beer and liquor at dinners, happy hours, bars, brunches, lunches, late nights, karaoke, weekends at the river, birthdays, New Years Eve, and countless other events. I’m surprised at how easily I’ve given it up considering how much I used to drink. I would characterize my prior self as a “serious social drinker.” I looked forward to enjoying a drink whenever and wherever the opportunity presented itself. I genuinely enjoyed the taste of beers, whiskies and wines. My life was full of alcohol-centric activities like wine tasting, happy hours after work, artisan cocktails, microbrews, and drinking at bars.

So why did I stop drinking?

1. Drinking distracted me from interacting with people. I don’t mean to say that I was an alcoholic shut-in who didn’t socialize with people. I did socialize with people, but sometimes I didn’t put enough energy into the people I was around. Sometimes I’d “balance” out an uncomfortable situation with alcohol. It took a while for me to realize what a terrible thing I was doing. Drinking doesn’t automatically make something better. All those times when I’d just sip on my drink I should have been interacting with people. I’d much rather focus my energy on the people I’m around instead of into a glass. Living in India for a year probably had something to do with that. After being away for so long I really have a much greater appreciation for face-to-face time with people. I see my drinking habits as an obstacle when trying to spend time people.

2. Being drunk wasn’t all that great. Sure, it feels great to get drunk, everything becomes more fun, inhibitions are lowered, and you never know what’ll happen next. But usually the same stuff happens; nothing of particular significance. However, I do enjoy potential chaos factor of getting drunk. When I’m drunk, I believe that anything could happen and that’s exciting. Unfortunately, getting drunk comes with downsides and for me that downside is getting really sleepy. This defeats the chaos element because all I want to do is fall asleep instead of being spontaneous and daring.

I realize that I didn’t have to completely give up alcohol completely to address the aforementioned problems. Ultimately I decided that it was easier to give give up alcohol completely than to devise a situation-based plan to decide when to drink, how much to drink, where to drink etc. The past few months haven’t always been fun, but it’s been an interesting experience. I don’t know when I’ll resume drinking, but I’m certainly looking forward to it. Meanwhile, I’m planning to write two follow up posts, one about what I’ve learned since I’ve stopped drinking and another one about what I’m going to do differently when I do resume drinking.

Stay tuned for parts 2 and 3:
Drinking Part 2: Same Same, but Different.
Drinking Part 3: Drink Different.

My First Backgammon Tournament

Last weekend I competed in my first backgammon tournament. I was up late practicing against GNUGB and on a whim I did a google search for local backgammon tournaments. As it would have turned out, the local backgammon club (Backgammon by the Bay) was having a tournament the next morning. I had only been practicing for 2.5 months, but I felt up for the challenge. I entered in the beginners bracket for $20. The turnout was a little low, so the organizer combined the beginner and intermediate bracket. I don’t want to keep you hanging, so I’ll briefly skip to the end, I finished in 4th place. Technically I tied for 3rd, but I don’t want to over inflate my performance. And to answer your second question, there were a total of four people in my bracket.

The tournament was held at a Peking Express in Berkeley. Most of the competitors were eating some steam-table Chinese food for brunch by the time I arrived. This was my first backgammon tournament and I had absolutely no idea what to expect. After registering and paying my fee, I patiently sat at one of the tables, waiting for the tournament to begin. The serious players brought their own backgammon boards which dwarfed my board not only in size, but quality as well. I play on a little travel size board that doesn’t even open completely flat. Their boards were full sized and required a shoulder strap to carry around. I tried my hardest not to let the superficial things phase me. After all, a nice backgammon board gives no more advantage than a new pair of Nike’s or fancy tennis racket.

From start to end, I was at the tournament for over 6 hours. I took a few breaks to use the toilet and to move my car, but the rest of the time was all backgammon. In hindsight I should have stopped for lunch, as my hunger ended up getting the better of me towards the end. Even though I didn’t win, I really enjoyed my first backgammon tournament. My inexperience was my downfall. I played half decent, but I made some fatal mistakes.

Playing against a strong AI will improve your backgammon game, but you need to practice against a real person too. There are so many factors outside of the backgammon board that can make or break your game. I play with one of my friends, but he’s not that good. The other times that I play with people it’s not so much practice as it is me teaching them how to play. In short, I was completely unprepared to sit down in front of another person and play competitively. I tried to block everything out and treat each game like I were playing against the computer, but clearly it didn’t work too well.

I’m used to playing against a consistent computer AI who always plays at the same level during a match. It never makes mistakes and never makes a particularly brilliant or outstandingly dumb move; it just plays consistently good. But human players aren’t that consistent. I made the mistake of judging a player too early and incorrectly assuming they were not as strong based on their first game or first mistake. In reality I was probably the weakest player as I had the least experience. But for some reason I immediately jumped to the conclusion that I was better than my opponent the second that they made a mistake.

Regardless of the final outcome, I was really happy that I went out and played. I can be a bit overly competitive at times and it’s always a humbling experience to come in last place. I need to focus on the metagame as well as the actual strategy if I want to start winning at these tournaments. Now that I’ve got one tournament under my belt the next ones should be easier.