Beispiel #1
0
 def __init__(self,
              publish_topic='events',
              sync=False,
              connection=None,
              **options):
     self.publish_topic = publish_topic
     self.pubsub = KafkaPublisher(connection)
     if not sync:
         self.pubsub = QueuedPublisher(self.pubsub)
Beispiel #2
0
class KafkaEventStream(EventStream):
    def __init__(self,
                 publish_topic='events',
                 sync=False,
                 connection=None,
                 **options):
        self.publish_topic = publish_topic
        self.pubsub = KafkaPublisher(connection)
        if not sync:
            self.pubsub = QueuedPublisher(self.pubsub)

    def publish(self,
                group,
                event,
                is_new,
                is_sample,
                is_regression,
                is_new_group_environment,
                primary_hash,
                skip_consume=False):
        project = event.project
        retention_days = quotas.get_event_retention(
            organization=Organization(project.organization_id))

        try:
            key = '%s:%s' % (event.project_id, event.event_id)
            value = (EVENT_PROTOCOL_VERSION, 'insert', {
                'group_id': event.group_id,
                'event_id': event.event_id,
                'organization_id': project.organization_id,
                'project_id': event.project_id,
                'message': event.message,
                'platform': event.platform,
                'datetime': event.datetime,
                'data': event.data.data,
                'primary_hash': primary_hash,
                'retention_days': retention_days,
            }, {
                'is_new': is_new,
                'is_sample': is_sample,
                'is_regression': is_regression,
                'is_new_group_environment': is_new_group_environment,
            })

            self.pubsub.publish(self.publish_topic,
                                key=key.encode('utf-8'),
                                value=json.dumps(value))
        except Exception as error:
            logger.warning('Could not publish event: %s', error, exc_info=True)
            raise
Beispiel #3
0
    is_same_domain,
)
from sentry.utils.pubsub import QueuedPublisher, RedisPublisher
from sentry.utils.safe import safe_execute
from sentry.web.helpers import render_to_response

logger = logging.getLogger('sentry')

# Transparent 1x1 gif
# See http://probablyprogramming.com/2009/03/15/the-tiniest-gif-ever
PIXEL = base64.b64decode('R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs=')

PROTOCOL_VERSIONS = frozenset(('2.0', '3', '4', '5', '6', '7'))

pubsub = QueuedPublisher(
    RedisPublisher(getattr(
        settings, 'REQUESTS_PUBSUB_CONNECTION', None))) if getattr(
            settings, 'REQUESTS_PUBSUB_ENABLED', False) else None


def api(func):
    @wraps(func)
    def wrapped(request, *args, **kwargs):
        data = func(request, *args, **kwargs)
        if request.is_ajax():
            response = HttpResponse(data)
            response['Content-Type'] = 'application/json'
        else:
            ref = request.META.get('HTTP_REFERER')
            if ref is None or not is_same_domain(ref,
                                                 request.build_absolute_uri()):