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:
- The script logs in to our app and gets a token.
- The script hits the API defined in the JSON schema.
- 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:
- If you don’t already have one, create a New Relic REST API key.
- Create a Synthetics secure credential, and specify REST_API_KEY as the key.
- Set up a Synthetics API test, and paste the script into the script editor.
- 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.
이 블로그에 표현된 견해는 저자의 견해이며 반드시 New Relic의 견해를 반영하는 것은 아닙니다. 저자가 제공하는 모든 솔루션은 환경에 따라 다르며 New Relic에서 제공하는 상용 솔루션이나 지원의 일부가 아닙니다. 이 블로그 게시물과 관련된 질문 및 지원이 필요한 경우 Explorers Hub(discuss.newrelic.com)에서만 참여하십시오. 이 블로그에는 타사 사이트의 콘텐츠에 대한 링크가 포함될 수 있습니다. 이러한 링크를 제공함으로써 New Relic은 해당 사이트에서 사용할 수 있는 정보, 보기 또는 제품을 채택, 보증, 승인 또는 보증하지 않습니다.