def get(self, request, event_id): """ Retrieve an Event ````````````````` This endpoint returns the data for a specific event. The event ID is the event as it appears in the Sentry database and not the event ID that is reported by the client upon submission. """ try: event = Event.objects.get(id=event_id) except Event.DoesNotExist: raise ResourceDoesNotExist self.check_object_permissions(request, event.group) Event.objects.bind_nodes([event], 'data') data = serialize(event, request.user, DetailedEventSerializer()) next_event = event.next_event prev_event = event.prev_event data['nextEventID'] = next_event and six.text_type(next_event.id) data['previousEventID'] = prev_event and six.text_type(prev_event.id) return Response(data)
def get(self, request, event_id): """ Retrieve an Event ````````````````` This endpoint returns the data for a specific event. The event ID is the event as it appears in the Sentry database and not the event ID that is reported by the client upon submission. This method is deprecated. """ event = Event.objects.from_event_id(event_id, project_id=None) if event is None: raise ResourceDoesNotExist self.check_object_permissions(request, event.group) Event.objects.bind_nodes([event], 'data') data = serialize(event, request.user, DetailedEventSerializer()) data['nextEventID'] = event.next_event_id() data['previousEventID'] = event.prev_event_id() return Response(data)
def get(self, request, project, event_id): """ Retrieve an Event for a Project ``````````````````````````````` Return details on an individual event. :pparam string organization_slug: the slug of the organization the event belongs to. :pparam string project_slug: the slug of the project the event belongs to. :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 """ event = Event.objects.from_event_id(event_id, project.id) if event is None: return Response({'detail': 'Event not found'}, status=404) Event.objects.bind_nodes([event], 'data') data = serialize(event, request.user, DetailedEventSerializer()) next_event = event.next_event prev_event = event.prev_event # TODO this is inconsistent with the event_details API which uses the # `id` instead of the `event_id` data['nextEventID'] = next_event and six.text_type(next_event.event_id) data['previousEventID'] = prev_event and six.text_type( prev_event.event_id) return Response(data)
def get(self, request, project, event_id): """ Retrieve an Event for a Project ``````````````````````````````` Return details on an individual event. :pparam string organization_slug: the slug of the organization the event belongs to. :pparam string project_slug: the slug of the project the event belongs to. :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 """ snuba_event = SnubaEvent.objects.from_event_id(event_id, project.id) if snuba_event is None: return Response({'detail': 'Event not found'}, status=404) data = serialize(snuba_event, request.user, DetailedEventSerializer()) requested_environments = set(request.GET.getlist('environment')) next_event_id = snuba_event.next_event_id( environments=requested_environments) prev_event_id = snuba_event.prev_event_id( environments=requested_environments) data['nextEventID'] = next_event_id data['previousEventID'] = prev_event_id return Response(data)
def get(self, request, project, event_id): """ Retrieve an Event for a Project ``````````````````````````````` Return details on an individual event. :pparam string organization_slug: the slug of the organization the event belongs to. :pparam string project_slug: the slug of the project the event belongs to. :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 """ event = eventstore.get_event_by_id(project.id, event_id) if event is None: return Response({"detail": "Event not found"}, status=404) data = serialize(event, request.user, DetailedEventSerializer()) # Used for paginating through events of a single issue in group details # Skip next/prev for issueless events next_event_id = None prev_event_id = None if event.group_id: requested_environments = set(request.GET.getlist("environment")) conditions = [["event.type", "!=", "transaction"]] if requested_environments: conditions.append( ["environment", "IN", requested_environments]) _filter = eventstore.Filter(conditions=conditions, project_ids=[event.project_id], group_ids=[event.group_id]) # Ignore any time params and search entire retention period next_event_filter = deepcopy(_filter) next_event_filter.end = datetime.utcnow() next_event = eventstore.get_next_event_id(event, filter=next_event_filter) prev_event_filter = deepcopy(_filter) prev_event_filter.start = datetime.utcfromtimestamp(0) prev_event = eventstore.get_prev_event_id(event, filter=prev_event_filter) next_event_id = next_event[1] if next_event else None prev_event_id = prev_event[1] if prev_event else None data["nextEventID"] = next_event_id data["previousEventID"] = prev_event_id return Response(data)
def get(self, request, project, event_id): """ Retrieve an Event for a Project ``````````````````````````````` Return details on an individual event. :pparam string organization_slug: the slug of the organization the event belongs to. :pparam string project_slug: the slug of the project the event belongs to. :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 """ event = eventstore.get_event_by_id(project.id, event_id) if event is None: return Response({"detail": "Event not found"}, status=404) data = serialize(event, request.user, DetailedEventSerializer()) # Used for paginating through events of a single issue in group details # Skip next/prev for issueless events next_event_id = None prev_event_id = None if event.group_id: requested_environments = set(request.GET.getlist("environment")) conditions = [] if requested_environments: conditions.append( ["environment", "IN", requested_environments]) filter_keys = { "project_id": [event.project_id], "issue": [event.group_id] } next_event = eventstore.get_next_event_id(event, conditions=conditions, filter_keys=filter_keys) prev_event = eventstore.get_prev_event_id(event, conditions=conditions, filter_keys=filter_keys) next_event_id = next_event[1] if next_event else None prev_event_id = prev_event[1] if prev_event else None data["nextEventID"] = next_event_id data["previousEventID"] = prev_event_id return Response(data)
def get(self, request, project, event_id): """ Retrieve an Event for a Project ``````````````````````````````` Return details on an individual event. :pparam string organization_slug: the slug of the organization the event belongs to. :pparam string project_slug: the slug of the project the event belongs to. :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 """ 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') data = serialize(event, request.user, DetailedEventSerializer()) next_event = event.next_event prev_event = event.prev_event # TODO this is inconsistent with the event_details API which uses the # `id` instead of the `event_id` data['nextEventID'] = next_event and six.text_type(next_event.event_id) data['previousEventID'] = prev_event and six.text_type( prev_event.event_id) return Response(data)
def get_legacy(self, request, project, event_id): event = Event.objects.from_event_id(event_id, project.id) if event is None: return Response({'detail': 'Event not found'}, status=404) Event.objects.bind_nodes([event], 'data') data = serialize(event, request.user, DetailedEventSerializer()) next_event_id = event.next_event_id() prev_event_id = event.prev_event_id() # TODO this is inconsistent with the event_details API which uses the # `id` instead of the `event_id` data['nextEventID'] = next_event_id data['previousEventID'] = prev_event_id return Response(data)
def get(self, request, event_id): """ Retrieve an Event ````````````````` This endpoint returns the data for a specific event. The event ID is the event as it appears in the Sentry database and not the event ID that is reported by the client upon submission. """ try: event = Event.objects.get(id=event_id) except Event.DoesNotExist: raise ResourceDoesNotExist self.check_object_permissions(request, event.group) Event.objects.bind_nodes([event], 'data') # HACK(dcramer): work around lack of unique sorting on datetime base_qs = Event.objects.filter( group_id=event.group_id, ).exclude(id=event.id) # First, we collect 5 leading/trailing events next_events = sorted( base_qs.filter( datetime__gte=event.datetime, ).order_by('datetime')[0:5], key=EVENT_ORDERING_KEY, ) prev_events = sorted( base_qs.filter( datetime__lte=event.datetime, ).order_by('-datetime')[0:5], key=EVENT_ORDERING_KEY, reverse=True, ) # Now, try and find the real next event. # "next" means: # * If identical timestamps, greater of the ids # * else greater of the timestamps next_event = None for e in next_events: if e.datetime == event.datetime and e.id > event.id: next_event = e break if e.datetime > event.datetime: next_event = e break # Last, pick the previous event # "previous" means: # * If identical timestamps, lesser of the ids # * else lesser of the timestamps prev_event = None for e in prev_events: if e.datetime == event.datetime and e.id < event.id: prev_event = e break if e.datetime < event.datetime: prev_event = e break data = serialize(event, request.user, DetailedEventSerializer()) if next_event: data['nextEventID'] = six.text_type(next_event.id) else: data['nextEventID'] = None if prev_event: data['previousEventID'] = six.text_type(prev_event.id) else: data['previousEventID'] = None return Response(data)
def get(self, request, project, event_id): """ Retrieve an Event for a Project ``````````````````````````````` Return details on an individual event. :pparam string organization_slug: the slug of the organization the event belongs to. :pparam string project_slug: the slug of the project the event belongs to. :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 """ 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') # HACK(dcramer): work around lack of unique sorting on datetime base_qs = Event.objects.filter( group_id=event.group_id, ).exclude(id=event.id) try: next_event = sorted(base_qs.filter( datetime__gte=event.datetime).order_by('datetime')[0:5], key=lambda x: (x.datetime, x.id))[0] except IndexError: next_event = None try: prev_event = sorted(base_qs.filter( datetime__lte=event.datetime, ).order_by('-datetime')[0:5], key=lambda x: (x.datetime, x.id), reverse=True)[0] except IndexError: prev_event = None data = serialize(event, request.user, DetailedEventSerializer()) if next_event: data['nextEventID'] = six.text_type(next_event.event_id) else: data['nextEventID'] = None if prev_event: data['previousEventID'] = six.text_type(prev_event.event_id) else: data['previousEventID'] = None return Response(data)