Пример #1
0
    def _get_entries(self, event, user, is_public=False):
        # XXX(dcramer): These are called entries for future-proofing

        meta = event.data.get('_meta') or {}
        interface_list = []

        for key, interface in six.iteritems(event.interfaces):
            # we treat user as a special contextual item
            if key in self._reserved_keys:
                continue

            data = interface.get_api_context(is_public=is_public)
            # data might not be returned for e.g. a public HTTP repr
            if not data:
                continue

            entry = {
                'data': data,
                'type': interface.get_alias(),
            }

            api_meta = None
            if meta.get(key):
                api_meta = interface.get_api_meta(meta[key], is_public=is_public)
                api_meta = meta_with_chunks(data, api_meta)

            interface_list.append((interface, entry, api_meta))

        interface_list.sort(
            key=lambda x: x[0].get_display_score(), reverse=True)

        return (
            [i[1] for i in interface_list],
            {k: {'data': i[2]} for k, i in enumerate(interface_list) if i[2]}
        )
Пример #2
0
    def _get_tags_with_meta(self, event):
        meta = get_path(event.data, '_meta', 'tags') or {}

        tags = sorted(
            [
                {
                    'key': kv[0].split('sentry:', 1)[-1],
                    'value': kv[1],
                    '_meta': meta.get(kv[0]) or get_path(meta, six.text_type(i), '1') or None,
                }
                # TODO this should be using event.tags but there are some weird
                # issues around that because event.tags re-sorts the tags and
                # this function relies on them being in the original order to
                # look up meta.
                for i, kv in enumerate(event.data.get('tags') or ())
                if kv is not None and kv[0] is not None and kv[1] is not None],
            key=lambda x: x['key']
        )

        # Add 'query' for each tag to tell the UI what to use as query
        # params for this tag.
        for tag in tags:
            query = convert_user_tag_to_query(tag['key'], tag['value'])
            if query:
                tag['query'] = query

        tags_meta = {
            six.text_type(i): {'value': e.pop('_meta')}
            for i, e in enumerate(tags) if e.get('_meta')
        }

        return (tags, meta_with_chunks(tags, tags_meta))
Пример #3
0
    def _get_entries(self, event, user, is_public=False):
        # XXX(dcramer): These are called entries for future-proofing

        platform = event.platform
        meta = event.data.get("_meta") or {}
        interface_list = []

        for key, interface in six.iteritems(event.interfaces):
            # we treat user as a special contextual item
            if key in self._reserved_keys:
                continue

            data = interface.get_api_context(is_public=is_public, platform=platform)
            # data might not be returned for e.g. a public HTTP repr
            # However, spans can be an empty list and should still be included.
            if not data and interface.path != "spans":
                continue

            entry = {"data": data, "type": interface.external_type}

            api_meta = None
            if meta.get(key):
                api_meta = interface.get_api_meta(meta[key], is_public=is_public, platform=platform)
                api_meta = meta_with_chunks(data, api_meta)

            interface_list.append((interface, entry, api_meta))

        interface_list.sort(key=lambda x: x[0].get_display_score(), reverse=True)

        return (
            [i[1] for i in interface_list],
            {k: {"data": i[2]} for k, i in enumerate(interface_list) if i[2]},
        )
Пример #4
0
    def _get_entries(self, event, user, is_public=False):
        # XXX(dcramer): These are called entries for future-proofing

        meta = event.data.get('_meta') or {}
        interface_list = []

        for key, interface in six.iteritems(event.interfaces):
            # we treat user as a special contextual item
            if key in self._reserved_keys:
                continue

            data = interface.get_api_context(is_public=is_public)
            # data might not be returned for e.g. a public HTTP repr
            if not data:
                continue

            entry = {
                'data': data,
                'type': interface.get_alias(),
            }

            api_meta = None
            if meta.get(key):
                api_meta = interface.get_api_meta(meta[key], is_public=is_public)
                api_meta = meta_with_chunks(data, api_meta)

            interface_list.append((interface, entry, api_meta))

        interface_list.sort(
            key=lambda x: x[0].get_display_score(), reverse=True)

        return (
            [i[1] for i in interface_list],
            {k: {'data': i[2]} for k, i in enumerate(interface_list) if i[2]}
        )
Пример #5
0
    def _get_message_with_meta(self, event):
        meta = event.data.get('_meta') or {}

        if 'logentry' not in event.data:
            message = event.message
            msg_meta = meta.get('message')
        elif 'formatted' in event.data['logentry']:
            message = event.data['logentry']['formatted']
            msg_meta = meta.get('logentry', {}).get('formatted')
        else:
            message = event.data['logentry']['message']
            msg_meta = meta.get('logentry', {}).get('message')

        return (message, meta_with_chunks(message, msg_meta))
Пример #6
0
    def _get_message_with_meta(self, event):
        meta = event.data.get('_meta') or {}

        if 'logentry' not in event.data:
            message = event.message
            msg_meta = meta.get('message')
        elif 'formatted' in event.data['logentry']:
            message = event.data['logentry']['formatted']
            msg_meta = meta.get('logentry', {}).get('formatted')
        else:
            message = event.data['logentry']['message']
            msg_meta = meta.get('logentry', {}).get('message')

        return (message, meta_with_chunks(message, msg_meta))
Пример #7
0
    def _get_legacy_message_with_meta(self, event):
        meta = event.data.get('_meta')

        message = get_path(event.data, 'logentry', 'formatted')
        msg_meta = get_path(meta, 'logentry', 'formatted')

        if not message:
            message = get_path(event.data, 'logentry', 'message')
            msg_meta = get_path(meta, 'logentry', 'message')

        if not message:
            message = event.message
            msg_meta = None

        return (message, meta_with_chunks(message, msg_meta))
    def _get_legacy_message_with_meta(self, event):
        meta = event.data.get('_meta')

        message = get_path(event.data, 'logentry', 'formatted')
        msg_meta = get_path(meta, 'logentry', 'formatted')

        if not message:
            message = get_path(event.data, 'logentry', 'message')
            msg_meta = get_path(meta, 'logentry', 'message')

        if not message:
            message = event.message
            msg_meta = None

        return (message, meta_with_chunks(message, msg_meta))
Пример #9
0
    def _get_legacy_message_with_meta(self, event):
        meta = event.data.get("_meta")

        message = get_path(event.data, "logentry", "formatted")
        msg_meta = get_path(meta, "logentry", "formatted")

        if not message:
            message = get_path(event.data, "logentry", "message")
            msg_meta = get_path(meta, "logentry", "message")

        if not message:
            message = event.message
            msg_meta = None

        return (message, meta_with_chunks(message, msg_meta))
Пример #10
0
    def _get_interface_with_meta(self, event, name, is_public=False):
        interface = event.interfaces.get(name)
        if not interface:
            return (None, None)

        data = interface.get_api_context(is_public=is_public)
        event_meta = event.data.get('_meta') or {}
        if not data or not event_meta.get(name):
            return (data, None)

        api_meta = interface.get_api_meta(event_meta[name], is_public=is_public)
        # data might not be returned for e.g. a public HTTP repr
        if not api_meta:
            return (data, None)

        return (data, meta_with_chunks(data, api_meta))
Пример #11
0
    def _get_interface_with_meta(self, event, name, is_public=False):
        interface = event.interfaces.get(name)
        if not interface:
            return (None, None)

        data = interface.get_api_context(is_public=is_public)
        event_meta = event.data.get('_meta') or {}
        if not data or not event_meta.get(name):
            return (data, None)

        api_meta = interface.get_api_meta(event_meta[name], is_public=is_public)
        # data might not be returned for e.g. a public HTTP repr
        if not api_meta:
            return (data, None)

        return (data, meta_with_chunks(data, api_meta))
Пример #12
0
    def _get_tags_with_meta(self, event):
        meta = (event.data.get('_meta') or {}).get('tags') or {}

        tags = sorted(
            [{
                'key': k.split('sentry:', 1)[-1],
                'value': v,
                '_meta': meta.get(k) or meta.get(six.text_type(i), {}).get('1') or None,
            } for i, (k, v) in enumerate(event.data.get('tags') or ())],
            key=lambda x: x['key']
        )

        tags_meta = {
            six.text_type(i): {'value': e.pop('_meta')}
            for i, e in enumerate(tags) if e.get('_meta')
        }

        return (tags, meta_with_chunks(tags, tags_meta))
Пример #13
0
    def _get_tags_with_meta(self, event):
        meta = (event.data.get('_meta') or {}).get('tags') or {}

        tags = sorted(
            [{
                'key': k.split('sentry:', 1)[-1],
                'value': v,
                '_meta': meta.get(k) or meta.get(six.text_type(i), {}).get('1') or None,
            } for i, (k, v) in enumerate(event.data.get('tags') or ())],
            key=lambda x: x['key']
        )

        tags_meta = {
            six.text_type(i): {'value': e.pop('_meta')}
            for i, e in enumerate(tags) if e.get('_meta')
        }

        return (tags, meta_with_chunks(tags, tags_meta))
Пример #14
0
    def _get_tags_with_meta(self, event):
        meta = get_path(event.data, '_meta', 'tags') or {}

        tags = sorted(
            [
                {
                    'key': kv[0].split('sentry:', 1)[-1],
                    'value': kv[1],
                    '_meta': meta.get(kv[0]) or get_path(meta, six.text_type(i), '1') or None,
                }
                for i, kv in enumerate(event.data.get('tags') or ())
                if kv is not None and kv[0] is not None and kv[1] is not None],
            key=lambda x: x['key']
        )

        tags_meta = {
            six.text_type(i): {'value': e.pop('_meta')}
            for i, e in enumerate(tags) if e.get('_meta')
        }

        return (tags, meta_with_chunks(tags, tags_meta))
Пример #15
0
    def _get_tags_with_meta(self, event):
        meta = get_path(event.data, "_meta", "tags") or {}

        # If we have meta, we need to get the tags in their original order
        # from the raw event body as the indexes need to line up with the
        # metadata indexes. In other cases we can use event.tags
        if meta:
            raw_tags = event.data.get("tags") or []
        else:
            raw_tags = event.tags

        tags = sorted(
            [{
                "key":
                kv[0].split("sentry:", 1)[-1],
                "value":
                kv[1],
                "_meta":
                meta.get(kv[0]) or get_path(meta, six.text_type(i), "1")
                or None,
            } for i, kv in enumerate(raw_tags)
             if kv is not None and kv[0] is not None and kv[1] is not None],
            key=lambda x: x["key"],
        )

        # Add 'query' for each tag to tell the UI what to use as query
        # params for this tag.
        for tag in tags:
            query = convert_user_tag_to_query(tag["key"], tag["value"])
            if query:
                tag["query"] = query

        tags_meta = {
            six.text_type(i): {
                "value": e.pop("_meta")
            }
            for i, e in enumerate(tags) if e.get("_meta")
        }

        return (tags, meta_with_chunks(tags, tags_meta))
Пример #16
0
    def _get_tags_with_meta(self, event):
        meta = get_path(event.data, '_meta', 'tags') or {}

        # If we have meta, we need to get the tags in their original order
        # from the raw event body as the indexes need to line up with the
        # metadata indexes. In other cases we can use event.tags
        if meta:
            raw_tags = event.data.get('tags') or []
        else:
            raw_tags = event.tags

        tags = sorted(
            [
                {
                    'key': kv[0].split('sentry:', 1)[-1],
                    'value': kv[1],
                    '_meta': meta.get(kv[0]) or get_path(meta, six.text_type(i), '1') or None,
                }
                for i, kv in enumerate(raw_tags)
                if kv is not None and kv[0] is not None and kv[1] is not None],
            key=lambda x: x['key']
        )

        # Add 'query' for each tag to tell the UI what to use as query
        # params for this tag.
        for tag in tags:
            query = convert_user_tag_to_query(tag['key'], tag['value'])
            if query:
                tag['query'] = query

        tags_meta = {
            six.text_type(i): {'value': e.pop('_meta')}
            for i, e in enumerate(tags) if e.get('_meta')
        }

        return (tags, meta_with_chunks(tags, tags_meta))
Пример #17
0
 def _get_attr_with_meta(self, event, attr, default=None):
     value = event.data.get(attr, default)
     meta = (event.data.get('_meta') or {}).get(attr)
     return (value, meta_with_chunks(value, meta))
Пример #18
0
def test_meta_with_chunks_empty_remarks():
    meta = semaphore.meta_with_chunks(TEXT, {"rem": []})
    assert meta == {"rem": []}
Пример #19
0
def test_meta_with_chunks_dict():
    meta = semaphore.meta_with_chunks({
        "test": TEXT,
        "other": 1
    }, {"test": META})
    assert meta == {"test": META_WITH_CHUNKS}
Пример #20
0
def test_meta_with_chunks_list():
    meta = semaphore.meta_with_chunks(["other", TEXT], {"1": META})
    assert meta == {"1": META_WITH_CHUNKS}
Пример #21
0
def test_meta_with_chunks_empty():
    meta = semaphore.meta_with_chunks(TEXT, {})
    assert meta == {}
Пример #22
0
 def _get_attr_with_meta(self, event, attr, default=None):
     value = event.data.get(attr, default)
     meta = (event.data.get('_meta') or {}).get(attr)
     return (value, meta_with_chunks(value, meta))
Пример #23
0
def test_meta_with_chunks():
    meta = semaphore.meta_with_chunks(TEXT, META)
    assert meta == META_WITH_CHUNKS
Пример #24
0
def test_meta_with_chunks_missing_value():
    meta = semaphore.meta_with_chunks(None, META)
    assert meta == META
Пример #25
0
def test_meta_with_chunks_missing_non_string():
    meta = semaphore.meta_with_chunks(True, META)
    assert meta == META
Пример #26
0
def test_meta_with_chunks_list():
    meta = semaphore.meta_with_chunks(["other", TEXT], {"1": META})
    assert meta == {"1": META_WITH_CHUNKS}
Пример #27
0
def test_meta_with_chunks():
    meta = semaphore.meta_with_chunks(TEXT, META)
    assert meta == META_WITH_CHUNKS
Пример #28
0
def test_meta_with_chunks_empty_remarks():
    meta = semaphore.meta_with_chunks(TEXT, {"rem": []})
    assert meta == {"rem": []}
Пример #29
0
def test_meta_with_chunks_empty():
    meta = semaphore.meta_with_chunks(TEXT, {})
    assert meta == {}
Пример #30
0
 def _get_attr_with_meta(self, event, attr, default=None):
     value = event.data.get(attr, default)
     meta = get_path(event.data, '_meta', attr)
     return (value, meta_with_chunks(value, meta))
Пример #31
0
def test_meta_with_chunks_none():
    meta = semaphore.meta_with_chunks(TEXT, None)
    assert meta is None
Пример #32
0
def test_meta_with_chunks_missing_non_string():
    meta = semaphore.meta_with_chunks(True, META)
    assert meta == META
Пример #33
0
 def _get_attr_with_meta(self, event, attr, default=None):
     value = event.data.get(attr, default)
     meta = get_path(event.data, "_meta", attr)
     return (value, meta_with_chunks(value, meta))
Пример #34
0
def test_meta_with_chunks_missing_value():
    meta = semaphore.meta_with_chunks(None, META)
    assert meta == META
Пример #35
0
def test_meta_with_chunks_dict():
    meta = semaphore.meta_with_chunks({"test": TEXT, "other": 1}, {"test": META})
    assert meta == {"test": META_WITH_CHUNKS}
Пример #36
0
def test_meta_with_chunks_none():
    meta = semaphore.meta_with_chunks(TEXT, None)
    assert meta is None