Skip to content

Comments

Fix transaction naming for django-ninja endpoints with transaction_style="function_name"#1

Merged
avilaton merged 4 commits intotransaction-naming-django-ninjafrom
copilot/fix-sentry-transaction-style-issue
Feb 17, 2026
Merged

Fix transaction naming for django-ninja endpoints with transaction_style="function_name"#1
avilaton merged 4 commits intotransaction-naming-django-ninjafrom
copilot/fix-sentry-transaction-style-issue

Conversation

Copy link

Copilot AI commented Feb 17, 2026

Django-ninja endpoints were all grouped under ninja.operation.PathView._sync_view when using transaction_style="function_name", making it impossible to distinguish between different API endpoints in Sentry.

Django's resolve() returns the PathView wrapper function instead of the actual endpoint. The wrapper is shared across all endpoints on the same path, causing the grouping issue.

Changes

  • Added _unwrap_django_ninja_view() - Detects PathView wrappers by checking __qualname__, extracts the PathView instance from the closure, matches the HTTP method to the correct Operation, and returns the actual endpoint function
  • Modified _set_transaction_name_and_source() - Calls unwrapper when transaction_style="function_name" before extracting the transaction name
  • Added integration tests - Validates both function_name and url transaction styles work correctly with ninja endpoints

Example

Before this change, all these endpoints would be grouped as ninja.operation.PathView._sync_view:

@api.get("/users")
def list_users(request):
    ...

@api.post("/users")
def create_user(request):
    ...

After this change, they get distinct names: myapp.views.list_users and myapp.views.create_user.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 3 commits February 17, 2026 14:41
Co-authored-by: avilaton <2209022+avilaton@users.noreply.github.com>
Co-authored-by: avilaton <2209022+avilaton@users.noreply.github.com>
Co-authored-by: avilaton <2209022+avilaton@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix Sentry Django integration transaction naming for Django Ninja Fix transaction naming for django-ninja endpoints with transaction_style="function_name" Feb 17, 2026
Copilot AI requested a review from avilaton February 17, 2026 14:46
@avilaton avilaton marked this pull request as ready for review February 17, 2026 14:56
@avilaton avilaton changed the base branch from master to transaction-naming-django-ninja February 17, 2026 14:57
@avilaton avilaton merged commit fe04211 into transaction-naming-django-ninja Feb 17, 2026
@avilaton avilaton deleted the copilot/fix-sentry-transaction-style-issue branch February 17, 2026 14:58
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

Successfully merging this pull request may close these issues.

2 participants