本文整理汇总了Python中sentry.helpers.construct_checksum函数的典型用法代码示例。如果您正苦于以下问题:Python construct_checksum函数的具体用法?Python construct_checksum怎么用?Python construct_checksum使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了construct_checksum函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: process
def process(self, **kwargs):
from sentry.helpers import get_filters
kwargs.setdefault('level', logging.ERROR)
kwargs.setdefault('server_name', conf.NAME)
if 'checksum' not in kwargs:
checksum = construct_checksum(**kwargs)
else:
checksum = kwargs['checksum']
if conf.THRASHING_TIMEOUT and conf.THRASHING_LIMIT:
cache_key = 'sentry:%s:%s' % (kwargs.get('class_name') or '', checksum)
added = cache.add(cache_key, 1, conf.THRASHING_TIMEOUT)
if not added:
try:
thrash_count = cache.incr(cache_key)
except (KeyError, ValueError):
# cache.incr can fail. Assume we aren't thrashing yet, and
# if we are, hope that the next error has a successful
# cache.incr call.
thrash_count = 0
if thrash_count > conf.THRASHING_LIMIT:
return
for filter_ in get_filters():
kwargs = filter_(None).process(kwargs) or kwargs
# Make sure all additional data is coerced
if 'data' in kwargs:
kwargs['data'] = transform(kwargs['data'])
return self.send(**kwargs)
示例2: process
def process(self, **kwargs):
from sentry.helpers import get_filters
kwargs.setdefault('level', logging.ERROR)
kwargs.setdefault('server_name', conf.NAME)
if 'checksum' not in kwargs:
checksum = construct_checksum(**kwargs)
else:
checksum = kwargs['checksum']
if conf.THRASHING_TIMEOUT and conf.THRASHING_LIMIT:
cache_key = 'sentry:%s:%s' % (kwargs.get('class_name') or '', checksum)
added = cache.add(cache_key, 1, conf.THRASHING_TIMEOUT)
try:
if not added and cache.incr(cache_key) > conf.THRASHING_LIMIT:
return
except KeyError:
pass
for filter_ in get_filters():
kwargs = filter_(None).process(kwargs) or kwargs
# Make sure all additional data is coerced
if 'data' in kwargs:
kwargs['data'] = transform(kwargs['data'])
return self.send(**kwargs)
示例3: from_kwargs
def from_kwargs(self, **kwargs):
from sentry.models import Message, GroupedMessage, FilterValue
URL_MAX_LENGTH = Message._meta.get_field_by_name("url")[0].max_length
now = datetime.datetime.now()
view = kwargs.pop("view", None)
logger_name = kwargs.pop("logger", "root")
url = kwargs.pop("url", None)
server_name = kwargs.pop("server_name", conf.CLIENT)
site = kwargs.pop("site", None)
data = kwargs.pop("data", {}) or {}
if url:
data["url"] = url
url = url[:URL_MAX_LENGTH]
checksum = construct_checksum(**kwargs)
mail = False
try:
group, created = GroupedMessage.objects.get_or_create(
view=view, logger=logger_name, checksum=checksum, defaults=kwargs
)
if not created:
GroupedMessage.objects.filter(pk=group.pk).update(
times_seen=models.F("times_seen") + 1, status=0, last_seen=now
)
# HACK: maintain appeared state
if group.status == 1:
mail = True
group.status = 0
group.last_seen = now
group.times_seen += 1
signals.post_save.send(sender=GroupedMessage, instance=group, created=False)
else:
mail = True
instance = Message.objects.create(
view=view,
logger=logger_name,
data=data,
url=url,
server_name=server_name,
site=site,
checksum=checksum,
group=group,
**kwargs
)
if server_name:
FilterValue.objects.get_or_create(key="server_name", value=server_name)
if site:
FilterValue.objects.get_or_create(key="site", value=site)
if logger_name:
FilterValue.objects.get_or_create(key="logger", value=logger_name)
except Exception, exc:
# TODO: should we mail admins when there are failures?
try:
logger.exception(u"Unable to process log entry: %s" % (exc,))
except Exception, exc:
warnings.warn(u"Unable to process log entry: %s" % (exc,))
示例4: create_from_record
def create_from_record(self, record, **kwargs):
"""
Creates an error log for a ``logging`` module ``record`` instance.
"""
for k in ('url', 'view', 'request', 'data'):
if not kwargs.get(k):
kwargs[k] = record.__dict__.get(k)
kwargs.update({
'logger': record.name,
'level': record.levelno,
'message': force_unicode(record.msg),
'server_name': conf.NAME,
})
# construct the checksum with the unparsed message
kwargs['checksum'] = construct_checksum(**kwargs)
# save the message with included formatting
kwargs['message'] = record.getMessage()
# If there's no exception being processed, exc_info may be a 3-tuple of None
# http://docs.python.org/library/sys.html#sys.exc_info
if record.exc_info and all(record.exc_info):
return self.create_from_exception(record.exc_info, **kwargs)
return self.process(
traceback=record.exc_text,
**kwargs
)
示例5: process
def process(self, **kwargs):
from sentry.helpers import get_filters
kwargs.setdefault("level", logging.ERROR)
kwargs.setdefault("server_name", conf.NAME)
checksum = construct_checksum(**kwargs)
if conf.THRASHING_TIMEOUT and conf.THRASHING_LIMIT:
cache_key = "sentry:%s:%s" % (kwargs.get("class_name") or "", checksum)
added = cache.add(cache_key, 1, conf.THRASHING_TIMEOUT)
try:
if not added and cache.incr(cache_key) > conf.THRASHING_LIMIT:
return
except KeyError:
pass
for filter_ in get_filters():
kwargs = filter_(None).process(kwargs) or kwargs
# Make sure all additional data is coerced
if "data" in kwargs:
kwargs["data"] = transform(kwargs["data"])
return self.send(**kwargs)
示例6: process
def process(self, **kwargs):
from sentry.helpers import get_filters
for filter_ in get_filters():
kwargs = filter_(None).process(kwargs) or kwargs
kwargs.setdefault('level', logging.ERROR)
kwargs.setdefault('server_name', settings.NAME)
checksum = construct_checksum(**kwargs)
if settings.THRASHING_TIMEOUT and settings.THRASHING_LIMIT:
cache_key = 'sentry:%s:%s' % (kwargs.get('class_name'), checksum)
added = cache.add(cache_key, 1, settings.THRASHING_TIMEOUT)
if not added:
try:
thrash_count = cache.incr(cache_key)
except ValueError:
# cache.incr can fail. Assume we aren't thrashing yet, and
# if we are, hope that the next error has a successful
# cache.incr call.
thrash_count = 0
if thrash_count > settings.THRASHING_LIMIT:
return
return self.send(**kwargs)
示例7: process
def process(self, **kwargs):
from sentry.helpers import get_filters
for filter_ in get_filters():
kwargs = filter_(None).process(kwargs) or kwargs
kwargs.setdefault('level', logging.ERROR)
kwargs.setdefault('server_name', socket.gethostname())
checksum = construct_checksum(**kwargs)
if settings.THRASHING_TIMEOUT and settings.THRASHING_LIMIT:
cache_key = 'sentry:%s:%s' % (kwargs.get('class_name'), checksum)
added = cache.add(cache_key, 1, settings.THRASHING_TIMEOUT)
if not added and cache.incr(cache_key) > settings.THRASHING_LIMIT:
return
if settings.REMOTE_URL:
data = {
'data': base64.b64encode(pickle.dumps(transform(kwargs)).encode('zlib')),
'key': settings.KEY,
}
req = urllib2.Request(settings.REMOTE_URL, urllib.urlencode(data))
try:
response = urllib2.urlopen(req, None, settings.REMOTE_TIMEOUT).read()
except urllib2.URLError, e:
logger.exception('Unable to reach Sentry log server')
except urllib2.HTTPError, e:
logger.exception('Unable to reach Sentry log server', extra={'body': e.read()})
示例8: from_kwargs
def from_kwargs(self, **kwargs):
from sentry.models import Message, GroupedMessage, FilterValue
URL_MAX_LENGTH = Message._meta.get_field_by_name('url')[0].max_length
now = datetime.datetime.now()
view = kwargs.pop('view', None)
logger_name = kwargs.pop('logger', 'root')
url = kwargs.pop('url', None)
server_name = kwargs.pop('server_name', settings.CLIENT)
data = kwargs.pop('data', {}) or {}
if url:
data['url'] = url
url = url[:URL_MAX_LENGTH]
checksum = construct_checksum(**kwargs)
mail = False
try:
group, created = GroupedMessage.objects.get_or_create(
view=view,
logger=logger_name,
checksum=checksum,
defaults=kwargs
)
if not created:
GroupedMessage.objects.filter(pk=group.pk).update(
times_seen=models.F('times_seen') + 1,
status=0,
last_seen=now,
)
# HACK: maintain appeared state
if group.status == 1:
mail = True
group.status = 0
group.last_seen = now
group.times_seen += 1
signals.post_save.send(sender=GroupedMessage, instance=group, created=False)
else:
mail = True
instance = Message.objects.create(
view=view,
logger=logger_name,
data=data,
url=url,
server_name=server_name,
checksum=checksum,
group=group,
**kwargs
)
FilterValue.objects.get_or_create(key='server_name', value=server_name)
FilterValue.objects.get_or_create(key='logger', value=logger_name)
except Exception, exc:
# TODO: should we mail admins when there are failures?
try:
logger.exception(u'Unable to process log entry: %s' % (exc,))
except Exception, exc:
warnings.warn(u'Unable to process log entry: %s' % (exc,))
示例9: process
def process(self, **kwargs):
from sentry.helpers import get_filters
kwargs.setdefault('level', logging.ERROR)
kwargs.setdefault('server_name', conf.NAME)
# save versions of all installed apps
if 'data' not in kwargs or '__sentry__' not in (kwargs['data'] or {}):
if kwargs.get('data') is None:
kwargs['data'] = {}
kwargs['data']['__sentry__'] = {}
versions = get_versions()
kwargs['data']['__sentry__']['versions'] = versions
if kwargs.get('view'):
# get list of modules from right to left
parts = kwargs['view'].split('.')
module_list = ['.'.join(parts[:idx]) for idx in xrange(1, len(parts)+1)][::-1]
version = None
for m in module_list:
if m in versions:
version = versions[m]
# store our "best guess" for application version
if version:
kwargs['data']['__sentry__']['version'] = version
if 'checksum' not in kwargs:
checksum = construct_checksum(**kwargs)
else:
checksum = kwargs['checksum']
if conf.THRASHING_TIMEOUT and conf.THRASHING_LIMIT:
cache_key = 'sentry:%s:%s' % (kwargs.get('class_name') or '', checksum)
added = cache.add(cache_key, 1, conf.THRASHING_TIMEOUT)
if not added:
try:
thrash_count = cache.incr(cache_key)
except (KeyError, ValueError):
# cache.incr can fail. Assume we aren't thrashing yet, and
# if we are, hope that the next error has a successful
# cache.incr call.
thrash_count = 0
if thrash_count > conf.THRASHING_LIMIT:
return
for filter_ in get_filters():
kwargs = filter_(None).process(kwargs) or kwargs
# Make sure all data is coerced
kwargs = transform(kwargs)
return self.send(**kwargs)
示例10: _create
def _create(self, **defaults):
from models import Message, GroupedMessage
URL_MAX_LENGTH = Message._meta.get_field_by_name('url')[0].max_length
view = defaults.pop('view', None)
logger_name = defaults.pop('logger', 'root')
url = defaults.pop('url', None)
data = defaults.pop('data', {}) or {}
if url:
data['url'] = url
url = url[:URL_MAX_LENGTH]
instance = Message(
view=view,
logger=logger_name,
data=data,
url=url,
server_name=socket.gethostname(),
**defaults
)
instance.checksum = construct_checksum(instance)
if settings.THRASHING_TIMEOUT and settings.THRASHING_LIMIT:
cache_key = 'sentry:%s:%s' % (instance.class_name, instance.checksum)
added = cache.add(cache_key, 1, settings.THRASHING_TIMEOUT)
if not added and cache.incr(cache_key) > settings.THRASHING_LIMIT:
return
try:
group, created = GroupedMessage.objects.get_or_create(
view=view,
logger=logger_name,
checksum=instance.checksum,
defaults=defaults
)
if not created:
GroupedMessage.objects.filter(pk=group.pk).update(
times_seen=models.F('times_seen') + 1,
status=0,
last_seen=datetime.datetime.now(),
)
instance.group = group
instance.save()
except Exception, exc:
try:
logger.exception(u'Unable to process log entry: %s' % (exc,))
except Exception, exc:
warnings.warn(u'Unable to process log entry: %s' % (exc,))
示例11: create_from_record
def create_from_record(self, record, **kwargs):
"""
Creates an error log for a `logging` module `record` instance.
"""
for k in ('url', 'view', 'data'):
if k not in kwargs:
kwargs[k] = record.__dict__.get(k)
request = getattr(record, 'request', None)
if request:
if not kwargs.get('data'):
kwargs['data'] = {}
kwargs['data'].update(dict(
META=request.META,
POST=request.POST,
GET=request.GET,
COOKIES=request.COOKIES,
raw_post_data=request.raw_post_data,
))
if not kwargs.get('url'):
kwargs['url'] = request.build_absolute_uri()
kwargs.update({
'logger': record.name,
'level': record.levelno,
'message': force_unicode(record.msg),
'server_name': conf.NAME,
})
# construct the checksum with the unparsed message
kwargs['checksum'] = construct_checksum(**kwargs)
# save the message with included formatting
kwargs['message'] = record.getMessage()
# If there's no exception being processed, exc_info may be a 3-tuple of None
# http://docs.python.org/library/sys.html#sys.exc_info
if record.exc_info and all(record.exc_info):
return self.create_from_exception(record.exc_info, **kwargs)
return self.process(
traceback=record.exc_text,
**kwargs
)
示例12: process
def process(self, **kwargs):
from sentry.helpers import get_filters
for filter_ in get_filters():
kwargs = filter_(None).process(kwargs) or kwargs
kwargs.setdefault("level", logging.ERROR)
kwargs.setdefault("server_name", settings.NAME)
checksum = construct_checksum(**kwargs)
if settings.THRASHING_TIMEOUT and settings.THRASHING_LIMIT:
cache_key = "sentry:%s:%s" % (kwargs.get("class_name"), checksum)
added = cache.add(cache_key, 1, settings.THRASHING_TIMEOUT)
if not added and cache.incr(cache_key) > settings.THRASHING_LIMIT:
return
return self.send(**kwargs)
示例13: create_from_record
def create_from_record(self, record, **kwargs):
"""
Creates an error log for a `logging` module `record` instance.
"""
for k in ("url", "view", "data"):
if k not in kwargs:
kwargs[k] = record.__dict__.get(k)
request = getattr(record, "request", None)
if request:
if not kwargs.get("data"):
kwargs["data"] = {}
kwargs["data"].update(dict(META=request.META, POST=request.POST, GET=request.GET, COOKIES=request.COOKIES))
if not kwargs.get("url"):
kwargs["url"] = request.build_absolute_uri()
kwargs.update(
{
"logger": record.name,
"level": record.levelno,
"message": force_unicode(record.msg),
"server_name": conf.NAME,
}
)
# construct the checksum with the unparsed message
kwargs["checksum"] = construct_checksum(**kwargs)
# save the message with included formatting
kwargs["message"] = record.getMessage()
# If there's no exception being processed, exc_info may be a 3-tuple of None
# http://docs.python.org/library/sys.html#sys.exc_info
if record.exc_info and all(record.exc_info):
return self.create_from_exception(record.exc_info, **kwargs)
return self.process(traceback=record.exc_text, **kwargs)
示例14: process
def process(self, **kwargs):
"Processes the message before passing it on to the server"
from sentry.helpers import get_filters
if kwargs.get('data'):
# Ensure we're not changing the original data which was passed
# to Sentry
kwargs['data'] = kwargs['data'].copy()
request = kwargs.pop('request', None)
if request:
if not kwargs.get('data'):
kwargs['data'] = {}
if not request.POST and request.raw_post_data:
post_data = request.raw_post_data
else:
post_data = request.POST
kwargs['data'].update(dict(
META=request.META,
POST=post_data,
GET=request.GET,
COOKIES=request.COOKIES,
REQUEST_USER=request.user,
))
if not kwargs.get('url'):
kwargs['url'] = request.build_absolute_uri()
kwargs.setdefault('level', logging.ERROR)
kwargs.setdefault('server_name', conf.NAME)
# save versions of all installed apps
if 'data' not in kwargs or '__sentry__' not in (kwargs['data'] or {}):
if kwargs.get('data') is None:
kwargs['data'] = {}
kwargs['data']['__sentry__'] = {}
versions = get_versions()
kwargs['data']['__sentry__']['versions'] = versions
# Shorten lists/strings
for k, v in kwargs['data'].iteritems():
if k == '__sentry__':
continue
kwargs['data'][k] = shorten(v)
if kwargs.get('view'):
# get list of modules from right to left
parts = kwargs['view'].split('.')
module_list = ['.'.join(parts[:idx]) for idx in xrange(1, len(parts)+1)][::-1]
version = None
module = None
for m in module_list:
if m in versions:
module = m
version = versions[m]
# store our "best guess" for application version
if version:
kwargs['data']['__sentry__'].update({
'version': version,
'module': module,
})
if 'checksum' not in kwargs:
checksum = construct_checksum(**kwargs)
else:
checksum = kwargs['checksum']
if conf.THRASHING_TIMEOUT and conf.THRASHING_LIMIT:
cache_key = 'sentry:%s:%s' % (kwargs.get('class_name') or '', checksum)
added = cache.add(cache_key, 1, conf.THRASHING_TIMEOUT)
if not added:
try:
thrash_count = cache.incr(cache_key)
except (KeyError, ValueError):
# cache.incr can fail. Assume we aren't thrashing yet, and
# if we are, hope that the next error has a successful
# cache.incr call.
thrash_count = 0
if thrash_count > conf.THRASHING_LIMIT:
message_id = cache.get('%s:last_message_id' % cache_key)
if request:
# attach the sentry object to the request
request.sentry = {
'id': message_id,
'thrashed': True,
}
return message_id
for filter_ in get_filters():
kwargs = filter_(None).process(kwargs) or kwargs
# create ID client-side so that it can be passed to application
message_id = uuid.uuid4().hex
kwargs['message_id'] = message_id
# Make sure all data is coerced
#.........这里部分代码省略.........
示例15: from_kwargs
def from_kwargs(self, **kwargs):
from sentry.models import Message, GroupedMessage, FilterValue
URL_MAX_LENGTH = Message._meta.get_field_by_name('url')[0].max_length
now = timezone.now()
view = kwargs.pop('view', None)
logger_name = kwargs.pop('logger', 'root')
url = kwargs.pop('url', None)
server_name = kwargs.pop('server_name', conf.CLIENT)
site = kwargs.pop('site', None)
data = kwargs.pop('data', {}) or {}
message_id = kwargs.pop('message_id', None)
if url:
data['url'] = url
url = url[:URL_MAX_LENGTH]
checksum = kwargs.pop('checksum', None)
if not checksum:
checksum = construct_checksum(**kwargs)
mail = False
try:
kwargs['data'] = {}
if 'url' in data:
kwargs['data']['url'] = data['url']
if 'version' in data.get('__sentry__', {}):
kwargs['data']['version'] = data['__sentry__']['version']
if 'module' in data.get('__sentry__', {}):
kwargs['data']['module'] = data['__sentry__']['module']
group, created = GroupedMessage.objects.get_or_create(
view=view,
logger=logger_name,
checksum=checksum,
# we store some sample data for rendering
defaults=kwargs
)
kwargs.pop('data', None)
if not created:
GroupedMessage.objects.filter(pk=group.pk).update(
times_seen=models.F('times_seen') + 1,
status=0,
last_seen=now,
)
# HACK: maintain appeared state
if group.status == 1:
mail = True
group.status = 0
group.last_seen = now
group.times_seen += 1
signals.post_save.send(sender=GroupedMessage, instance=group, created=False)
else:
mail = True
instance = Message.objects.create(
message_id=message_id,
view=view,
logger=logger_name,
data=data,
url=url,
server_name=server_name,
site=site,
checksum=checksum,
group=group,
**kwargs
)
if server_name:
FilterValue.objects.get_or_create(key='server_name', value=server_name)
if site:
FilterValue.objects.get_or_create(key='site', value=site)
if logger_name:
FilterValue.objects.get_or_create(key='logger', value=logger_name)
except Exception, exc:
# TODO: should we mail admins when there are failures?
try:
logger.exception(u'Unable to process log entry: %s' % (exc,))
except Exception, exc:
warnings.warn(u'Unable to process log entry: %s' % (exc,))