예제 #1
0
파일: store.py 프로젝트: bihicheng/sentry
def preprocess_event(cache_key=None, data=None, **kwargs):
    from sentry.app import cache
    from sentry.tasks.fetch_source import expand_javascript_source

    if cache_key:
        data = cache.get(cache_key)

    if data is None:
        return

    logger = preprocess_event.get_logger()

    try:
        if settings.SENTRY_SCRAPE_JAVASCRIPT_CONTEXT and data[
                'platform'] == 'javascript':
            try:
                expand_javascript_source(data)
            except Exception as e:
                logger.exception(u'Error fetching javascript source: %r [%s]',
                                 data['event_id'], e)
            cache.set(cache_key, data, 3600)
    finally:
        if cache_key:
            data = None
        save_event.delay(cache_key=cache_key, data=data)
예제 #2
0
파일: tests.py 프로젝트: seanlinsley/sentry
    def test_inlined_sources(self, discover_sourcemap, fetch_url, update):
        data = {
            'sentry.interfaces.Exception': {
                'values': [{
                    'stacktrace': {
                        'frames': [
                            {
                                'abs_path': 'http://example.com/test.js',
                                'filename': 'test.js',
                                'lineno': 1,
                                'colno': 0,
                            },
                        ],
                    },
                }],
            }
        }
        discover_sourcemap.return_value = base64_sourcemap
        fetch_url.return_value.body = '\n'.join('<generated source>')

        expand_javascript_source(data)
        fetch_url.assert_called_once_with('http://example.com/test.js')

        frame_list = data['sentry.interfaces.Exception']['values'][0][
            'stacktrace']['frames']
        frame = frame_list[0]
        assert frame['pre_context'] == []
        assert frame['context_line'] == 'console.log("hello, World!")'
        assert frame['post_context'] == []
예제 #3
0
파일: tests.py 프로젝트: uber/sentry
    def test_inlined_sources(self, discover_sourcemap, fetch_url, update):
        data = {
            'project': self.project.id,
            'sentry.interfaces.Exception': {
                'values': [{
                    'stacktrace': {
                        'frames': [
                            {
                                'abs_path': 'http://example.com/test.min.js',
                                'filename': 'test.js',
                                'lineno': 1,
                                'colno': 0,
                            },
                        ],
                    },
                }],
            }
        }
        discover_sourcemap.return_value = base64_sourcemap
        fetch_url.return_value.url = 'http://example.com/test.min.js'
        fetch_url.return_value.body = '\n'.join('<generated source>')

        expand_javascript_source(data)
        fetch_url.assert_called_once_with(
            'http://example.com/test.min.js', project=self.project)

        frame_list = data['sentry.interfaces.Exception']['values'][0]['stacktrace']['frames']
        frame = frame_list[0]
        assert not frame.get('pre_context')
        assert frame['context_line'] == 'console.log("hello, World!")'
        assert not frame.get('post_context')
예제 #4
0
파일: store.py 프로젝트: 755/sentry
def preprocess_event(data, **kwargs):
    from sentry.tasks.fetch_source import expand_javascript_source

    logger = preprocess_event.get_logger()

    try:
        if settings.SCRAPE_JAVASCRIPT_CONTEXT and data['platform'] == 'javascript':
            try:
                expand_javascript_source(data)
            except Exception, e:
                logger.exception(u'Error fetching javascript source: %s', e)
    finally:
        save_event.delay(data=data)
예제 #5
0
def preprocess_event(data, **kwargs):
    from sentry.tasks.fetch_source import expand_javascript_source

    logger = preprocess_event.get_logger()

    try:
        if settings.SENTRY_SCRAPE_JAVASCRIPT_CONTEXT and data[
                'platform'] == 'javascript':
            try:
                expand_javascript_source(data)
            except Exception as e:
                logger.exception(u'Error fetching javascript source: %s', e)
    finally:
        save_event.delay(data=data)
예제 #6
0
def preprocess_event(cache_key=None, data=None, **kwargs):
    from sentry.app import cache
    from sentry.plugins import plugins
    from sentry.tasks.fetch_source import expand_javascript_source

    if cache_key:
        data = cache.get(cache_key)

    logger = preprocess_event.get_logger()

    if data is None:
        logger.error('Data not available in preprocess_event (cache_key=%s)',
                     cache_key)
        return

    project = data['project']

    # TODO(dcramer): ideally we would know if data changed by default
    has_changed = False

    # TODO(dcramer): move js sourcemap processing into JS plugin
    if settings.SENTRY_SCRAPE_JAVASCRIPT_CONTEXT and data.get(
            'platform') == 'javascript':
        try:
            expand_javascript_source(data)
        except Exception as e:
            logger.exception(u'Error fetching javascript source: %r [%s]',
                             data['event_id'], e)
        else:
            has_changed = True

    for plugin in plugins.all(version=2):
        for processor in (safe_execute(plugin.get_event_preprocessors) or ()):
            result = safe_execute(processor, data)
            if result:
                data = result
                has_changed = True

    assert data[
        'project'] == project, 'Project cannot be mutated by preprocessor'

    if has_changed and cache_key:
        cache.set(cache_key, data, 3600)

    if cache_key:
        data = None
    save_event.delay(cache_key=cache_key, data=data)
예제 #7
0
파일: store.py 프로젝트: BlueMoebius/sentry
def preprocess_event(cache_key=None, data=None, **kwargs):
    from sentry.app import cache
    from sentry.plugins import plugins
    from sentry.tasks.fetch_source import expand_javascript_source

    if cache_key:
        data = cache.get(cache_key)

    logger = preprocess_event.get_logger()

    if data is None:
        logger.error('Data not available in preprocess_event (cache_key=%s)', cache_key)
        return

    project = data['project']

    # TODO(dcramer): ideally we would know if data changed by default
    has_changed = False

    # TODO(dcramer): move js sourcemap processing into JS plugin
    if settings.SENTRY_SCRAPE_JAVASCRIPT_CONTEXT and data.get('platform') == 'javascript':
        try:
            expand_javascript_source(data)
        except Exception as e:
            logger.exception(u'Error fetching javascript source: %r [%s]', data['event_id'], e)
        else:
            has_changed = True

    for plugin in plugins.all(version=2):
        for processor in (safe_execute(plugin.get_event_preprocessors) or ()):
            result = safe_execute(processor, data)
            if result:
                data = result
                has_changed = True

    assert data['project'] == project, 'Project cannot be mutated by preprocessor'

    if has_changed and cache_key:
        cache.set(cache_key, data, 3600)

    if cache_key:
        data = None
    save_event.delay(cache_key=cache_key, data=data)
예제 #8
0
파일: tests.py 프로젝트: uber/sentry
    def test_simple(self, discover_sourcemap, fetch_sourcemap, fetch_url, update):
        data = {
            'project': self.project.id,
            'sentry.interfaces.Exception': {
                'values': [{
                    '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,
                            },
                        ],
                    },
                }],
            }
        }
        discover_sourcemap.return_value = None
        fetch_sourcemap.return_value = None
        fetch_url.return_value.body = '\n'.join('hello world')

        expand_javascript_source(data)

        fetch_url.assert_called_once_with(
            'http://example.com/foo.js', project=self.project)

        frame_list = data['sentry.interfaces.Exception']['values'][0]['stacktrace']['frames']
        frame = frame_list[0]
        assert frame['pre_context'] == ['h', 'e', 'l']
        assert frame['context_line'] == 'l'
        assert frame['post_context'] == ['o', ' ', 'w', 'o', 'r']

        frame = frame_list[1]
        assert not frame.get('pre_context')
        assert frame['context_line'] == 'h'
        assert frame['post_context'] == ['e', 'l', 'l', 'o', ' ']
예제 #9
0
파일: tests.py 프로젝트: seanlinsley/sentry
    def test_simple(self, discover_sourcemap, fetch_sourcemap, fetch_url,
                    update):
        data = {
            'sentry.interfaces.Exception': {
                'values': [{
                    '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,
                            },
                        ],
                    },
                }],
            }
        }
        discover_sourcemap.return_value = None
        fetch_sourcemap.return_value = None
        fetch_url.return_value.body = '\n'.join('hello world')

        expand_javascript_source(data)

        fetch_url.assert_called_once_with('http://example.com/foo.js')

        frame_list = data['sentry.interfaces.Exception']['values'][0][
            'stacktrace']['frames']
        frame = frame_list[0]
        assert frame['pre_context'] == ['h', 'e', 'l']
        assert frame['context_line'] == 'l'
        assert frame['post_context'] == ['o', ' ', 'w', 'o', 'r']

        frame = frame_list[1]
        assert frame['pre_context'] == []
        assert frame['context_line'] == 'h'
        assert frame['post_context'] == ['e', 'l', 'l', 'o', ' ']
예제 #10
0
파일: store.py 프로젝트: jpadilla/sentry
def preprocess_event(cache_key=None, data=None, **kwargs):
    from sentry.app import cache
    from sentry.tasks.fetch_source import expand_javascript_source

    if cache_key:
        data = cache.get(cache_key)

    if data is None:
        return

    logger = preprocess_event.get_logger()

    if settings.SENTRY_SCRAPE_JAVASCRIPT_CONTEXT and data['platform'] == 'javascript':
        try:
            expand_javascript_source(data)
        except Exception as e:
            logger.exception(u'Error fetching javascript source: %r [%s]', data['event_id'], e)
        else:
            cache.set(cache_key, data, 3600)

    if cache_key:
        data = None
    save_event.delay(cache_key=cache_key, data=data)
예제 #11
0
파일: tests.py 프로젝트: 755/sentry
    def test_calls_from_kwargs(self, fetch_sourcemap, fetch_url, update):
        data = {
            '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,
                    },
                ],
            },
        }
        fetch_sourcemap.return_value = None
        fetch_url.return_value.body = '\n'.join('hello world')

        expand_javascript_source(data)

        fetch_url.assert_called_once_with('http://example.com/foo.js')

        frame_list = data['sentry.interfaces.Stacktrace']['frames']
        frame = frame_list[0]
        assert frame['pre_context'] == ['h', 'e', 'l']
        assert frame['context_line'] == 'l'
        assert frame['post_context'] == ['o', ' ', 'w', 'o', 'r']

        frame = frame_list[1]
        assert frame['pre_context'] == []
        assert frame['context_line'] == 'h'
        assert frame['post_context'] == ['e', 'l', 'l', 'o', ' ']