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

Duplicate error log for "HTTP 500 Internal Server Error" #31

Open
browniebroke opened this issue Mar 14, 2024 · 0 comments
Open

Duplicate error log for "HTTP 500 Internal Server Error" #31

browniebroke opened this issue Mar 14, 2024 · 0 comments

Comments

@browniebroke
Copy link
Contributor

  • Django DataDog Logger version: 0.6.3
  • Python version: 3.12
  • Operating System: Docker python:3.12-slim

Description

In case of 5XX errors, the RequestLoggingMiddleware logs an error, using logger.error:

elif 500 <= response.status_code < 600:
log_entry_dict["error.kind"] = response.status_code
log_entry_dict["error.message"] = response.reason_phrase
logger.error(
f"HTTP {response.status_code} {response.reason_phrase}",
extra=log_entry_dict,
)

However, I noticed that it duplicates error logging. In case of 500 error, it seems like Django already logs the exception, and with more context. This causes all errors to be reported twice: once with the generic Django handler and once with this middleware.

We're using Sentry and I noticed that the error logged from the middleware is less actionable: Sentry groups all occurrences together, and there is no stack trace attached.

I was going to suggest to add the option to override the action for error logging in subclasses, so that I could customise it more easily, but maybe we shouldn't log anything in the case of a 500, given that Django logging is good enough.

Then I thought a about more and wondered if anything >=500 make sense?

  • 501: I'm never used this status, but I guess once could choose to return that
  • 502, 503, 504: would typically be raised by a reverse proxy in front of the server, not by Django itself
  • 505 and above: I'm not too sure to be honest...

What I Did

  • Got a 500 error
  • Saw 2 errors in Datadog (and Sentry) instead of one
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant