Пример #1
0
def test_stacktraces_basics():
    data = {
        'message': 'hello',
        'platform': 'javascript',
        'sentry.interfaces.Stacktrace': {
            'frames': [
                {
                    'abs_path': 'http://example.com/foo.js',
                    'filename': 'foo.js',
                    'lineno': 4,
                    'colno': 0,
                },
                {
                    'abs_path': 'http://example.com/foo.js',
                    'filename': 'foo.js',
                    'lineno': 1,
                    'colno': 0,
                },
            ],
        },
    }

    infos = find_stacktraces_in_data(data)
    assert len(infos) == 1
    assert len(infos[0].stacktrace['frames']) == 2
    assert infos[0].platforms == set(['javascript'])
Пример #2
0
def test_stacktraces_basics():
    data = {
        'message': 'hello',
        'platform': 'javascript',
        'sentry.interfaces.Stacktrace': {
            'frames': [
                {
                    'abs_path': 'http://example.com/foo.js',
                    'filename': 'foo.js',
                    'lineno': 4,
                    'colno': 0,
                },
                {
                    'abs_path': 'http://example.com/foo.js',
                    'filename': 'foo.js',
                    'lineno': 1,
                    'colno': 0,
                },
            ],
        },
    }

    infos = find_stacktraces_in_data(data)
    assert len(infos) == 1
    assert len(infos[0].stacktrace['frames']) == 2
    assert infos[0].platforms == set(['javascript'])
Пример #3
0
def test_get_stacktraces_returns_exception_interface():
    data = {
        'message': 'hello',
        'platform': 'javascript',
        'sentry.interfaces.Exception': {
            'values': [{
                'type': 'Error',
                'stacktrace': {
                    'frames': [
                        {
                            'abs_path': 'http://example.com/foo.js',
                            'filename': 'foo.js',
                            'lineno': 4,
                            'colno': 0,
                        },
                        {
                            'abs_path': 'http://example.com/foo.js',
                            'filename': 'foo.js',
                            'lineno': 1,
                            'colno': 0,
                        },
                    ],
                },
            }],
        }
    }

    infos = find_stacktraces_in_data(data)
    assert len(infos) == 1
    assert len(infos[0].stacktrace['frames']) == 2
Пример #4
0
def test_get_stacktraces_returns_exception_interface():
    data = {
        'message': 'hello',
        'platform': 'javascript',
        'sentry.interfaces.Exception': {
            'values': [
                {
                    'type': 'Error',
                    'stacktrace': {
                        'frames': [
                            {
                                'abs_path': 'http://example.com/foo.js',
                                'filename': 'foo.js',
                                'lineno': 4,
                                'colno': 0,
                            },
                            {
                                'abs_path': 'http://example.com/foo.js',
                                'filename': 'foo.js',
                                'lineno': 1,
                                'colno': 0,
                            },
                        ],
                    },
                }
            ],
        }
    }

    infos = find_stacktraces_in_data(data)
    assert len(infos) == 1
    assert len(infos[0].stacktrace['frames']) == 2
Пример #5
0
    def test_stacktraces_threads(self):
        data = {
            'message': 'hello',
            'platform': 'javascript',
            'threads': {
                'values': [{
                    'id': '4711',
                    'stacktrace': {
                        'frames': [
                            {
                                'abs_path': 'http://example.com/foo.js',
                                'filename': 'foo.js',
                                'lineno': 4,
                                'colno': 0,
                            },
                            {
                                'abs_path': 'http://example.com/foo.js',
                                'filename': 'foo.js',
                                'lineno': 1,
                                'colno': 0,
                            },
                        ],
                    },
                }]
            }
        }

        infos = find_stacktraces_in_data(data)
        assert len(infos) == 1
        assert len(infos[0].stacktrace['frames']) == 2
Пример #6
0
    def test_stacktraces_threads(self):
        data = {
            'message': 'hello',
            'platform': 'javascript',
            'threads': {
                'values': [
                    {
                        'id': '4711',
                        'stacktrace': {
                            'frames': [
                                {
                                    'abs_path': 'http://example.com/foo.js',
                                    'filename': 'foo.js',
                                    'lineno': 4,
                                    'colno': 0,
                                },
                                {
                                    'abs_path': 'http://example.com/foo.js',
                                    'filename': 'foo.js',
                                    'lineno': 1,
                                    'colno': 0,
                                },
                            ],
                        },
                    }
                ]
            }
        }

        infos = find_stacktraces_in_data(data)
        assert len(infos) == 1
        assert len(infos[0].stacktrace['frames']) == 2
Пример #7
0
    def test_find_stacktraces_skip_none(self):
        # This tests:
        #  1. exception is None
        #  2. stacktrace is None
        #  3. frames is None
        #  3. frames contains only None
        #  4. frame is None
        data = {
            'message': 'hello',
            'platform': 'javascript',
            'exception': {
                'values': [
                    None,
                    {
                        'type': 'Error',
                        'stacktrace': None,
                    },
                    {
                        'type': 'Error',
                        'stacktrace': {
                            'frames': None,
                        },
                    },
                    {
                        'type': 'Error',
                        'stacktrace': {
                            'frames': [None],
                        },
                    },
                    {
                        'type': 'Error',
                        'stacktrace': {
                            'frames': [
                                None,
                                {
                                    'abs_path': 'http://example.com/foo.js',
                                    'filename': 'foo.js',
                                    'lineno': 4,
                                    'colno': 0,
                                },
                                {
                                    'abs_path': 'http://example.com/foo.js',
                                    'filename': 'foo.js',
                                    'lineno': 1,
                                    'colno': 0,
                                },
                            ],
                        },
                    },
                ]
            }
        }

        infos = find_stacktraces_in_data(data)
        assert len(infos) == 1
        # XXX: The null frame is still part of this stack trace!
        assert len(infos[0].stacktrace['frames']) == 3
Пример #8
0
    def test_find_stacktraces_skip_none(self):
        # This tests:
        #  1. exception is None
        #  2. stacktrace is None
        #  3. frames is None
        #  3. frames contains only None
        #  4. frame is None
        data = {
            'message': 'hello',
            'platform': 'javascript',
            'exception': {
                'values': [
                    None,
                    {
                        'type': 'Error',
                        'stacktrace': None,
                    },
                    {
                        'type': 'Error',
                        'stacktrace': {
                            'frames': None,
                        },
                    },
                    {
                        'type': 'Error',
                        'stacktrace': {
                            'frames': [None],
                        },
                    },
                    {
                        'type': 'Error',
                        'stacktrace': {
                            'frames': [
                                None,
                                {
                                    'abs_path': 'http://example.com/foo.js',
                                    'filename': 'foo.js',
                                    'lineno': 4,
                                    'colno': 0,
                                },
                                {
                                    'abs_path': 'http://example.com/foo.js',
                                    'filename': 'foo.js',
                                    'lineno': 1,
                                    'colno': 0,
                                },
                            ],
                        },
                    },
                ]
            }
        }

        infos = find_stacktraces_in_data(data)
        assert len(infos) == 1
        # XXX: The null frame is still part of this stack trace!
        assert len(infos[0].stacktrace['frames']) == 3
Пример #9
0
def generate_modules(data):
    from sentry.lang.javascript.processor import generate_module

    for info in find_stacktraces_in_data(data):
        for frame in info.stacktrace['frames']:
            platform = frame.get('platform') or data['platform']
            if platform != 'javascript' or frame.get('module'):
                continue
            abs_path = frame.get('abs_path')
            if abs_path and abs_path.startswith(('http:', 'https:', 'webpack:')):
                frame['module'] = generate_module(abs_path)
Пример #10
0
def generate_modules(data):
    from sentry.lang.javascript.processor import generate_module

    for info in find_stacktraces_in_data(data):
        for frame in get_path(info.stacktrace, 'frames', filter=True, default=()):
            platform = frame.get('platform') or data['platform']
            if platform not in ('javascript', 'node') or frame.get('module'):
                continue
            abs_path = frame.get('abs_path')
            if abs_path and abs_path.startswith(('http:', 'https:', 'webpack:', 'app:')):
                frame['module'] = generate_module(abs_path)