Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _capture_stats(event, is_new):
# TODO(dcramer): limit platforms to... something?
group = event.group
platform = group.platform
if not platform:
return
platform = platform.split('-', 1)[0].split('_', 1)[0]
if is_new:
metrics.incr('events.unique')
metrics.incr('events.processed')
metrics.incr('events.processed.{platform}'.format(
platform=platform))
metrics.timing('events.size.data', len(unicode(event.data)))
def _capture_stats(event, is_new):
# TODO(dcramer): limit platforms to... something?
group = event.group
platform = group.platform
if not platform:
return
platform = platform.split('-', 1)[0].split('_', 1)[0]
tags = {
'platform': platform,
}
if is_new:
metrics.incr('events.unique', tags=tags, skip_internal=False)
metrics.incr('events.processed', tags=tags, skip_internal=False)
metrics.incr(u'events.processed.{platform}'.format(platform=platform), skip_internal=False)
metrics.timing('events.size.data', event.size, tags=tags)
om.delete()
else:
om.set_user(self.request.user)
om.save()
self.instance.create_audit_entry(
self.request,
organization=om.organization,
target_object=om.id,
target_user=self.request.user,
event=AuditLogEntryEvent.MEMBER_ACCEPT,
data=om.get_audit_log_data(),
)
self.handle_success()
metrics.incr("organization.invite-accepted", sample_rate=1.0)
def post_process(self, event, **kwargs):
token = self.get_option("token", event.project)
index = self.get_option("index", event.project)
instance = self.get_option("instance", event.project)
if not (token and index and instance):
metrics.incr(
"integrations.splunk.forward-event.unconfigured",
tags={
"project_id": event.project_id,
"organization_id": event.project.organization_id,
"event_type": event.get_event_type(),
},
)
return
if not instance.endswith("/services/collector"):
instance = instance.rstrip("/") + "/services/collector"
source = self.get_option("source", event.project) or "sentry"
rl_key = "splunk:{}".format(md5_text(token).hexdigest())
# limit splunk to 50 requests/second
def build_handler(self, incident, project):
type = AlertRuleTriggerAction.Type(self.type)
if type in self._type_registrations:
return self._type_registrations[type].handler(self, incident, project)
else:
metrics.incr("alert_rule_trigger.unhandled_type.{}".format(self.type))
def set(self, key, attachments, timeout=None):
key = self.make_key(key)
for index, attachment in enumerate(attachments):
compressed = zlib.compress(attachment.data)
self.inner.set(u"{}:{}".format(key, index), compressed, timeout, raw=True)
metrics_tags = {"type": attachment.type}
metrics.incr("attachments.received", tags=metrics_tags, skip_internal=False)
metrics.timing("attachments.blob-size.raw", len(attachment.data), tags=metrics_tags)
metrics.timing("attachments.blob-size.compressed", len(compressed), tags=metrics_tags)
meta = [attachment.meta() for attachment in attachments]
self.inner.set(key, meta, timeout, raw=False)
md5_text(request.POST["username"].lower()).hexdigest()
),
limit=10,
window=60, # 10 per minute should be enough for anyone
):
login_form.errors["__all__"] = [
u"You have made too many login attempts. Please try again later."
]
metrics.incr(
"login.attempt", instance="rate_limited", skip_internal=True, sample_rate=1.0
)
elif login_form.is_valid():
user = login_form.get_user()
auth.login(request, user, organization_id=organization.id if organization else None)
metrics.incr(
"login.attempt", instance="success", skip_internal=True, sample_rate=1.0
)
if not user.is_active:
return self.redirect(reverse("sentry-reactivate-account"))
return self.redirect(auth.get_login_redirect(request))
else:
metrics.incr(
"login.attempt", instance="failure", skip_internal=True, sample_rate=1.0
)
context = {
"op": op or "login",
"server_hostname": get_server_hostname(),
"login_form": login_form,
def _call_all_backends(self, func, *args, **kwargs):
"""\
Call `func` on all backends, returning the first backend's return value, or raising any exception.
"""
metrics.incr(
'tagstore.multi.call',
instance=func,
skip_internal=True,
)
ret_val = None
exc = None
for i, backend in enumerate(self.backends):
try:
f = getattr(backend, func)
if (i == 0):
ret_val = f(*args, **kwargs)
else:
self.runner.run(f, *args, **kwargs)
except Exception as e:
json=True,
allow_text=None,
allow_redirects=None,
):
if allow_text is None:
allow_text = self.allow_text
if allow_redirects is None:
allow_redirects = self.allow_redirects
if allow_redirects is None: # is still None
allow_redirects = method.upper() == "GET"
full_url = self.build_url(path)
metrics.incr("sentry-plugins.http_request", tags={"plugin": self.plugin_name})
session = build_session()
try:
resp = getattr(session, method.lower())(
url=full_url,
headers=headers,
json=data if json else None,
data=data if not json else None,
params=params,
auth=auth,
verify=self.verify_ssl,
allow_redirects=allow_redirects,
)
resp.raise_for_status()
except ConnectionError as e:
raise ApiHostError.from_exception(e)
self._ensure_open()
url = urljoin(self.url, path)
# required for load balancing
kwargs.setdefault("headers", {})["x-sentry-project-id"] = self.project_id
kwargs.setdefault("headers", {})["x-sentry-event-id"] = self.event_id
attempts = 0
wait = 0.5
while True:
try:
response = self.session.request(method, url, **kwargs)
metrics.incr(
"events.symbolicator.status_code",
tags={"status_code": response.status_code, "project_id": self.project_id},
)
if (
method.lower() == "get"
and path.startswith("requests/")
and response.status_code == 404
):
# The symbolicator does not know this task. This is
# expected to happen when we're currently deploying
# symbolicator (which will clear all of its state). Re-send
# the symbolication task.
return None
if response.status_code in (502, 503):