Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Comments

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

Open
avilaton wants to merge 1 commit intogetsentry:master from
avilaton:transaction-naming-django-ninja
Open

Fix transaction naming for django-ninja endpoints with transaction_style="function_name" #5474
avilaton wants to merge 1 commit intogetsentry:master from
avilaton:transaction-naming-django-ninja

Conversation

@avilaton
Copy link

@avilaton avilaton commented Feb 17, 2026
edited
Loading

Description

DISCLAIMER: We patched django using a middleware to fix this and wanted to contribute it back to sentry, delegated this to copilot and it looks ok, no intention to be ai-slop, just wanted to raise the issue here.

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.

sentry[bot] reacted with hooray emoji
...yle="function_name" (#1)
* Initial plan
* Add django-ninja support for transaction_style=function_name
Co-authored-by: avilaton <2209022+avilaton@users.noreply.github.com>
* Address code review feedback: fix exception handling and improve test
Co-authored-by: avilaton <2209022+avilaton@users.noreply.github.com>
* Fix trailing whitespace in docstring
Co-authored-by: avilaton <2209022+avilaton@users.noreply.github.com>
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: avilaton <2209022+avilaton@users.noreply.github.com>
Copy link
Contributor

github-actions bot commented Feb 17, 2026
edited
Loading

Semver Impact of This PR

None (no version bump detected)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


Internal Changes 🔧

  • (openai-agents) Expect new tool fields by alexander-alderman-webb in #5471
  • (repo) Add .serena to .gitignore by ericapisani in #5464

Other

  • Fix transaction naming for django-ninja endpoints with transaction_style="function_name" by avilaton in #5474

🤖 This preview updates automatically when you update the PR.

@avilaton avilaton marked this pull request as ready for review February 17, 2026 17:58
@avilaton avilaton requested a review from a team as a code owner February 17, 2026 17:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

AltStyle によって変換されたページ (->オリジナル) /