error_collector.expected_status_codes setting is not set properly
Description
After setting error_collector.expected_status_codes, no errors are marked as expected.
Expected Behavior
Errors with the status codes given in setting are marked as expected.
Troubleshooting or NR Diag results
The config setting is correct when viewing Settings > Environment > Agent initialization

~~But Settings > Application shows that the value isn't set:~~

edit: above screenshot is irrelevant, since it shows Server-side configuration.
Steps to Reproduce
Add the following to newrelic.ini
error_collector.expected_status_codes = 403 404 409 422
Your Environment

Additional context
- Server-side configuration is disabled
We are currently working around this by setting error_collector.expected_classes instead, which does work as expected.
Hi @sloria! The Settings > Application view you are pointing out is the server-side configuration view for your app. We would not expect those status codes to show up there unless you have enabled server side config explicitly. Are you finding that the agent is still factoring the status codes you marked as expected into your error rate/ Apdex score?
@umaannamalai Oh sorry, you're right--my screenshot is misleading. in any case, the setting did not have the expected effect.
Are you finding that the agent is still factoring the status codes you marked as expected into your error rate/ Apdex score?
yes, when setting error_collector.expected_status_codes, those errors still appear in the error rate metrics.
@sloria From looking at your screenshots it looks like you're using uwsgi and Flask. I spun up a test app with the following route.
@app.route('/coffee')
def coffee():
raise werkzeug.exceptions.ImATeapot()
And set the expected status codes accordingly.
error_collector.expected_status_codes = 418
After running traffic for several minutes I see all errors being properly expected in my audit_log, and the UI shows no errors included in the error rate but hundreds of these in the errors inbox, which is what I would expect out of the feature working properly.
Any part of this jump out to you as significantly different than your existing application? I'm running v7.14.0 the same as what's listed in your screenshot.
Are you by chance not using werkzeug exceptions for your status codes and raising things in some other way?
For reference this is the code that's used to extract status code information from exceptions in Flask applications.
https://github.com/newrelic/newrelic-python-agent/blob/ad65494033a6aef95fa2cd10b49ae73cb4c612ed/newrelic/hooks/framework_flask.py#L37-L45
Oh I see, that's the issue--we're using a framework that re-raises werkzeug.exceptions.HTTPExceptions with a custom error, so we won't hit that code.
perhaps the issue could be solved with some duck typing. something like
response = getattr(value, "response", None)
if hasattr(response, "status_code"):
return response.status_code
that said, we're perfectly fine using expected_classes for the time being, so no urgency from my end!
Hi all!
In Dash plotly apps, How the agent ignore the status codes I marked as expected into the error rate/ Apdex score?
@glenlp Have you tried using the notice_error API? You can pass in the errors you would like to mark as expected directly to this API.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.