How to Fix Server Issues By Integrating New Relic With Bugfender

How to Fix Server Issues By Integrating New Relic With Bugfender

DebuggingQ/A
Fix bugs faster! Log Collection Made Easy
START NOW!

New Relic has changed the game in the application performance monitoring market. It’s heading towards $1 billion in revenue and has already raced past 17,000 users.

Now we want to explain how to integrate this amazing product with Bugfender to ensure end-to-end traceability for your mobile app.

What’s New Relic?

New Relic’s APM is a software that delivers real-time and trending data about your web application’s performance and the level of satisfaction that your end users experience. It also tracks errors in your backend code, so you can easily fix errors when your customers find them.

Why Do We Need New Relic Integration?

Most mobile apps nowadays have some sort of communication with the backend; the era of apps isolated from the world has long gone.

This means, however, that developers must also factor in potential problems at the back-end when building their app. Even if you’re an amazing mobile developer and your code is almost bug-free, your customers may still end up finding bugs in it.

So, while using Bugfender to monitor your app, it’s important to install a solution to monitor what’s happening at the backend, too.

New Relic is ideal for this purpose. The tool enables developers to track errors in the backend code and identify any problems in the server’s response time, enabling developers to optimize it.

By combining Bugfender and New Relic we can create a complete monitoring solution, providing 100% traceability. Bugfender identifies problems in the front-end of the app, and then the developer can use New Relic to trace the problem to the server.

How to Identify Requests

But we still need to properly flag all requests between the app and the server. By flagging each request, the developers can then work backwards and consult with the backend team to check why that request is not behaving as expected.

But how do we ensure all requests are properly marked?

Well what we need to do is add a custom header to each request. A good tip is to call this header X-Request-Id.

Additionally, it’s recommended that you add the Bufender device ID and the session, so you can recover the app logs if the backend team finds something strange on their monitoring system.

How you add this header depends on the network library you’re using in your app. Below is an Android example that puts these custom headers in a HashMap.

Map<String, String> params = new HashMap<String, String>();
params.put("X-Request-Id", UUID.randomUUID().toString());
params.put("X-Bugfender-Id", Bugfender.getDeviceURL().toString());
params.put("X-Bugfender-Session", Bugfender.getSessionURL().toString());

New Relic Custom Headers Tracking

By default, New Relic (at least for PHP) doesn’t track all custom headers. Even if we add them in the app, they will not be available in New Relic. So it’s vital we properly configure New Relic to save all request headers.

To keep track of these customer headers, we will use the newrelic_add_custom_parameter function. Here’s an example of the code you can use:

$headers = $app->request->headers;

if ($headers->has("X-Request-Id")) {
if (extension_loaded('newrelic')) {
newrelic_add_custom_parameter("request-id", $headers->get("X-Request-Id"));
}
}

if ($headers->has("X-Bugfender-Id")) {
if (extension_loaded('newrelic')) {
newrelic_add_custom_parameter("bugfender-id", $headers->get("X-Bugfender-Id"));
}
}

if ($headers->has("X-Bugfender-Session")) {
if (extension_loaded('newrelic')) {
newrelic_add_custom_parameter("bugfender-session", $headers->get("X-Bugfender-Session"));
}
}

And here you can see that now New Relic tracks this information. Here you have a screenshot of an error:

With this code you will be able to achieve full traceability of your issues, from mobile app to backend. Happy hunting!

Expect the Unexpected! Debug Faster with Bugfender
START FOR FREE

Trusted By

/assets/images/svg/customers/highprofile/macys.svg/assets/images/svg/customers/highprofile/kohler.svg/assets/images/svg/customers/cool/levis.svg/assets/images/svg/customers/highprofile/dolby.svg/assets/images/svg/customers/cool/websummit.svg/assets/images/svg/customers/projects/porsche.svg/assets/images/svg/customers/projects/vorwerk.svg/assets/images/svg/customers/highprofile/adt.svg

Already Trusted by Thousands

Bugfender is the best remote logger for mobile and web apps.

Get Started for Free, No Credit Card Required