# How to ignore http status code 501 from being considered as error in APM

**URL:** <https://discuss.elastic.co/t/how-to-ignore-http-status-code-501-from-being-considered-as-error-in-apm/356976>\
**Category:** APM\
**Tags:** elastic-stack-monitoring, nodejs\
**Created:** [April 8, 2024, 1:40pm UTC](https://discuss.elastic.co/t/how-to-ignore-http-status-code-501-from-being-considered-as-error-in-apm/356976 "2024-04-08T13:40:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anandakumar](https://avatars.discourse-cdn.com/v4/letter/a/cc9497/32.png) [@Anandakumar](https://discuss.elastic.co/u/Anandakumar)\
**Post date:** [April 8, 2024, 1:40pm UTC](https://discuss.elastic.co/t/how-to-ignore-http-status-code-501-from-being-considered-as-error-in-apm/356976/1 "2024-04-08T13:40:32Z")

</div>

Hi,

We are using `elastic-apm-node` package to send APM to our Elastic Cloud deployment. One of our services tends to receive a lot of requests from a 3rd party which we don't support at this time and so we return 501 status code.

How do we avoid 501 from getting considered as an error in APM `Failed transaction rate`?

---

<div class="post-metadata">

**Author:** ![David\_Luna\_Bistuer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/david_luna_bistuer/32/122147_2.png) [@David\_Luna\_Bistuer](https://discuss.elastic.co/u/David_Luna_Bistuer)\
**Post date:** [April 18, 2024, 12:39pm UTC](https://discuss.elastic.co/t/how-to-ignore-http-status-code-501-from-being-considered-as-error-in-apm/356976/2 "2024-04-18T12:39:21Z")

</div>

Hi @Anandakumar

5XX responses are considered transaction errors and you see int in Kibana as such. They count in the "failed transaction rate" and you see the failed status in the transaction details. like here

 ![Screenshot 2024-04-18 at 14.16.10](https://us1.discourse-cdn.com/elastic/original/3X/c/e/ce9f0d7d2418b5636d56103277e96b5a74d59392.png)

Since the issue is a 3rd party app/service calling an endpoint where they shouldn't I'd suggest to change the HTTP status code to 4XX indicating there is an issue in the request. 4XX statuses are not reported as failed in APM.

If changing the HTTP status is not possible there is another solution that requires updating the instrumentation of your app. You should use [addTransactionFilter API](https://www.elastic.co/guide/en/apm/agent/nodejs/current/agent-api.html#apm-add-transaction-filter) to change the outcome of the transaction from `failure` to `unknown` or `success` (probably you'd prefer the later).

Here is a small snippet on how to change the status of a transaction

```js
// Keep a reference to the APM agent
const apm = require('elastic-apm-node').start({
  serviceName: 'example-trace-http',
  usePathAsTransactionName: true,
});

// call the agent's API to modify transaction payloads
// before sending
apm.addTransactionFilter((payload) => {
  if (
    payload &&
    payload.context &&
    payload.context.response &&
    payload.context.response.status_code === 501
  ) {
    payload.outcome = 'unknown';
  }
  return payload;
});

```

Hope this helps on your issue.  
Cheers,  
David
