elastic / elastic/apm-agent-python

[EVENT OUTCOME] 4xx status codes are always reported as errors

Open
#1,760 5 comments 0 reactions 0 assignees View on GitHub
agent-python community triage
Dominant language
Python
Stars
431
Forks
239
Avg merge
5d 10h
Merged PRs (30d)
7

Description

**Describe the bug**:
For any calls to services, all 4xx status codes are reporting as error. This includes expected 401 / 403 / 404 codes, which just indicate an issue with the requester (not an error in code).

This causes our alerts to be useless since we cannot tell if something is an error (to alert every time to fix) or just an invalid request (to alert for anomalies).

**To Reproduce**

1. Set up monitoring for a project with GCS
2. Have code call to GCS bucket to check for existence on a file that doesn't exist (GCS will return 404)
3. Pull up dashboard (or alerts)
4. See that it is reported as an error

**Environment (please complete the following information)**
- OS: Linux
- Python version: 3.8
- Framework and version [e.g. Django 2.1]: Django 3.8
- APM Server version: 7.15
- Agent version: 6.14.0

**Additional context**
- `requirements.txt`:

Click to expand

```
google-cloud-storage==1.42.0
```


**Observations**
It seems to be handled differently on different parts of code:
* in [traces.py](https://github.com/elastic/apm-agent-python/blob/main/elasticapm/traces.py#L1189) it is looking for 5xx's to error
* in [instrumentation](https://github.com/elastic/apm-agent-python/blob/main/elasticapm/instrumentation/packages/urllib3.py#L136) it is looking for 4xx's to error

**Suggestions**
Could we have 4xx's return as invalid request or warning levels instead? We could still be able to monitor and alert for them, but differently than 5xx's

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.