Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expected_status_codes is not honored when there is an exception in the transaction #376

Closed
meiao opened this issue Aug 19, 2021 · 10 comments
Assignees
Labels
bug Something isn't working as designed/intended GTSE There is an associated support escalation with this issue.

Comments

@meiao
Copy link
Contributor

meiao commented Aug 19, 2021

Description

Setting a expected_status_code will not mark an error as expected when there is an exception in the transaction.

Expected Behavior

If a transaction returns with a status code that is in the expected_status_code an error from this transaction should be marked as expected regardless of the existence of an exception.

This is how ignored_status_code works.

@meiao meiao added the bug Something isn't working as designed/intended label Aug 19, 2021
@meiao meiao changed the title newrelic.config.error_collector.expected_status_codes is not honored when there is an exception in the transaction expected_status_codes is not honored when there is an exception in the transaction Aug 19, 2021
@meiao
Copy link
Contributor Author

meiao commented Aug 19, 2021

This is likely due to the difference between ThrowableError and HttpTracedError.

@meiao
Copy link
Contributor Author

meiao commented Aug 19, 2021

The repository below has a simple app to reproduce the problem.
https://github.com/meiao/repro-nr-376

@meiao meiao added the GTSE There is an associated support escalation with this issue. label Aug 24, 2021
@sdmcintyre
Copy link

Any idea when this might get looked at? This causes many false alarms in our monitoring due to things like input validation errors (HTTP bad request).

@jasonjkeller
Copy link
Contributor

jasonjkeller commented Oct 6, 2021

If an exception is thrown that has an associated HTTP error response code then simply configuring the error response code as expected (expected_status_code) is not sufficient, you have to configure the exception class as expected (expected_classes).


This works for the repro app that was previously posted:

  error_collector:
    # force agent to override default of ignoring 404s
    ignore_status_codes: 0
    expected_classes:
      -
        class_name: "org.springframework.web.server.ResponseStatusException"
        message: "404 NOT_FOUND"

If the controller is modified in the repro app so that it only returns an error response code instead of throwing an exception:

    @RequestMapping("/")
    public ResponseEntity<String> fourOFour() {
//        throw new ResponseStatusException(HttpStatus.NOT_FOUND);
        return new ResponseEntity<>(HttpStatus.NOT_FOUND);
    }

then the 404 HTTP response code is recorded as error.expected=true with just the following config:

  error_collector:
    # force agent to override default of ignoring 404s
    ignore_status_codes: 0
    expected_status_codes: 404

@jasonjkeller
Copy link
Contributor

Some additional details from a deep dive: https://newrelic.atlassian.net/browse/GTSE-10856?focusedCommentId=980682

@tbradellis
Copy link
Contributor

tbradellis commented Nov 18, 2021

I think the problem starts here with markedExpected:

boolean markedExpected = td.getThrowable() == null ? false : td.getThrowable().expected;

We only check whether it's expected on the Throwable. As @meiao hinted on ThrowableError and HttpTracedError. When we get to HttpTracedError we don't consult the status code to see if we need to set markedExpected differently based on status. I have a local change and will run some tests with a change for this.
Essentially, I think we should just check if the status code is expected and reset markedExpected here:

@tbradellis
Copy link
Contributor

Correction...we also need to check this for ThrowableError.

@tbradellis
Copy link
Contributor

tbradellis commented Nov 18, 2021

boolean responseStatusExpected = errorCollectorConfig.getExpectedStatusCodes().contains(responseStatus);

@sdmcintyre
Copy link

Do we need to update our New Relic Agent to apply the fix?

@meiao
Copy link
Contributor Author

meiao commented Mar 28, 2022

Yes. Agent 7.5.0 has the fix.

@meiao meiao added the 7.5.0 label Mar 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working as designed/intended GTSE There is an associated support escalation with this issue.
Projects
Archived in project
Development

No branches or pull requests

5 participants