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)

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("path", request.path)
        for i, part in enumerate(request.path.strip("/").split("/")):
            scope.set_tag("path_{}".format(i), part)

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

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

Tag sentry event with each part of path
Tag sentry event with each part of path

  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)
+         scope.set_tag("path", request.path)
+         for i, part in enumerate(request.path.strip("/").split("/")):
+             scope.set_tag("path_{}".format(i), part)
  
          capture_message("Page not found", level="error")
  
      return defaults.page_not_found(request, *args, **kwargs)
  
Tag sentry event with each part of path
## Code Before:
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)

## Instruction:
Tag sentry event with each part of path
## 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("path", request.path)
        for i, part in enumerate(request.path.strip("/").split("/")):
            scope.set_tag("path_{}".format(i), part)

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

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