示例#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'])
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
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)