Skip to content

ref(api): Report client_kind attributes from every endpoint - #123907

Merged
DominikB2014 merged 4 commits into
masterfrom
ref/client-kind-attributes-all-endpoints
Sep 9, 2026
Merged

ref(api): Report client_kind attributes from every endpoint#123907
DominikB2014 merged 4 commits into
masterfrom
ref/client-kind-attributes-all-endpoints

Conversation

@DominikB2014

@DominikB2014 DominikB2014 commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

The client_kind caller-attribution wiring lived in OrganizationEventsEndpointBase.convert_args, so only the ~44 events endpoints reported it. This moves it to a single call site in Endpoint.dispatch, which reads the organization convert_args already resolved — from the organization kwarg, or off request.organization, which every organization-scoped base assigns and which access_log already reads the same way.

The organization is used only to check the opt-in. get_client_kind derives everything else from the request and no longer takes one, which also drops the Organization/RpcOrganization handling from client_kind.py. Ordering matters here: the flag is checked before set_client_kind_attributes, so a client_kind_scope declaration can't report for an org that never enabled the feature.

Coverage goes from ~44 endpoints to 300+ — organization, project, team and issue endpoints — with no per-endpoint wiring, and new endpoints are picked up automatically. Everything stays behind the existing organizations:api-client-kind-check flag, so the only work added to an unflagged request is one features.has call.

I ran this locally and can see it logging the derived client_kind for requests as they come in.

One behavior change worth noting: attributes are now recorded only after convert_args completes, so an endpoint whose convert_args raises after super() no longer reports. OrganizationEventDetailsEndpoint is the only affected subclass.

@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label Sep 9, 2026

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit be65ac1. Configure here.

Comment thread src/sentry/api/base.py Outdated
The caller attribution wiring lived in OrganizationEventsEndpointBase.convert_args, so only the ~44 events endpoints reported it. Move it to a single call site in Endpoint.dispatch, driven by an overridable client_kind_organization hook: the default reads the organization kwarg that every org-scoped base populates, and ProjectEndpoint reads it off the project it already select_relateds.

Widens get_client_kind to accept RpcOrganization so control-silo organization endpoints are covered too. Coverage goes from ~44 endpoints to 300+, with no per-endpoint wiring.
TeamEndpoint and GroupEndpoint resolve their organization off the related object rather than into the organization kwarg, so the default hook left 38 endpoints unattributed. Both already select_related the organization, so neither override costs a query.
@DominikB2014
DominikB2014 force-pushed the ref/client-kind-attributes-all-endpoints branch from 94752f5 to 37caa88 Compare September 9, 2026 14:42
@DominikB2014

Copy link
Copy Markdown
Contributor Author

@cursor review

@DominikB2014
DominikB2014 marked this pull request as ready for review September 9, 2026 14:56
@DominikB2014
DominikB2014 requested review from a team as code owners September 9, 2026 14:56
@linear-code

linear-code Bot commented Sep 9, 2026

Copy link
Copy Markdown

ENG-8570

Comment thread src/sentry/api/bases/project.py Outdated
@DominikB2014
DominikB2014 requested a review from a team as a code owner September 9, 2026 15:36
Per review feedback: the organization was only ever needed for the feature flag, not for classification. Moving that check up to the dispatch call site lets get_client_kind and set_client_kind_attributes drop the organization parameter entirely, along with the Organization/RpcOrganization widening and both model imports.

The client_kind_organization hook stays, so a base that resolves its organization some other way is still covered and plain Endpoint subclasses that populate the organization kwarg keep working without per-base wiring. At GA the hook and the features.has call delete together, leaving one unconditional call.

Ordering matters here: the opt-in is checked before set_client_kind_attributes, so a client_kind_scope declaration cannot report for an org that never enabled the feature. That guarantee used to be enforced inside get_client_kind; test_a_declared_kind_does_not_bypass_the_opt_in now pins it at dispatch.
@DominikB2014
DominikB2014 force-pushed the ref/client-kind-attributes-all-endpoints branch from 8f02e7f to 9ceef94 Compare September 9, 2026 15:39
Every base that resolves an organization already assigns it to request._request.organization, and DRF proxies attribute lookups to the underlying HttpRequest, so dispatch can read it directly. access_log.py already reads it the same way.

That removes the client_kind_organization hook and its three overrides -- no extension point on Endpoint for what is temporary scaffolding. kwargs is still consulted first, because the SentryApp bases populate only that and never touch the request.

The hook's unit tests are replaced by real requests against organization, project, team and issue endpoints, which is the only honest way to pin coverage now that there is no seam. Removing the request fallback fails the project, team and issue cases.

@skaasten skaasten left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great 🚀

@DominikB2014
DominikB2014 enabled auto-merge (squash) September 9, 2026 16:07
@DominikB2014
DominikB2014 merged commit 899815f into master Sep 9, 2026
90 checks passed
@DominikB2014
DominikB2014 deleted the ref/client-kind-attributes-all-endpoints branch September 9, 2026 16:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants