-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
feat: Allow id or event_id in project events endpoint #10898
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,8 +7,9 @@ | |
from sentry.api.base import DocSection | ||
from sentry.api.bases.project import ProjectEndpoint | ||
from sentry.api.serializers import serialize | ||
from sentry.models import Event | ||
from sentry.models import Event, Release, UserReport | ||
from sentry.utils.apidocs import scenario, attach_scenarios | ||
from sentry.utils.validators import is_event_id | ||
|
||
|
||
@scenario('RetrieveEventForProject') | ||
|
@@ -23,6 +24,20 @@ def retrieve_event_for_project_scenario(runner): | |
class ProjectEventDetailsEndpoint(ProjectEndpoint): | ||
doc_section = DocSection.EVENTS | ||
|
||
def _get_release_info(self, request, event): | ||
version = event.get_tag('sentry:release') | ||
if not version: | ||
return None | ||
try: | ||
release = Release.objects.get( | ||
projects=event.project, | ||
organization_id=event.project.organization_id, | ||
version=version, | ||
) | ||
except Release.DoesNotExist: | ||
return {'version': version} | ||
return serialize(release, request.user) | ||
|
||
@attach_scenarios([retrieve_event_for_project_scenario]) | ||
def get(self, request, project, event_id): | ||
""" | ||
|
@@ -35,16 +50,33 @@ def get(self, request, project, event_id): | |
event belongs to. | ||
:pparam string project_slug: the slug of the project the event | ||
belongs to. | ||
:pparam string event_id: the hexadecimal ID of the event to | ||
retrieve (as reported by the raven client). | ||
:pparam string event_id: the id of the event to retrieve (either the | ||
numeric primary-key or the hexadecimal id as | ||
reported by the raven client) | ||
:auth: required | ||
""" | ||
try: | ||
event = Event.objects.get( | ||
event_id=event_id, | ||
project_id=project.id, | ||
) | ||
except Event.DoesNotExist: | ||
|
||
event = None | ||
# If its a numeric string, check if it's an event Primary Key first | ||
if event_id.isdigit(): | ||
try: | ||
event = Event.objects.get( | ||
id=event_id, | ||
project_id=project.id, | ||
) | ||
except Event.DoesNotExist: | ||
pass | ||
# If it was not found as a PK, and its a possible event_id, search by that instead. | ||
if event is None and is_event_id(event_id): | ||
try: | ||
event = Event.objects.get( | ||
event_id=event_id, | ||
project_id=project.id, | ||
) | ||
except Event.DoesNotExist: | ||
pass | ||
|
||
if event is None: | ||
return Response({'detail': 'Event not found'}, status=404) | ||
|
||
Event.objects.bind_nodes([event], 'data') | ||
|
@@ -72,7 +104,17 @@ def get(self, request, project, event_id): | |
except IndexError: | ||
prev_event = None | ||
|
||
try: | ||
user_report = UserReport.objects.get( | ||
event_id=event.event_id, | ||
project=event.project, | ||
) | ||
except UserReport.DoesNotExist: | ||
user_report = None | ||
|
||
data = serialize(event, request.user) | ||
data['userReport'] = serialize(user_report, request.user) | ||
data['release'] = self._get_release_info(request, event) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. would probably be nice to move the shared stuff between this and the other endpoint into a serializer or something (maybe There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good idea. Have done it here. #10921 |
||
|
||
if next_event: | ||
data['nextEventID'] = six.text_type(next_event.event_id) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,12 +38,15 @@ const GroupEventDetails = createReactClass({ | |
}, | ||
|
||
fetchData() { | ||
let eventId = this.props.params.eventId || 'latest'; | ||
const eventId = this.props.params.eventId || 'latest'; | ||
const groupId = this.getGroup().id; | ||
const orgSlug = this.getOrganization().slug; | ||
const projSlug = this.getProject().slug; | ||
|
||
let url = | ||
eventId === 'latest' || eventId === 'oldest' | ||
? '/issues/' + this.getGroup().id + '/events/' + eventId + '/' | ||
: '/events/' + eventId + '/'; | ||
? `/issues/${groupId}/events/${eventId}/` | ||
: `/projects/${orgSlug}/${projSlug}/events/${eventId}/`; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not 100% sure this is the only place that called |
||
|
||
this.setState({ | ||
loading: true, | ||
|
@@ -59,9 +62,9 @@ const GroupEventDetails = createReactClass({ | |
}); | ||
|
||
this.api.bulkUpdate({ | ||
orgId: this.getOrganization().slug, | ||
projectId: this.getProject().slug, | ||
itemIds: [this.getGroup().id], | ||
orgId: orgSlug, | ||
projectId: projSlug, | ||
itemIds: [groupId], | ||
failSilently: true, | ||
data: {hasSeen: true}, | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
copypasta from https://github.com/getsentry/sentry/blob/master/src/sentry/api/endpoints/event_details.py#L18-L30