How to Fix Server Issues By Integrating New Relic With Bugfender
Tags: announcements, bugfenderintegratio, coding, engineering
Published: 2019-04-02 11:48:49

---
title: How to Fix Server Issues By Integrating New Relic With Bugfender
published: true
tags: Announcements,Bugfender Integratio,Coding,Engineering
canonical_url: https://bugfender.com/blog/how-to-fix-server-issues-by-integrating-new-relic-with-bugfender/
---

![](https://bugfender.com/wp-content/uploads/2019/04/new-relic-integration.jpg)

[New Relic](https://newrelic.com/) 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.getDeviceIdentifier());
params.put("X-Bugfender-Session", Bugfender.getSessionIdentifier());
```

## **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](https://docs.newrelic.com/docs/agents/php-agent/php-agent-api/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:

![](https://lh4.googleusercontent.com/8Xrd803V_MQiuZPp90YnzbD9NI6FkLDNZzlvMpohAzxfB94XlVbzWeJ-YKzakznFmSSgnPTFy82pq-BRfzrhWGJkClhHoGg4_gCEhbFvuTzmg_IfMw0UZmNbOsga7XRVQaS-G14)

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