Ready player 1: lets learn how to use New Relic and play a video game!
The opening scroll: Observability for the uninitiated
In this blog, you’ll learn a few of the most common elements that observability solutions provide, you’ll also find out how to build a custom solution when the out-of-the-box configuration doesn’t suit your needs. More importantly, you’re going to have a little fun while you do it. That’s because we are using an actual game as our sample application. You see, plenty of examples start with “here’s this fake take-out food web application” and — while they certainly show a valid real-world example of something you might want to monitor — they are usually a real yawner.
What if — hear us out — you could learn observability concepts and techniques AND PLAY A VIDEO GAME at the same time?!?
I KNOW, RIGHT?!?
That’s what this example is all about. We’re going to install a game, configure New Relic to monitor it, and then — entirely for research purposes, you understand — play the game to see the stats posted on a dashboard.
For those who deal with monitoring and observability every day, the need for tools like New Relic is not only a no-brainer, it’s self-evident. It requires no further explanation.
But that’s not everyone. From the leaders in upper management all the way down to troops in the trenches, there are plenty of folks who don’t have a clear sense of what monitoring does, what observability is, and — perhaps most importantly of all — what it would even look like.
Character backstory
Dangerous Dave was a classic 1980’s side-scroller style game that many folks spent hours playing when they should have been doing productive work. It was created by John Romero, the same game designer who brought to life Wolfenstein 3D, Doom, and Quake.
Along with the obvious attraction of being able to play a level or two in between examples, there’s another reason for using a game as our example: Games are not — as a class of application — particularly easy to instrument in monitoring. They aren’t generally written to share resources, emit statistics, or even run while other things are running on the same machine. By using Dangerous Dave (which we’ve dubbed “Data Driven Dave” for our purposes) we’re making the subtle point that if you can add observability here, you can add it to pretty much any business application — standard, custom-off-the-shelf, or home grown — that you can come up with.
But most of all, we’re using the Dangerous Dave game so you can have a fun way to kick the tires on New Relic monitoring and to show how easy it is to instrument non-web scripts, background worker processes, and functions, to capture and collect non-standard metrics, and to display them in a meaningful way.
Teaser trailer: Seeing is believing
We realize the best way to entice you to try out the techniques you’ll see later in this blog is to show you the results now. So here it is. New Relic can take a game that looks like this:
And display the results like this:
Now remember, the point isn’t for you to ooh and aaah over how amazing this specific dashboard looks. We want you to recognize that we’re collecting and displaying a range of telemetry and data types — from simple metrics like the top score to a breakdown of individual items collected during the game with the value each contributes to the overall score. Later, we’ll even show you how this dashboard can include log data. It’s going to be good! Let’s get started.
Cheat code: Cut (scene) to the chase
What if you want an amazing dashboard like that, but don’t want to go through every step of instrumentation we will be describing below? We’ve got good news because we’ve already done all the heavy lifting for you. If you follow these quick steps, you’ll have a dashboard of your own up and running in no time.
- Make sure you’ve got a New Relic account. You can sign-up for free here. Free accounts include 100 GB/month of free data ingest, one free full-platform user, and unlimited free basic users.
- Set up a system so it can run Python with pygame modules on the command line. That can be a laptop, a virtual machine, a cloud instance, or even a project in an online IDE like Replit.
- Head over to Rachel’s GitHub (aka DevRel Dragon) and create a local copy of the Data Driven Dave repo.
- Follow the steps in the README.md file to install the game on your system and the dashboard in your New Relic account.
- Play the game.
That’s it! Playing the game will send telemetry data into your New Relic account. You can explore your application data in the New Relic platform. Specifically, you will notice the application performance monitoring (APM) Summary, Transactions and Logs screens are now reporting data about the Data Driven Dave game. Pretty cool, right? Go ahead, take some time to explore a little bit.
Oh wow. You’re still reading — even after spinning up the game? Okay, you’re serious. Well, roll up your sleeves and let’s dig into the code to see how we pulled this off.
Ready player one: Getting started with custom instrumentation in Python
New Relic does a great job in the guided installation process of walking you through the steps necessary to get up and running quickly with a new account. There’s a bit of bias in the process, and applications without a web frontend can fall through the cracks. We’re going to show you ways to solve that problem. For our purposes, because the original code behind Data Driven Dave was written in Python, we’re going to take a look at how you can use the Python agent API to customize your monitoring solution.
To start, in your code you must import the newrelic.agent module and initialize it with a specified config file.
The initialize call sets up the Python agent, but does not register the agent with a collector — a component that collects data from New Relic agents.
You should call register_application as soon as possible — as it relates to processing order in your code — after the call to initialize.
Next, you can use Python code decorators to instrument your non-web transactions. Typically, you might use these decorators in a way that most accurately reflects the function-level segments of your transaction trace. For example:
However, for our game demonstration, we wanted to show more transactions in APM. So, we chose to use the background_task decorator exclusively. Here’s an excerpt from main_fun.py:
Finally, at the end of your code, call the shutdown_agent to shut down the agent and make a final upload of data to the collector.
And just like that, you are sending your application telemetry data to New Relic.
If you are a nonprofit organization, looking to level up your Observability tools, sign up for a free account here:
https://newrelic.com/social-impact/signup
New Relic offers free tools and full platform features along with 1TB of free monthly data injest and 5 user accounts to all qualifying global nonprofit customers! Just email us at hgruber(at)newrelic(dot)com to find out more!