Relic Solution: 500 Errors showing no stack traces in the .NET Agent

Issue:

Depending on the situation, you may find error traces in the APM UI that do not include stack traces for your .NET app.

Cause:

When a 500(or similar) error is returned, it means that the application server itself detected an error and set the HTTPS 500 status code.

  • If the error condition was detected and handled by application logic, there was no exception object and thus, no stack.
  • If there was an exception object at some point, but it was handled internally by the application code that set the 500 status on the response, then the exception never became visible to the .NET agent. There is no stack available for the .NET agent to report.

When stack traces are reported, the error results from an exception that was not caught and handled within the application server logic. The .NET agent sees the unhandled exception during a monitored transaction, so it reports the stack trace.

However, no stack traces appear for the 500 errors because the application server is handling the errors and then setting the status code. The application code itself does not retain any stack traces.

Solution:

You can use the .NET NoticeError API from your own code.

NewRelic.Api.Agent.NewRelic.NoticeError(exception $exception[, IDictionary $attributes])
NewRelic.Api.Agent.NewRelic.NoticeError(string $error_message, IDictionary $attributes)
NewRelic.Api.Agent.NewRelic.NoticeError(string $error_message, IDictionary $attributes, bool $is_expected)

Notice an error and report it to New Relic along with optional custom attributes. For each transaction, the agent only retains the exception and attributes from the first call to NoticeError() . You can pass an actual exception, or pass a string to capture an arbitrary error message.