Esempio n. 1
0
def record_affected_user(event, **kwargs):
    from sentry.models import EventUser, Group

    user_data = event.data.get('sentry.interfaces.User', event.data.get('user'))
    if not user_data:
        logger.info('No user data found for event_id=%s', event.event_id)
        return

    euser = EventUser(
        project=event.project,
        ident=user_data.get('id'),
        email=user_data.get('email'),
        username=user_data.get('username'),
        ip_address=user_data.get('ip_address'),
    )

    if not euser.tag_value:
        # no ident, bail
        logger.info('No identifying value found for user on event_id=%s',
                    event.event_id)
        return

    try:
        with transaction.atomic():
            euser.save()
    except IntegrityError:
        pass

    Group.objects.add_tags(event.group, [
        ('sentry:user', euser.tag_value)
    ])
Esempio n. 2
0
    def _get_event_user(self, project, data):
        user_data = data.get('sentry.interfaces.User')
        if not user_data:
            return

        euser = EventUser(
            project=project,
            ident=user_data.get('id'),
            email=user_data.get('email'),
            username=user_data.get('username'),
            ip_address=user_data.get('ip_address'),
        )

        if not euser.tag_value:
            return

        cache_key = 'euser:{}:{}'.format(
            project.id,
            md5_text(euser.tag_value).hexdigest(),
        )
        cached = default_cache.get(cache_key)
        if cached is None:
            try:
                with transaction.atomic(using=router.db_for_write(EventUser)):
                    euser.save()
            except IntegrityError:
                pass
            default_cache.set(cache_key, '', 3600)

        return euser
Esempio n. 3
0
def record_affected_user(event, **kwargs):
    from sentry.models import EventUser, Group

    Raven.tags_context({
        'project': event.project_id,
    })

    user_data = event.data.get('sentry.interfaces.User',
                               event.data.get('user'))
    if not user_data:
        logger.info('No user data found for event_id=%s', event.event_id)
        return

    euser = EventUser(
        project=event.project,
        ident=user_data.get('id'),
        email=user_data.get('email'),
        username=user_data.get('username'),
        ip_address=user_data.get('ip_address'),
    )

    if not euser.tag_value:
        # no ident, bail
        logger.info('No identifying value found for user on event_id=%s',
                    event.event_id)
        return

    try:
        with transaction.atomic(using=router.db_for_write(EventUser)):
            euser.save()
    except IntegrityError:
        pass

    Group.objects.add_tags(event.group, [('sentry:user', euser.tag_value)])
Esempio n. 4
0
    def _get_event_user(self, project, data):
        user_data = data.get("sentry.interfaces.User")
        if not user_data:
            return

        euser = EventUser(
            project=project,
            ident=user_data.get("id"),
            email=user_data.get("email"),
            username=user_data.get("username"),
            ip_address=user_data.get("ip_address"),
        )

        if not euser.tag_value:
            return

        cache_key = "euser:{}:{}".format(project.id, md5(euser.tag_value.encode("utf-8")).hexdigest())
        cached = default_cache.get(cache_key)
        if cached is None:
            try:
                with transaction.atomic(using=router.db_for_write(EventUser)):
                    euser.save()
            except IntegrityError:
                pass
            default_cache.set(cache_key, "", 3600)

        return euser
Esempio n. 5
0
def _get_event_user_impl(project, data, metrics_tags):
    user_data = data.get("user")
    if not user_data:
        metrics_tags["event_has_user"] = "******"
        return

    metrics_tags["event_has_user"] = "******"

    ip_address = user_data.get("ip_address")

    if ip_address:
        try:
            ipaddress.ip_address(six.text_type(ip_address))
        except ValueError:
            ip_address = None

    euser = EventUser(
        project_id=project.id,
        ident=user_data.get("id"),
        email=user_data.get("email"),
        username=user_data.get("username"),
        ip_address=ip_address,
        name=user_data.get("name"),
    )
    euser.set_hash()
    if not euser.hash:
        return

    cache_key = u"euserid:1:{}:{}".format(project.id, euser.hash)
    euser_id = cache.get(cache_key)
    if euser_id is None:
        metrics_tags["cache_hit"] = "false"
        try:
            with transaction.atomic(using=router.db_for_write(EventUser)):
                euser.save()
            metrics_tags["created"] = "true"
        except IntegrityError:
            metrics_tags["created"] = "false"
            try:
                euser = EventUser.objects.get(project_id=project.id,
                                              hash=euser.hash)
            except EventUser.DoesNotExist:
                metrics_tags["created"] = "lol"
                # why???
                e_userid = -1
            else:
                if euser.name != (user_data.get("name") or euser.name):
                    euser.update(name=user_data["name"])
                e_userid = euser.id
            cache.set(cache_key, e_userid, 3600)
    else:
        metrics_tags["cache_hit"] = "true"

    return euser
Esempio n. 6
0
    def _get_event_user(self, project, data):
        user_data = data.get('sentry.interfaces.User')
        if not user_data:
            return

        euser = EventUser(
            project_id=project.id,
            ident=user_data.get('id'),
            email=user_data.get('email'),
            username=user_data.get('username'),
            ip_address=user_data.get('ip_address'),
            name=user_data.get('name'),
        )
        euser.set_hash()
        if not euser.hash:
            return

        cache_key = 'euserid:1:{}:{}'.format(
            project.id,
            euser.hash,
        )
        euser_id = default_cache.get(cache_key)
        if euser_id is None:
            try:
                with transaction.atomic(using=router.db_for_write(EventUser)):
                    euser.save()
            except IntegrityError:
                try:
                    euser = EventUser.objects.get(
                        project_id=project.id,
                        hash=euser.hash,
                    )
                except EventUser.DoesNotExist:
                    # why???
                    e_userid = -1
                else:
                    if euser.name != (user_data.get('name') or euser.name):
                        euser.update(
                            name=user_data['name'],
                        )
                    e_userid = euser.id
                default_cache.set(cache_key, e_userid, 3600)
        return euser
Esempio n. 7
0
    def _get_event_user(self, project, data):
        user_data = data.get('user')
        if not user_data:
            return

        euser = EventUser(
            project_id=project.id,
            ident=user_data.get('id'),
            email=user_data.get('email'),
            username=user_data.get('username'),
            ip_address=user_data.get('ip_address'),
            name=user_data.get('name'),
        )
        euser.set_hash()
        if not euser.hash:
            return

        cache_key = u'euserid:1:{}:{}'.format(
            project.id,
            euser.hash,
        )
        euser_id = cache.get(cache_key)
        if euser_id is None:
            try:
                with transaction.atomic(using=router.db_for_write(EventUser)):
                    euser.save()
            except IntegrityError:
                try:
                    euser = EventUser.objects.get(
                        project_id=project.id,
                        hash=euser.hash,
                    )
                except EventUser.DoesNotExist:
                    # why???
                    e_userid = -1
                else:
                    if euser.name != (user_data.get('name') or euser.name):
                        euser.update(
                            name=user_data['name'],
                        )
                    e_userid = euser.id
                cache.set(cache_key, e_userid, 3600)
        return euser
Esempio n. 8
0
    def _get_event_user(self, project, data):
        user_data = data.get('sentry.interfaces.User')
        if not user_data:
            return

        euser = EventUser(
            project=project,
            ident=user_data.get('id'),
            email=user_data.get('email'),
            username=user_data.get('username'),
            ip_address=user_data.get('ip_address'),
        )

        if not euser.tag_value:
            return

        try:
            with transaction.atomic():
                euser.save()
        except IntegrityError:
            pass

        return euser
Esempio n. 9
0
    def _get_event_user(self, project, data):
        user_data = data.get('sentry.interfaces.User')
        if not user_data:
            return

        euser = EventUser(
            project=project,
            ident=user_data.get('id'),
            email=user_data.get('email'),
            username=user_data.get('username'),
            ip_address=user_data.get('ip_address'),
        )

        if not euser.tag_value:
            return

        try:
            with transaction.atomic():
                euser.save()
        except IntegrityError:
            pass

        return euser