def test_truncation(self):
        data = {
            'sentry.interfaces.Exception': {
                'values': [{
                    'stacktrace': {
                        'frames': [{
                            'filename': 'x' * (MAX_CULPRIT_LENGTH + 1),
                        }],
                    }
                }],
            }
        }
        assert len(generate_culprit(data)) == MAX_CULPRIT_LENGTH

        data = {
            'sentry.interfaces.Stacktrace': {
                'frames': [{
                    'filename': 'x' * (MAX_CULPRIT_LENGTH + 1),
                }]
            }
        }
        assert len(generate_culprit(data)) == MAX_CULPRIT_LENGTH

        data = {
            'sentry.interfaces.Http': {
                'url': 'x' * (MAX_CULPRIT_LENGTH + 1),
            }
        }
        assert len(generate_culprit(data)) == MAX_CULPRIT_LENGTH
Beispiel #2
0
def test_truncation():
    data = {
        "exception": {
            "values": [{
                "stacktrace": {
                    "frames": [{
                        "filename": "x" * (MAX_CULPRIT_LENGTH + 1)
                    }]
                }
            }]
        }
    }
    assert len(generate_culprit(data)) == MAX_CULPRIT_LENGTH

    data = {
        "stacktrace": {
            "frames": [{
                "filename": "x" * (MAX_CULPRIT_LENGTH + 1)
            }]
        }
    }
    assert len(generate_culprit(data)) == MAX_CULPRIT_LENGTH

    data = {"request": {"url": "x" * (MAX_CULPRIT_LENGTH + 1)}}
    assert len(generate_culprit(data)) == MAX_CULPRIT_LENGTH
def test_truncation():
    data = {
        'exception': {
            'values':
            [{
                'stacktrace': {
                    'frames': [{
                        'filename': 'x' * (MAX_CULPRIT_LENGTH + 1),
                    }],
                }
            }],
        }
    }
    assert len(generate_culprit(data)) == MAX_CULPRIT_LENGTH

    data = {
        'stacktrace': {
            'frames': [{
                'filename': 'x' * (MAX_CULPRIT_LENGTH + 1),
            }]
        }
    }
    assert len(generate_culprit(data)) == MAX_CULPRIT_LENGTH

    data = {
        'request': {
            'url': 'x' * (MAX_CULPRIT_LENGTH + 1),
        }
    }
    assert len(generate_culprit(data)) == MAX_CULPRIT_LENGTH
Beispiel #4
0
def test_truncation():
    data = {
        'exception': {
            'values':
            [{
                'stacktrace': {
                    'frames': [{
                        'filename': 'x' * (MAX_CULPRIT_LENGTH + 1),
                    }],
                }
            }],
        }
    }
    assert len(generate_culprit(data)) == MAX_CULPRIT_LENGTH

    data = {
        'stacktrace': {
            'frames': [{
                'filename': 'x' * (MAX_CULPRIT_LENGTH + 1),
            }]
        }
    }
    assert len(generate_culprit(data)) == MAX_CULPRIT_LENGTH

    data = {
        'request': {
            'url': 'x' * (MAX_CULPRIT_LENGTH + 1),
        }
    }
    assert len(generate_culprit(data)) == MAX_CULPRIT_LENGTH
Beispiel #5
0
    def test_truncation(self):
        data = {
            'sentry.interfaces.Exception': {
                'values':
                [{
                    'stacktrace': {
                        'frames': [{
                            'filename': 'x' * (MAX_CULPRIT_LENGTH + 1),
                        }],
                    }
                }],
            }
        }
        assert len(generate_culprit(data)) == MAX_CULPRIT_LENGTH

        data = {
            'sentry.interfaces.Stacktrace': {
                'frames': [{
                    'filename': 'x' * (MAX_CULPRIT_LENGTH + 1),
                }]
            }
        }
        assert len(generate_culprit(data)) == MAX_CULPRIT_LENGTH

        data = {
            'sentry.interfaces.Http': {
                'url': 'x' * (MAX_CULPRIT_LENGTH + 1),
            }
        }
        assert len(generate_culprit(data)) == MAX_CULPRIT_LENGTH
    def test_with_only_http_interface(self):
        data = {
            'sentry.interfaces.Http': {
                'url': 'http://example.com'
            },
        }
        assert generate_culprit(data) == 'http://example.com'

        data = {
            'sentry.interfaces.Http': {},
        }
        assert generate_culprit(data) == ''
Beispiel #7
0
def test_with_only_http_interface():
    data = {
        'request': {
            'url': 'http://example.com'
        },
    }
    assert generate_culprit(data) == 'http://example.com'

    data = {
        'request': {},
    }
    assert generate_culprit(data) == ''
Beispiel #8
0
def test_with_only_http_interface():
    data = {"request": {"url": "http://example.com"}}
    assert generate_culprit(data) == "http://example.com"

    data = {"request": {"url": None}}
    assert generate_culprit(data) == ""

    data = {"request": {}}
    assert generate_culprit(data) == ""

    data = {"request": None}
    assert generate_culprit(data) == ""
Beispiel #9
0
    def test_with_only_http_interface(self):
        data = {
            'sentry.interfaces.Http': {
                'url': 'http://example.com'
            },
        }
        assert generate_culprit(data) == 'http://example.com'

        data = {
            'sentry.interfaces.Http': {},
        }
        assert generate_culprit(data) == ''
Beispiel #10
0
    def test_truncation(self):
        data = {
            "sentry.interfaces.Exception": {
                "values": [{"stacktrace": {"frames": [{"filename": "x" * (MAX_CULPRIT_LENGTH + 1)}]}}]
            }
        }
        assert len(generate_culprit(data)) == MAX_CULPRIT_LENGTH

        data = {"sentry.interfaces.Stacktrace": {"frames": [{"filename": "x" * (MAX_CULPRIT_LENGTH + 1)}]}}
        assert len(generate_culprit(data)) == MAX_CULPRIT_LENGTH

        data = {"sentry.interfaces.Http": {"url": "x" * (MAX_CULPRIT_LENGTH + 1)}}
        assert len(generate_culprit(data)) == MAX_CULPRIT_LENGTH
 def test_with_exception_interface(self):
     data = {
         'sentry.interfaces.Exception': {
             'values': [{
                 'stacktrace': {
                     'frames': [{
                         'lineno': 1,
                         'filename': 'foo.py',
                     }, {
                         'lineno': 1,
                         'filename': 'bar.py',
                         'in_app': True,
                     }],
                 }
             }]
         },
         'sentry.interfaces.Stacktrace': {
             'frames': [{
                 'lineno': 1,
                 'filename': 'NOTME.py',
             }, {
                 'lineno': 1,
                 'filename': 'PLZNOTME.py',
                 'in_app': True,
             }],
         },
         'sentry.interfaces.Http': {
             'url': 'http://example.com'
         },
     }
     assert generate_culprit(data) == 'bar.py in ?'
Beispiel #12
0
 def test_with_exception_interface(self):
     data = {
         'sentry.interfaces.Exception': {
             'values': [{
                 'stacktrace': {
                     'frames': [{
                         'lineno': 1,
                         'filename': 'foo.py',
                     }, {
                         'lineno': 1,
                         'filename': 'bar.py',
                         'in_app': True,
                     }],
                 }
             }]
         },
         'sentry.interfaces.Stacktrace': {
             'frames': [{
                 'lineno': 1,
                 'filename': 'NOTME.py',
             }, {
                 'lineno': 1,
                 'filename': 'PLZNOTME.py',
                 'in_app': True,
             }],
         },
         'sentry.interfaces.Http': {
             'url': 'http://example.com'
         },
     }
     assert generate_culprit(data) == 'bar.py in ?'
def fix_culprit(data):
    exc = data.get('sentry.interfaces.Exception')
    if not exc:
        return

    from sentry.event_manager import generate_culprit
    data['culprit'] = generate_culprit(data)
Beispiel #14
0
def fix_culprit(data):
    exc = data.get('sentry.interfaces.Exception')
    if not exc:
        return

    from sentry.event_manager import generate_culprit
    data['culprit'] = generate_culprit(data)
Beispiel #15
0
def test_with_empty_stacktrace():
    data = {
        'stacktrace': None,
        'request': {
            'url': 'http://example.com'
        },
    }
    assert generate_culprit(data) == 'http://example.com'
def test_with_empty_stacktrace():
    data = {
        'stacktrace': None,
        'request': {
            'url': 'http://example.com'
        },
    }
    assert generate_culprit(data) == 'http://example.com'
 def test_with_empty_stacktrace(self):
     data = {
         'sentry.interfaces.Stacktrace': None,
         'sentry.interfaces.Http': {
             'url': 'http://example.com'
         },
     }
     assert generate_culprit(data) == 'http://example.com'
Beispiel #18
0
 def test_with_empty_stacktrace(self):
     data = {
         'sentry.interfaces.Stacktrace': None,
         'sentry.interfaces.Http': {
             'url': 'http://example.com'
         },
     }
     assert generate_culprit(data) == 'http://example.com'
Beispiel #19
0
def _generate_culprit(event):
    # XXX(mitsuhiko): workaround: some old events do not have this data yet.
    # This should be save delete by end of 2019 even considering slow on-prem
    # releases.  Platform was added back to data in december 2018.
    data = event.data
    if data.get("platform") is None:
        data = dict(data.items())
        data["platform"] = event.platform
    return generate_culprit(data)
Beispiel #20
0
def _generate_culprit(event):
    # XXX(mitsuhiko): workaround: some old events do not have this data yet.
    # This should be save delete by end of 2019 even considering slow on-prem
    # releases.  Platform was added back to data in december 2018.
    data = event.data
    if data.get('platform') is None:
        data = dict(data.items())
        data['platform'] = event.platform
    return generate_culprit(data)
Beispiel #21
0
def test_with_missing_stacktrace_frames():
    data = {
        "stacktrace": {
            "frames": None
        },
        "request": {
            "url": "http://example.com"
        }
    }
    assert generate_culprit(data) == "http://example.com"
def test_with_missing_stacktrace_frames():
    data = {
        'stacktrace': {
            'frames': None,
        },
        'request': {
            'url': 'http://example.com'
        },
    }
    assert generate_culprit(data) == 'http://example.com'
def test_with_missing_stacktrace_frames():
    data = {
        'stacktrace': {
            'frames': None,
        },
        'request': {
            'url': 'http://example.com'
        },
    }
    assert generate_culprit(data) == 'http://example.com'
Beispiel #24
0
def test_with_stacktrace_interface():
    data = {
        "stacktrace": {
            "frames": [
                {"lineno": 1, "filename": "NOTME.py"},
                {"lineno": 1, "filename": "PLZNOTME.py", "in_app": True},
            ]
        },
        "request": {"url": "http://example.com"},
    }
    assert generate_culprit(data) == "PLZNOTME.py in ?"
Beispiel #25
0
 def test_with_missing_exception_interface(self):
     data = {
         "sentry.interfaces.Stacktrace": {
             "frames": [
                 {"lineno": 1, "filename": "NOTME.py"},
                 {"lineno": 1, "filename": "PLZNOTME.py", "in_app": True},
             ]
         },
         "sentry.interfaces.Http": {"url": "http://example.com"},
     }
     assert generate_culprit(data) == "PLZNOTME.py in ?"
Beispiel #26
0
def test_with_missing_exception_stacktrace():
    data = {
        "exception": {
            "values": [
                {"stacktrace": None},
                {"stacktrace": {"frames": None}},
                {"stacktrace": {"frames": [None]}},
            ]
        },
        "request": {"url": "http://example.com"},
    }
    assert generate_culprit(data) == "http://example.com"
def test_with_only_http_interface():
    data = {
        'request': {
            'url': 'http://example.com'
        },
    }
    assert generate_culprit(data) == 'http://example.com'

    data = {
        'request': {
            'url': None
        },
    }
    assert generate_culprit(data) == ''

    data = {
        'request': {},
    }
    assert generate_culprit(data) == ''

    data = {
        'request': None,
    }
    assert generate_culprit(data) == ''
Beispiel #28
0
def _rehash_group_events(group, limit=100):
    from sentry.event_manager import (EventManager,
                                      get_hashes_from_fingerprint,
                                      generate_culprit, md5_from_hash)
    from sentry.models import Event, Group

    environment_cache = {}
    project = group.project
    event_list = list(Event.objects.filter(group_id=group.id)[:limit])
    Event.objects.bind_nodes(event_list, 'data')

    for event in event_list:
        fingerprint = event.data.get('fingerprint', ['{{ default }}'])
        if fingerprint and not isinstance(fingerprint, (list, tuple)):
            fingerprint = [fingerprint]
        elif not fingerprint:
            fingerprint = ['{{ default }}']

        manager = EventManager({})

        group_kwargs = {
            'message': event.message,
            'platform': event.platform,
            'culprit': generate_culprit(event.data),
            'logger': event.get_tag('logger') or group.logger,
            'level': group.level,
            'last_seen': event.datetime,
            'first_seen': event.datetime,
            'data': group.data,
        }

        # XXX(dcramer): doesnt support checksums as they're not stored
        hashes = map(md5_from_hash,
                     get_hashes_from_fingerprint(event, fingerprint))
        for hash in hashes:
            new_group, _, _, _ = manager._save_aggregate(event=event,
                                                         hashes=hashes,
                                                         release=None,
                                                         **group_kwargs)
            event.update(group_id=new_group.id)
            if event.data.get('tags'):
                Group.objects.add_tags(
                    new_group,
                    _get_event_environment(event, project, environment_cache),
                    event.data['tags'])

    return bool(event_list)
def test_with_stacktrace_interface():
    data = {
        'stacktrace': {
            'frames': [{
                'lineno': 1,
                'filename': 'NOTME.py',
            }, {
                'lineno': 1,
                'filename': 'PLZNOTME.py',
                'in_app': True,
            }],
        },
        'request': {
            'url': 'http://example.com'
        },
    }
    assert generate_culprit(data) == 'PLZNOTME.py in ?'
Beispiel #30
0
def _rehash_group_events(group, limit=100):
    from sentry.event_manager import (
        EventManager, get_hashes_from_fingerprint, generate_culprit, md5_from_hash
    )
    from sentry.models import Event, Group

    environment_cache = {}
    project = group.project
    event_list = list(Event.objects.filter(group_id=group.id)[:limit])
    Event.objects.bind_nodes(event_list, 'data')

    for event in event_list:
        fingerprint = event.data.get('fingerprint', ['{{ default }}'])
        if fingerprint and not isinstance(fingerprint, (list, tuple)):
            fingerprint = [fingerprint]
        elif not fingerprint:
            fingerprint = ['{{ default }}']

        manager = EventManager({})

        group_kwargs = {
            'message': event.message,
            'platform': event.platform,
            'culprit': generate_culprit(event.data),
            'logger': event.get_tag('logger') or group.logger,
            'level': group.level,
            'last_seen': event.datetime,
            'first_seen': event.datetime,
            'data': group.data,
        }

        # XXX(dcramer): doesnt support checksums as they're not stored
        hashes = map(md5_from_hash, get_hashes_from_fingerprint(event, fingerprint))
        for hash in hashes:
            new_group, _, _, _ = manager._save_aggregate(
                event=event, hashes=hashes, release=None, **group_kwargs
            )
            event.update(group_id=new_group.id)
            if event.data.get('tags'):
                Group.objects.add_tags(
                    new_group,
                    _get_event_environment(event, project, environment_cache),
                    event.data['tags'])

    return bool(event_list)
def test_with_stacktrace_interface():
    data = {
        'stacktrace': {
            'frames': [
                {
                    'lineno': 1,
                    'filename': 'NOTME.py',
                }, {
                    'lineno': 1,
                    'filename': 'PLZNOTME.py',
                    'in_app': True,
                }
            ],
        },
        'request': {
            'url': 'http://example.com'
        },
    }
    assert generate_culprit(data) == 'PLZNOTME.py in ?'
def test_with_missing_exception_stacktrace():
    data = {
        'exception': {
            'values': [
                {
                    'stacktrace': None,
                },
                {
                    'stacktrace': {
                        'frames': None,
                    }
                },
                {
                    'stacktrace': {
                        'frames': [None],
                    }
                },
            ]
        },
        'request': {
            'url': 'http://example.com'
        },
    }
    assert generate_culprit(data) == 'http://example.com'
def test_with_missing_exception_stacktrace():
    data = {
        'exception': {
            'values': [
                {
                    'stacktrace': None,
                },
                {
                    'stacktrace': {
                        'frames': None,
                    }
                },
                {
                    'stacktrace': {
                        'frames': [None],
                    }
                },
            ]
        },
        'request': {
            'url': 'http://example.com'
        },
    }
    assert generate_culprit(data) == 'http://example.com'
 def test_empty_data(self):
     assert generate_culprit({}) == ''
Beispiel #35
0
                version=version,
            ),
        ),
    }


def merge_mappings(values):
    result = {}
    for value in values:
        result.update(value)
    return result


initial_fields = {
    'culprit': lambda event: generate_culprit(
        event.data,
        event.platform,
    ),
    'data': lambda event: {
        'last_received': event.data.get('received') or float(event.datetime.strftime('%s')),
        'type': event.data['type'],
        'metadata': event.data['metadata'],
    },
    'last_seen': lambda event: event.datetime,
    'level': lambda event: LOG_LEVELS_MAP.get(
        event.get_tag('level'),
        logging.ERROR,
    ),
    'message': lambda event: event.message,
    'times_seen': lambda event: 0,
}
Beispiel #36
0
def fix_culprit(data):
    if not get_path(data, 'exception', 'values', filter=True):
        return

    from sentry.event_manager import generate_culprit
    data['culprit'] = generate_culprit(data)
Beispiel #37
0
 def test_empty_data(self):
     assert generate_culprit({}) == ''
Beispiel #38
0
def test_with_empty_stacktrace():
    data = {"stacktrace": None, "request": {"url": "http://example.com"}}
    assert generate_culprit(data) == "http://example.com"
Beispiel #39
0
def test_empty_data():
    assert generate_culprit({}) == ""
Beispiel #40
0
def get_culprit(event):
    from sentry.event_manager import generate_culprit

    return generate_culprit(event.data, event.platform)
Beispiel #41
0
 def fix_culprit(self, data, stacktraces):
     data['culprit'] = generate_culprit(data)
Beispiel #42
0
 def fix_culprit(self, data, stacktraces):
     data['culprit'] = generate_culprit(data)
Beispiel #43
0
            ),
        ),
    }


def merge_mappings(values):
    result = {}
    for value in values:
        result.update(value)
    return result


initial_fields = {
    'culprit':
    lambda event: generate_culprit(
        event.data,
        event.platform,
    ),
    'data':
    lambda event: {
        'last_received':
        event.data.get('received') or float(event.datetime.strftime('%s')),
        'type':
        event.data['type'],
        'metadata':
        event.data['metadata'],
    },
    'last_seen':
    lambda event: event.datetime,
    'level':
    lambda event: LOG_LEVELS_MAP.get(
        event.get_tag('level'),
Beispiel #44
0
    def test_with_only_http_interface(self):
        data = {"sentry.interfaces.Http": {"url": "http://example.com"}}
        assert generate_culprit(data) == "http://example.com"

        data = {"sentry.interfaces.Http": {}}
        assert generate_culprit(data) == ""