Skip to content

chore(sentry-apps): Allow Sentry App tokens to appear on group activity payload #93078

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

leeandher
Copy link
Member

@leeandher leeandher commented Jun 6, 2025

In the event a token issued from a sentry app is used to create an activity, we attribute it to the proxy user instead of a sentry app.

image

To get the sentry app to appear (and minimize API/RPC calls) I added a new rpc method that will return the sentry app, and its avatars (everything the FE will need) to properly render the source of the activity.

Thinking about this more, I would rather read is_sentry_app off of the user property, so I will modify the RPC method to do that instead of using all user_ids.

@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Jun 6, 2025
Copy link

codecov bot commented Jun 6, 2025

Codecov Report

Attention: Patch coverage is 95.77465% with 3 lines in your changes missing coverage. Please review.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/sentry/sentry_apps/services/app/model.py 91.30% 2 Missing ⚠️
src/sentry/sentry_apps/services/app/service.py 75.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           master   #93078       +/-   ##
===========================================
+ Coverage   46.13%   87.89%   +41.75%     
===========================================
  Files       10279    10295       +16     
  Lines      590206   591220     +1014     
  Branches    22977    22977               
===========================================
+ Hits       272316   519647   +247331     
+ Misses     317443    71126   -246317     
  Partials      447      447               

@leeandher leeandher marked this pull request as ready for review June 9, 2025 14:50
@leeandher leeandher requested review from a team as code owners June 9, 2025 14:50
@@ -22,6 +28,35 @@ class RpcApiApplication(RpcModel):
client_secret: str = Field(repr=False, default="")


class RpcSentryAppAvatar(RpcModel):
id: int = -1
ident: str | None = None
Copy link
Contributor

Choose a reason for hiding this comment

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

what is ident? / could we call it uuid?

@@ -87,6 +87,11 @@ def get_sentry_app_by_id(self, *, id: int) -> RpcSentryApp | None:
def get_sentry_app_by_slug(self, *, slug: str) -> RpcSentryApp | None:
pass

@rpc_method
@abc.abstractmethod
def get_sentry_apps_by_proxy_users(self, *, proxy_user_ids: list[int]) -> list[RpcSentryApp]:
Copy link
Contributor

Choose a reason for hiding this comment

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

I forget but can we declare rpc methods & models and use them in the same PR? I forget if the soaking is needed only when editing existing models/methods?

Comment on lines +36 to +52
str(app.proxy_user_id): {
"id": str(app.id),
"name": app.name,
"slug": app.slug,
"avatars": [
{
"avatarType": avatar.get_avatar_type_display(),
"avatarUuid": avatar.ident,
"avatarUrl": avatar.absolute_url(),
"color": avatar.color,
"photoType": avatar.get_avatar_photo_type(),
}
for avatar in app.avatars
],
}
for app in sentry_apps_list
if app.proxy_user_id
Copy link
Contributor

Choose a reason for hiding this comment

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

Q: should we be using the existing serializer for Sentry apps? Is the concern that the existing serializer is too bulky?

Comment on lines +107 to +109
sentry_app_avatar_map = defaultdict(list)
for avatar in sentry_app_avatars:
sentry_app_avatar_map[avatar.sentry_app_id].append(avatar)
Copy link
Contributor

Choose a reason for hiding this comment

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

Kinda random thing I learned but we can do .prefetch_related() to get the associated sentry_app_avatars per sentry_app e.g

sentry_apps = SentryApp.objects.filter(proxy_user_id__in=proxy_user_ids).prefetch_related('sentryappavatar')
...
sentry_app_avatar_map = defaultdict(list)
for app in sentry_apps:
            sentry_app_avatar_map[app.id] = app.sentryappavatar.all()

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