from django.views import defaults
from sentry_sdk import capture_message


def page_not_found(*args, **kwargs):
    capture_message("Page not found", level="error")

    return defaults.page_not_found(*args, **kwargs)

from django.views import defaults
from sentry_sdk import capture_message, push_scope


def page_not_found(request, *args, **kwargs):
    with push_scope() as scope:
        scope.set_tag("type", "404")
        scope.set_extra("path", request.path)

        capture_message("Page not found", level="error")

    return defaults.page_not_found(request, *args, **kwargs)

Set some event data on 404 logging
Set some event data on 404 logging

  from django.views import defaults
- from sentry_sdk import capture_message
+ from sentry_sdk import capture_message, push_scope
  
  
- def page_not_found(*args, **kwargs):
+ def page_not_found(request, *args, **kwargs):
-     capture_message("Page not found", level="error")
+     with push_scope() as scope:
+         scope.set_tag("type", "404")
+         scope.set_extra("path", request.path)
  
-     return defaults.page_not_found(*args, **kwargs)
+         capture_message("Page not found", level="error")
  
+     return defaults.page_not_found(request, *args, **kwargs)
+ 
Set some event data on 404 logging
## Code Before:
from django.views import defaults
from sentry_sdk import capture_message


def page_not_found(*args, **kwargs):
    capture_message("Page not found", level="error")

    return defaults.page_not_found(*args, **kwargs)

## Instruction:
Set some event data on 404 logging
## Code After:
from django.views import defaults
from sentry_sdk import capture_message, push_scope


def page_not_found(request, *args, **kwargs):
    with push_scope() as scope:
        scope.set_tag("type", "404")
        scope.set_extra("path", request.path)

        capture_message("Page not found", level="error")

    return defaults.page_not_found(request, *args, **kwargs)
