<commit_before>#!/usr/bin/env python
# encoding: utf-8

import logging

from raven.contrib.flask import Sentry

from framework.sessions import get_session

from website import settings

logger = logging.getLogger(__name__)

sentry = Sentry(dsn=settings.SENTRY_DSN)

# Nothing in this module should send to Sentry if debug mode is on
#   or if Sentry isn't configured.
enabled = (not settings.DEBUG_MODE) and settings.SENTRY_DSN


def get_session_data():
    try:
        return get_session().data
    except (RuntimeError, AttributeError):
        return {}


def log_exception():
    if not enabled:
        logger.warning('Sentry called to log exception, but is not active')
        return None

    return sentry.captureException(extra={
        'session': get_session_data(),
    })


def log_message(message, extra={}):
    if not enabled:
        logger.warning(
            'Sentry called to log message, but is not active: %s' % message
        )
        return None

    return sentry.captureMessage(message, extra=extra)<commit_msg>Add session info to extra data<commit_after>#!/usr/bin/env python
# encoding: utf-8

import logging

from raven.contrib.flask import Sentry

from framework.sessions import get_session

from website import settings

logger = logging.getLogger(__name__)

sentry = Sentry(dsn=settings.SENTRY_DSN)

# Nothing in this module should send to Sentry if debug mode is on
#   or if Sentry isn't configured.
enabled = (not settings.DEBUG_MODE) and settings.SENTRY_DSN


def get_session_data():
    try:
        return get_session().data
    except (RuntimeError, AttributeError):
        return {}


def log_exception():
    if not enabled:
        logger.warning('Sentry called to log exception, but is not active')
        return None

    return sentry.captureException(extra={
        'session': get_session_data(),
    })


def log_message(message, extra_data={}):
    if not enabled:
        logger.warning(
            'Sentry called to log message, but is not active: %s' % message
        )
        return None
    extra = {
        'session': get_session_data(),
    }

    if extra_data: extra.update(extra_data)

    return sentry.captureMessage(message, extra=extra)
{'fraction_non_alphanumeric': 0.08642533936651584, 'fraction_numerical': 0.0009049773755656109, 'mean_word_length': 3.2114285714285713, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '747759', 'n_tokens_mistral': 649, 'n_tokens_neox': 632, 'n_words': 204}