def _send_event( self, event # type: Event ): # type: (...) -> None # As this is ran in a thread sqs_client = boto3.client('sqs', **self._sqs_client_kwargs) body = io.BytesIO() with gzip.GzipFile(fileobj=body, mode="w") as f: f.write(json.dumps(event, allow_nan=False).encode("utf-8")) assert self.parsed_dsn is not None assert self._sqs_queue_url is not None logger.debug( "Sending event to SQS, type:%s level:%s event_id:%s project:%s host:%s" % ( event.get("type") or "null", event.get("level") or "null", event.get("event_id") or "null", self.parsed_dsn.project_id, self.parsed_dsn.host, )) sqs_payload = json.dumps({ 'method': 'POST', 'headers': { "User-Agent": str(self._auth.client), "X-Sentry-Auth": str(self._auth.to_header()), "Content-Type": "application/json", "Content-Encoding": "gzip", }, 'url': str(self._auth.store_api_url), 'body': base64.b64encode(body.getvalue()).decode() }) # TODO if message is greater than 256KiB then SQS wont take it, should add S3 ref fallback system try: sqs_client.send_message(QueueUrl=self._sqs_queue_url, MessageBody=sqs_payload) except Exception as err: logger.exception('Unexpected error whilst putting message on SQS', exc_info=err)
def bind_organization_context(organization): helper = settings.SENTRY_ORGANIZATION_CONTEXT_HELPER # XXX(dcramer): this is duplicated in organizationContext.jsx on the frontend with sentry_sdk.configure_scope() as scope: scope.set_tag("organization", organization.id) scope.set_tag("organization.slug", organization.slug) scope.set_context("organization", {"id": organization.id, "slug": organization.slug}) if helper: try: helper(scope=scope, organization=organization) except Exception: sdk_logger.exception( "internal-error.organization-context", extra={"organization_id": organization.id}, )
def setup_once(): # type: () -> None import redis patch_redis_client(redis.StrictRedis) try: import rb.clients # type: ignore except ImportError: pass else: patch_redis_client(rb.clients.FanoutClient) patch_redis_client(rb.clients.MappingClient) patch_redis_client(rb.clients.RoutingClient) try: _patch_rediscluster() except Exception: logger.exception( "Error occurred while patching `rediscluster` library")