New Relic Now Start training on Intelligent Observability February 25th.
Save your seat.
Pour le moment, cette page n'est disponible qu'en anglais.

Of the many challenges facing application development, one recently became of particular interest to the New Relic mobile apps team: App developers are often in the position of depending on APIs that belong to other teams. If you develop mobile apps in a large enterprise, you probably already know that this codependency can be stressful and difficult to manage, especially if communication channels are compromised or broken. The most innocent change to an API’s structure can seriously affect the reliability of your app, and you may not even know the change is coming.

How then can mobile developers protect the integrity of their apps when they rely on other teams’ APIs? At New Relic, the mobile apps team combines New Relic Mobile and New Relic APM 360 with custom New Relic Synthetics scripts to help ensure high levels of app performance.

New Relic Synthetics—not just for browsers

Synthetics is a suite of automated, scriptable tools commonly used to monitor real-world website performance and the critical business transactions that occur in web apps. With Synthetics you can establish a ping monitor, set up a simple browser, and interact with a site to make sure it loads properly and that all buttons are functional.

Another important Synthetics capability involves running scripted API tests. In essence, a scripted API test hits the backend API your mobile app is reliant on, validates that the responses it receives are what you expect, and alerts you if they’re not. In fact, we use Synthetics in conjunction with our New Relic Insights mobile app and New Relic iOS and Android apps as an everyday best practice.

The apps we build on the mobile team make API calls from such a large code base that it’s difficult to track all the changes other teams make to their APIs. To make sure we’re able to manage and respond to any changes, we’ve written a Synthetics script that hits the various APIs our apps depend on. We’re sharing the script here, so anyone can use it!

Using our script

Our script reads a JSON schema file that tells the script what API paths it needs to hit. Basically, three things happen:

  1. The script logs in to our app and gets a token.
  2. The script hits the API defined in the JSON schema.
  3. The script then tests the API's endpoints for health status, throughput, error rate, and other details.

You’ll need these three files, available on Github:

The example schema tests the New Relic REST API (v2), but you can create your own schema file for testing your own endpoints. If you want to try anything other than our basic example, we’ve documented the code inline with more explanation of how to use it.

To use our example as is, here’s how to get started:

  1. If you don’t already have one, create a New Relic REST API key.
  2. Create a Synthetics secure credential, and specify REST_API_KEY as the key.
  3. Set up a Synthetics API test, and paste the script into the script editor.
  4. Run the script.

You can run this test as often as you see fit; for example, we run the script every 30 minutes for all of the APIs that we consume.

Synthetic checks—a mobile developer’s best friend

The mobile apps team considers these Synthetics API checks basic due diligence, in both staging and production. In staging, we use the script to confirm that any changes made by another team won’t break our apps in production. In production, we use Synthetics checks to monitor our mobile applications to make sure they’re performing as expected. When we do encounter issues, we raise “soft alerts”—these won’t wake someone up in the middle of the night, but they will send a notification to Slack or email so the appropriate team can address the issue during work hours.

By combining Synthetics with New Relic Mobile and New Relic APM, our team is able to understand the complete performance story of our mobile apps. We’re able to catch API-dependency issues early, resolve them quickly, and ship mobile apps that are highly performant for our users.