예제 #1
0
    def serialize(self, obj, attrs, user):
        errors = []
        error_set = set()
        for error in obj.data.get("errors", []):
            message = EventError.get_message(error)
            if message in error_set:
                continue
            error_set.add(message)
            error_result = {
                "type": error["type"],
                "message": message,
                "data": {k: v for k, v in error.items() if k != "type"},
            }
            errors.append(error_result)

        # TODO(dcramer): move release serialization here
        d = {
            "id": str(obj.id),
            "groupID": obj.group.id,
            "eventID": str(obj.event_id),
            "size": obj.size,
            "entries": attrs["entries"],
            "message": obj.message,
            "user": attrs["user"],
            "context": obj.data.get("extra", {}),
            "packages": obj.data.get("modules", {}),
            "tags": dict(obj.get_tags(with_internal=False)),
            "platform": obj.platform,
            "dateCreated": obj.datetime,
            "timeSpent": obj.time_spent,
            "errors": errors,
        }
        return d
예제 #2
0
파일: event.py 프로젝트: hyserver/sentry
    def serialize(self, obj, attrs, user):
        errors = []
        error_set = set()
        for error in obj.data.get("errors", []):
            message = EventError.get_message(error)
            if message in error_set:
                continue
            error_set.add(message)
            error_result = {"type": error["type"], "message": message}
            errors.append(error_result)

        d = {
            "id": str(obj.id),
            "groupID": obj.group.id,
            "eventID": str(obj.event_id),
            "size": obj.size,
            "entries": attrs["entries"],
            "message": obj.message,
            "user": attrs["user"],
            "context": obj.data.get("extra", {}),
            "packages": obj.data.get("modules", {}),
            "tags": dict(obj.get_tags()),
            "platform": obj.platform,
            "dateCreated": obj.datetime,
            "timeSpent": obj.time_spent,
            "errors": errors,
        }
        return d
예제 #3
0
def test_api_context():
    error = {"type": "unknown_error", "foo": "bar"}
    assert EventError(error).get_api_context() == {
        "type": "unknown_error",
        "message": "Unknown error",
        "data": {"foo": "bar"},
    }
예제 #4
0
    def serialize(self, obj, attrs, user):
        errors = []
        error_set = set()
        for error in obj.data.get('errors', []):
            message = EventError.get_message(error)
            if message in error_set:
                continue
            error_set.add(message)
            error_result = {
                'type': error['type'],
                'message': message,
                'data': {k: v
                         for k, v in error.items() if k != 'type'},
            }
            errors.append(error_result)

        # TODO(dcramer): move release serialization here
        d = {
            'id': str(obj.id),
            'groupID': obj.group.id,
            'eventID': str(obj.event_id),
            'size': obj.size,
            'entries': attrs['entries'],
            'message': obj.message,
            'user': attrs['user'],
            'context': obj.data.get('extra', {}),
            'packages': obj.data.get('modules', {}),
            'tags': dict(obj.get_tags()),
            'platform': obj.platform,
            'dateCreated': obj.datetime,
            'timeSpent': obj.time_spent,
            'errors': errors,
        }
        return d
예제 #5
0
파일: event.py 프로젝트: zmyer/sentry
    def serialize(self, obj, attrs, user):
        errors = []
        error_set = set()
        for error in obj.data.get('errors', []):
            message = EventError.get_message(error)
            if message in error_set:
                continue
            error_set.add(message)
            error_result = {
                'type': error['type'],
                'message': message,
                'data': {
                    k: v for k, v in six.iteritems(error)
                    if k != 'type'
                },
            }
            errors.append(error_result)

        tags = sorted([
            {
                'key': k.split('sentry:', 1)[-1],
                'value': v
            } for k, v in obj.get_tags()
        ], key=lambda x: x['key'])

        received = obj.data.get('received')
        if received:
            # Sentry at one point attempted to record invalid types here.
            # Remove after June 2 2016
            try:
                received = datetime.utcfromtimestamp(received).replace(
                    tzinfo=timezone.utc,
                )
            except TypeError:
                received = None

        # TODO(dcramer): move release serialization here
        d = {
            'id': six.text_type(obj.id),
            'groupID': six.text_type(obj.group_id),
            'eventID': six.text_type(obj.event_id),
            'size': obj.size,
            'entries': attrs['entries'],
            # See GH-3248
            'message': obj.get_legacy_message(),
            'user': attrs['user'],
            'contexts': attrs['contexts'],
            'sdk': attrs['sdk'],
            # TODO(dcramer): move into contexts['extra']
            'context': obj.data.get('extra', {}),
            'packages': obj.data.get('modules', {}),
            'type': obj.get_event_type(),
            'metadata': obj.get_event_metadata(),
            'tags': tags,
            'platform': obj.platform,
            'dateCreated': obj.datetime,
            'dateReceived': received,
            'errors': errors,
        }
        return d
예제 #6
0
    def serialize(self, obj, attrs, user):
        errors = [
            EventError(error).get_api_context()
            for error in get_path(obj.data, 'errors', filter=True, default=())
        ]

        (message, message_meta) = self._get_legacy_message_with_meta(obj)
        (tags, tags_meta) = self._get_tags_with_meta(obj)
        (context, context_meta) = self._get_attr_with_meta(obj, 'extra', {})
        (packages,
         packages_meta) = self._get_attr_with_meta(obj, 'modules', {})

        received = obj.data.get('received')
        if received:
            # Sentry at one point attempted to record invalid types here.
            # Remove after June 2 2016
            try:
                received = datetime.utcfromtimestamp(received).replace(
                    tzinfo=timezone.utc, )
            except TypeError:
                received = None

        # TODO(dcramer): move release serialization here
        d = {
            'id': six.text_type(obj.id),
            'groupID': six.text_type(obj.group_id),
            'eventID': six.text_type(obj.event_id),
            'size': obj.size,
            'entries': attrs['entries'],
            'dist': obj.dist,
            # See GH-3248
            'message': message,
            'user': attrs['user'],
            'contexts': attrs['contexts'],
            'crashFile': attrs['crash_file'],
            'sdk': attrs['sdk'],
            # TODO(dcramer): move into contexts['extra']
            'context': context,
            'packages': packages,
            'type': obj.get_event_type(),
            'metadata': obj.get_event_metadata(),
            'tags': tags,
            'platform': obj.platform,
            'dateCreated': obj.datetime,
            'dateReceived': received,
            'errors': errors,
            'fingerprints': obj.get_hashes(),
            '_meta': {
                'entries': attrs['_meta']['entries'],
                'message': message_meta,
                'user': attrs['_meta']['user'],
                'contexts': attrs['_meta']['contexts'],
                'sdk': attrs['_meta']['sdk'],
                'context': context_meta,
                'packages': packages_meta,
                'tags': tags_meta,
            },
        }
        return d
예제 #7
0
def test_api_context():
    error = {'type': 'unknown_error', 'foo': 'bar'}
    assert EventError(error).get_api_context() == {
        'type': 'unknown_error',
        'message': 'Unknown error',
        'data': {
            'foo': 'bar'
        }
    }
예제 #8
0
def summarize_issues(issues: Iterable[Any]) -> Iterable[Mapping[str, str]]:
    rv = []
    for issue in issues:
        extra_info = None
        msg_d = dict(issue["data"])
        msg_d["type"] = issue["type"]

        if "image_path" in issue["data"]:
            extra_info = issue["data"]["image_path"].rsplit("/", 1)[-1]
            if "image_arch" in issue["data"]:
                extra_info = "{} ({})".format(extra_info, issue["data"]["image_arch"])

        rv.append({"message": EventError(msg_d).message, "extra_info": extra_info})
    return rv
def summarize_issues(issues):
    rv = []
    for issue in issues:
        extra_info = None
        msg_d = dict(issue['data'])
        msg_d['type'] = issue['type']

        if 'image_path' in issue['data']:
            extra_info = issue['data']['image_path'].rsplit('/', 1)[-1]
            if 'image_arch' in issue['data']:
                extra_info = '%s (%s)' % (extra_info, issue['data']['image_arch'], )

        rv.append({
            'message': EventError(msg_d).message,
            'extra_info': extra_info,
        })
    return rv
def summarize_issues(issues):
    rv = []
    for issue in issues:
        extra_info = None
        msg_d = dict(issue['data'])
        msg_d['type'] = issue['type']

        if 'image_path' in issue['data']:
            extra_info = issue['data']['image_path'].rsplit('/', 1)[-1]
            if 'image_arch' in issue['data']:
                extra_info = '%s (%s)' % (extra_info, issue['data']['image_arch'], )

        rv.append({
            'message': EventError.get_message(msg_d),
            'extra_info': extra_info,
        })
    return rv
예제 #11
0
def summarize_issues(issues):
    rv = []
    for issue in issues:
        extra_info = None
        msg_d = dict(issue["data"])
        msg_d["type"] = issue["type"]

        if "image_path" in issue["data"]:
            extra_info = issue["data"]["image_path"].rsplit("/", 1)[-1]
            if "image_arch" in issue["data"]:
                extra_info = "%s (%s)" % (extra_info,
                                          issue["data"]["image_arch"])

        rv.append({
            "message": EventError(msg_d).message,
            "extra_info": extra_info
        })
    return rv
예제 #12
0
파일: event.py 프로젝트: IthacaDream/sentry
    def serialize(self, obj, attrs, user):
        errors = []
        error_set = set()
        for error in obj.data.get('errors', []):
            message = EventError.get_message(error)
            if message in error_set:
                continue
            error_set.add(message)
            error_result = {
                'type': error['type'],
                'message': message,
                'data': {
                    k: v for k, v in error.items()
                    if k != 'type'
                },
            }
            errors.append(error_result)

        tags = sorted([
            {
                'key': k.split('sentry:', 1)[-1],
                'value': v
            } for k, v in obj.get_tags()
        ], key=lambda x: x['key'])

        # TODO(dcramer): move release serialization here
        d = {
            'id': str(obj.id),
            'groupID': obj.group.id,
            'eventID': str(obj.event_id),
            'size': obj.size,
            'entries': attrs['entries'],
            'message': obj.message,
            'user': attrs['user'],
            'context': obj.data.get('extra', {}),
            'packages': obj.data.get('modules', {}),
            'tags': tags,
            'platform': obj.platform,
            'dateCreated': obj.datetime,
            'dateReceived': obj.data.get('received', obj.datetime),
            'timeSpent': obj.time_spent,
            'errors': errors,
        }
        return d
예제 #13
0
def test_get_message(data, message):
    assert EventError.get_message(data) == message
예제 #14
0
파일: event.py 프로젝트: zhouhuiquan/sentry
    def serialize(self, obj, attrs, user):
        errors = []
        for error in obj.data.get('errors', []):
            message = EventError.get_message(error)
            error_result = {
                'type': error['type'],
                'message': message,
                'data': {k: v for k, v in six.iteritems(error) if k != 'type'},
            }
            errors.append(error_result)

        (message, message_meta) = self._get_message_with_meta(obj)
        (tags, tags_meta) = self._get_tags_with_meta(obj)
        (context, context_meta) = self._get_attr_with_meta(obj, 'extra', {})
        (packages, packages_meta) = self._get_attr_with_meta(obj, 'modules', {})

        received = obj.data.get('received')
        if received:
            # Sentry at one point attempted to record invalid types here.
            # Remove after June 2 2016
            try:
                received = datetime.utcfromtimestamp(received).replace(
                    tzinfo=timezone.utc,
                )
            except TypeError:
                received = None

        from sentry.event_manager import (
            get_hashes_from_fingerprint,
            md5_from_hash,
        )

        # TODO(dcramer): move release serialization here
        d = {
            'id': six.text_type(obj.id),
            'groupID': six.text_type(obj.group_id),
            'eventID': six.text_type(obj.event_id),
            'size': obj.size,
            'entries': attrs['entries'],
            'dist': obj.dist,
            # See GH-3248
            'message': message,
            'user': attrs['user'],
            'contexts': attrs['contexts'],
            'sdk': attrs['sdk'],
            # TODO(dcramer): move into contexts['extra']
            'context': context,
            'packages': packages,
            'type': obj.get_event_type(),
            'metadata': obj.get_event_metadata(),
            'tags': tags,
            'platform': obj.platform,
            'dateCreated': obj.datetime,
            'dateReceived': received,
            'errors': errors,
            'fingerprints': [
                md5_from_hash(h)
                for h in get_hashes_from_fingerprint(obj, obj.data.get('fingerprint', ['{{ default }}']))
            ],
            '_meta': {
                'entries': attrs['_meta']['entries'],
                'message': message_meta,
                'user': attrs['_meta']['user'],
                'contexts': attrs['_meta']['contexts'],
                'sdk': attrs['_meta']['sdk'],
                'context': context_meta,
                'packages': packages_meta,
                'tags': tags_meta,
            },
        }
        return d
예제 #15
0
def test_event_error(error, type, message, data):
    assert EventError.get_message(error) == message
    assert EventError(error).type == type
    assert EventError(error).message == message
    assert EventError(error).data == data
예제 #16
0
파일: event.py 프로젝트: nighter233/sentry
    def serialize(self, obj, attrs, user):
        errors = [
            EventError(error).get_api_context() for error
            in get_path(obj.data, 'errors', filter=True, default=())
            # TODO(ja): Temporary workaround to hide certain normalization errors.
            # Remove this and the test in tests/sentry/api/serializers/test_event.py
            if self.should_display_error(error)
        ]

        (message, message_meta) = self._get_legacy_message_with_meta(obj)
        (tags, tags_meta) = self._get_tags_with_meta(obj)
        (context, context_meta) = self._get_attr_with_meta(obj, 'extra', {})
        (packages, packages_meta) = self._get_attr_with_meta(obj, 'modules', {})

        received = obj.data.get('received')
        if received:
            # Sentry at one point attempted to record invalid types here.
            # Remove after June 2 2016
            try:
                received = datetime.utcfromtimestamp(received).replace(
                    tzinfo=timezone.utc,
                )
            except TypeError:
                received = None

        d = {
            'id': six.text_type(obj.id),
            'groupID': six.text_type(obj.group_id),
            'eventID': six.text_type(obj.event_id),
            'projectID': six.text_type(obj.project_id),
            'size': obj.size,
            'entries': attrs['entries'],
            'dist': obj.dist,
            # See GH-3248
            'message': message,
            'title': obj.title,
            'location': obj.location,
            'culprit': obj.culprit,
            'user': attrs['user'],
            'contexts': attrs['contexts'],
            'crashFile': attrs['crash_file'],
            'sdk': attrs['sdk'],
            # TODO(dcramer): move into contexts['extra']
            'context': context,
            'packages': packages,
            'type': obj.get_event_type(),
            'metadata': obj.get_event_metadata(),
            'tags': tags,
            'platform': obj.platform,
            'dateCreated': obj.datetime,
            'dateReceived': received,
            'errors': errors,
            'fingerprints': obj.get_hashes(),
            'groupingConfig': obj.get_grouping_config(),
            '_meta': {
                'entries': attrs['_meta']['entries'],
                'message': message_meta,
                'user': attrs['_meta']['user'],
                'contexts': attrs['_meta']['contexts'],
                'sdk': attrs['_meta']['sdk'],
                'context': context_meta,
                'packages': packages_meta,
                'tags': tags_meta,
            },
        }
        return d
예제 #17
0
파일: event.py 프로젝트: code-watch/sentry
    def serialize(self, obj, attrs, user):
        errors = [
            EventError(error).get_api_context()
            for error in get_path(obj.data, "errors", filter=True, default=())
            # TODO(ja): Temporary workaround to hide certain normalization errors.
            # Remove this and the test in tests/sentry/api/serializers/test_event.py
            if self.should_display_error(error)
        ]

        (message, message_meta) = self._get_legacy_message_with_meta(obj)
        (tags, tags_meta) = get_tags_with_meta(obj)
        (context, context_meta) = self._get_attr_with_meta(obj, "extra", {})
        (packages,
         packages_meta) = self._get_attr_with_meta(obj, "modules", {})

        received = obj.data.get("received")
        if received:
            # Sentry at one point attempted to record invalid types here.
            # Remove after June 2 2016
            try:
                received = datetime.utcfromtimestamp(received).replace(
                    tzinfo=timezone.utc)
            except TypeError:
                received = None

        d = {
            "id": obj.event_id,
            "groupID": str(obj.group_id) if obj.group_id else None,
            "eventID": obj.event_id,
            "projectID": str(obj.project_id),
            "size": obj.size,
            "entries": attrs["entries"],
            "dist": obj.dist,
            # See GH-3248
            "message": message,
            "title": obj.title,
            "location": obj.location,
            "user": attrs["user"],
            "contexts": attrs["contexts"],
            "sdk": attrs["sdk"],
            # TODO(dcramer): move into contexts['extra']
            "context": context,
            "packages": packages,
            "type": obj.get_event_type(),
            "metadata": obj.get_event_metadata(),
            "tags": tags,
            "platform": obj.platform,
            "dateReceived": received,
            "errors": errors,
            "_meta": {
                "entries": attrs["_meta"]["entries"],
                "message": message_meta,
                "user": attrs["_meta"]["user"],
                "contexts": attrs["_meta"]["contexts"],
                "sdk": attrs["_meta"]["sdk"],
                "context": context_meta,
                "packages": packages_meta,
                "tags": tags_meta,
            },
        }
        # Serialize attributes that are specific to different types of events.
        if obj.get_event_type() == "transaction":
            d.update(self.__serialize_transaction_attrs(attrs, obj))
        else:
            d.update(self.__serialize_error_attrs(attrs, obj))
        return d
예제 #18
0
def test_get_message(data, message):
    assert EventError.get_message(data) == message
예제 #19
0
파일: groups.py 프로젝트: gdyuldin/sentry
def render_with_group_context(group,
                              template,
                              context,
                              request=None,
                              event=None,
                              is_public=False):
    context.update({
        'team': group.project.team,
        'organization': group.project.organization,
        'project': group.project,
        'group': group,
    })

    if request and request.user.is_authenticated():
        context['ACCESS'] = access.from_user(
            user=request.user,
            organization=group.organization,
        ).to_django_context()
    else:
        context['ACCESS'] = access.DEFAULT.to_django_context()

    if event:
        if event.id:
            # HACK(dcramer): work around lack of unique sorting on datetime
            base_qs = Event.objects.filter(
                group=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
        else:
            next_event = None
            prev_event = None

        if not is_public:
            extra_data = event.data.get('extra', {})
            if not isinstance(extra_data, dict):
                extra_data = {}

            errors = []
            error_set = set()
            for error in event.data.get('errors', []):
                error_data = json.dumps(
                    {k: v
                     for k, v in error.iteritems() if k != 'type'})
                if error_data == '{}':
                    error_data = None

                error_hash = (error['type'], error_data)
                if error_hash in error_set:
                    continue
                error_set.add(error_hash)
                error_result = {
                    'type': error['type'],
                    'title': EventError.get_title(error['type']),
                    'data': error_data,
                }
                errors.append(error_result)

            context.update({
                'tags': event.get_tags(),
                'json_data': extra_data,
                'errors': errors,
            })

        context.update({
            'event': event,
            'version_data': event.data.get('modules', None),
            'next_event': next_event,
            'prev_event': prev_event,
        })

    return render_to_response(template, context, request)
예제 #20
0
파일: event.py 프로젝트: mjumbewu/sentry
    def serialize(self, obj, attrs, user):
        errors = []
        for error in obj.data.get('errors', []):
            message = EventError.get_message(error)
            error_result = {
                'type': error['type'],
                'message': message,
                'data': {k: v for k, v in six.iteritems(error) if k != 'type'},
            }
            errors.append(error_result)

        (message, message_meta) = self._get_message_with_meta(obj)
        (tags, tags_meta) = self._get_tags_with_meta(obj)
        (context, context_meta) = self._get_attr_with_meta(obj, 'extra', {})
        (packages, packages_meta) = self._get_attr_with_meta(obj, 'modules', {})

        received = obj.data.get('received')
        if received:
            # Sentry at one point attempted to record invalid types here.
            # Remove after June 2 2016
            try:
                received = datetime.utcfromtimestamp(received).replace(
                    tzinfo=timezone.utc,
                )
            except TypeError:
                received = None

        from sentry.event_manager import (
            get_hashes_from_fingerprint,
            md5_from_hash,
        )

        # TODO(dcramer): move release serialization here
        d = {
            'id': six.text_type(obj.id),
            'groupID': six.text_type(obj.group_id),
            'eventID': six.text_type(obj.event_id),
            'size': obj.size,
            'entries': attrs['entries'],
            'dist': obj.dist,
            # See GH-3248
            'message': message,
            'user': attrs['user'],
            'contexts': attrs['contexts'],
            'sdk': attrs['sdk'],
            # TODO(dcramer): move into contexts['extra']
            'context': context,
            'packages': packages,
            'type': obj.get_event_type(),
            'metadata': obj.get_event_metadata(),
            'tags': tags,
            'platform': obj.platform,
            'dateCreated': obj.datetime,
            'dateReceived': received,
            'errors': errors,
            'fingerprints': [
                md5_from_hash(h)
                for h in get_hashes_from_fingerprint(obj, obj.data.get('fingerprint', ['{{ default }}']))
            ],
            '_meta': {
                'entries': attrs['_meta']['entries'],
                'message': message_meta,
                'user': attrs['_meta']['user'],
                'contexts': attrs['_meta']['contexts'],
                'sdk': attrs['_meta']['sdk'],
                'context': context_meta,
                'packages': packages_meta,
                'tags': tags_meta,
            },
        }
        return d
예제 #21
0
def test_event_error(error, type, message, data):
    assert EventError.get_message(error) == message
    assert EventError(error).type == type
    assert EventError(error).message == message
    assert EventError(error).data == data
예제 #22
0
파일: groups.py 프로젝트: GpadillaQ/sentry
def render_with_group_context(group, template, context, request=None,
                              event=None, is_public=False):
    context.update({
        'team': group.project.team,
        'organization': group.project.organization,
        'project': group.project,
        'group': group,
    })

    if request and request.user.is_authenticated():
        context['ACCESS'] = access.from_user(
            user=request.user,
            organization=group.organization,
        ).to_django_context()
    else:
        context['ACCESS'] = access.DEFAULT.to_django_context()

    if event:
        if event.id:
            # HACK(dcramer): work around lack of unique sorting on datetime
            base_qs = Event.objects.filter(
                group=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
        else:
            next_event = None
            prev_event = None

        if not is_public:
            extra_data = event.data.get('extra', {})
            if not isinstance(extra_data, dict):
                extra_data = {}

            errors = []
            error_set = set()
            for error in event.data.get('errors', []):
                error_data = json.dumps({
                    k: v for k, v in error.iteritems()
                    if k != 'type'
                })
                if error_data == '{}':
                    error_data = None

                error_hash = (error['type'], error_data)
                if error_hash in error_set:
                    continue
                error_set.add(error_hash)
                error_result = {
                    'type': error['type'],
                    'title': EventError.get_title(error['type']),
                    'data': error_data,
                }
                errors.append(error_result)

            context.update({
                'tags': event.get_tags(),
                'json_data': extra_data,
                'errors': errors,
            })

        context.update({
            'event': event,
            'version_data': event.data.get('modules', None),
            'next_event': next_event,
            'prev_event': prev_event,
        })

    return render_to_response(template, context, request)