-
Notifications
You must be signed in to change notification settings - Fork 580
Closed
Labels
Description
Currently, the Django integration creates a transaction from the request URL by calling LEGACY_RESOLVER.resolve(request.path). This transforms URLS such as /test/1/ into /test/{pk}/.
However, if the Django application is served from a non-root path, such as /django/, request.path becomes /django/test/1/. Django only processes the /test/1/ part, which is accessible in request.path_info, but the transaction becomes /django/test/1/.
To demonstrate this, I created a new Django project and added the setting FORCE_SCRIPT_NAME = "/test" to settings.py.
I then created the following view:
from django.http.response import JsonResponse
from sentry_sdk.integrations.django.transactions import LEGACY_RESOLVER
def show_example(request, *args, **kwargs):
return JsonResponse(
{
"current": LEGACY_RESOLVER.resolve(request.path),
"correct": LEGACY_RESOLVER.resolve(request.path_info),
}
)I added
path('<int:pk>/<var>/', views.show_example)to the urlpatterns, then executed the runserver management command.
Here is the output of curl http://localhost:8000/1/@/:
{"current": "/test/1/@/", "correct": "/{pk}/{var}/"}