Exemplo n.º 1
0
    def send_encoded(self, message, auth_header=None, **kwargs):
        """
        Given an already serialized message, signs the message and passes the
        payload off to ``send_remote`` for each server specified in the servers
        configuration.

        callback can be specified as a keyword argument
        """
        if not auth_header:
            timestamp = time.time()
            auth_header = get_auth_header(
                protocol=self.protocol_version,
                timestamp=timestamp,
                client='raven-python/%s' % (raven.VERSION,),
                api_key=self.public_key,
                api_secret=self.secret_key,
            )

        for url in self.servers:
            headers = {
                'X-Sentry-Auth': auth_header,
                'Content-Type': 'application/octet-stream',
            }

            self.send_remote(
                url=url, data=message, headers=headers,
                callback=kwargs.get('callback', None)
            )
Exemplo n.º 2
0
    def send_encoded(self, message, auth_header=None, **kwargs):
        """
        Given an already serialized message, signs the message and passes the
        payload off to ``send_remote``.
        """
        client_string = 'raven-python/%s' % (raven.VERSION, )

        if not auth_header:
            timestamp = time.time()
            auth_header = get_auth_header(
                protocol=self.protocol_version,
                timestamp=timestamp,
                client=client_string,
                api_key=self.remote.public_key,
                api_secret=self.remote.secret_key,
            )

        headers = {
            'User-Agent': client_string,
            'X-Sentry-Auth': auth_header,
            'Content-Encoding': self.get_content_encoding(),
            'Content-Type': 'application/octet-stream',
        }

        return self.send_remote(url=self.remote.store_endpoint,
                                data=message,
                                headers=headers,
                                **kwargs)
Exemplo n.º 3
0
    def send_encoded(self, message, public_key=None, auth_header=None, **kwargs):
        """
        Given an already serialized message, signs the message and passes the
        payload off to ``send_remote`` for each server specified in the servers
        configuration.
        """
        if not self.servers:
            warnings.warn('Raven client has no remote servers configured')
            return

        client_string = 'raven-python/%s' % (raven.VERSION,)

        if not auth_header:
            timestamp = time.time()
            auth_header = get_auth_header(
                protocol=self.protocol_version,
                timestamp=timestamp,
                client=client_string,
                api_key=public_key or self.public_key
            )

        for url in self.servers:
            headers = {
                'User-Agent': client_string,
                'X-Sentry-Auth': auth_header,
                'Content-Type': 'application/octet-stream',
            }

            self.send_remote(url=url, data=message, headers=headers)
Exemplo n.º 4
0
Arquivo: base.py Projeto: mbenda/raven
    def send(self, **data):
        """
        Sends the message to the server.

        If ``servers`` was passed into the constructor, this will serialize the data and pipe it to
        each server using ``send_remote()``. Otherwise, this will communicate with ``sentry.models.GroupedMessage``
        directly.
        """
        message = base64.b64encode(json.dumps(data).encode('zlib'))

        for url in self.servers:
            timestamp = time.time()
            signature = get_signature(message, timestamp, self.secret_key or self.key)
            headers = {
                'X-Sentry-Auth': get_auth_header(signature, timestamp, 'raven/%s' % (raven.VERSION,), self.public_key),
                'Content-Type': 'application/octet-stream',
            }

            try:
                self.send_remote(url=url, data=message, headers=headers)
            except urllib2.HTTPError, e:
                body = e.read()
                self.logger.error('Unable to reach Sentry log server: %s (url: %%s, body: %%s)' % (e,), url, body,
                             exc_info=True, extra={'data': {'body': body, 'remote_url': url}})
                self.logger.log(data.pop('level', None) or logging.ERROR, data.pop('message', None))
            except urllib2.URLError, e:
                self.logger.error('Unable to reach Sentry log server: %s (url: %%s)' % (e,), url,
                             exc_info=True, extra={'data': {'remote_url': url}})
                self.logger.log(data.pop('level', None) or logging.ERROR, data.pop('message', None))
Exemplo n.º 5
0
    def send_encoded(self,
                     message,
                     public_key=None,
                     auth_header=None,
                     **kwargs):
        """
        Given an already serialized message, signs the message and passes the
        payload off to ``send_remote`` for each server specified in the servers
        configuration.
        """
        if not self.servers:
            warnings.warn('Raven client has no remote servers configured')
            return

        if not auth_header:
            timestamp = time.time()
            auth_header = get_auth_header(
                protocol=self.protocol_version,
                timestamp=timestamp,
                client='raven-python/%s' % (raven.VERSION, ),
                api_key=public_key or self.public_key)

        for url in self.servers:
            headers = {
                'X-Sentry-Auth': auth_header,
                'Content-Type': 'application/octet-stream',
            }

            self.send_remote(url=url, data=message, headers=headers)
Exemplo n.º 6
0
    def send_encoded(self, message, auth_header=None, **kwargs):
        """
        Given an already serialized message, signs the message and passes the
        payload off to ``send_remote`` for each server specified in the servers
        configuration.
        """
        client_string = "raven-python/%s" % (raven.VERSION,)

        if not auth_header:
            timestamp = time.time()
            auth_header = get_auth_header(
                protocol=self.protocol_version,
                timestamp=timestamp,
                client=client_string,
                api_key=self.remote.public_key,
                api_secret=self.remote.secret_key,
            )

        headers = {
            "User-Agent": client_string,
            "X-Sentry-Auth": auth_header,
            "Content-Encoding": self.get_content_encoding(),
            "Content-Type": "application/octet-stream",
        }

        self.send_remote(url=self.remote.store_endpoint, data=message, headers=headers, **kwargs)
Exemplo n.º 7
0
    def send_encoded(self, message, auth_header=None, **kwargs):
        """
        Given an already serialized message, signs the message and passes the
        payload off to ``send_remote`` for each server specified in the servers
        configuration.
        """
        client_string = 'raven-python/%s' % (raven.VERSION,)

        if not auth_header:
            timestamp = time.time()
            auth_header = get_auth_header(
                protocol=self.protocol_version,
                timestamp=timestamp,
                client=client_string,
                api_key=self.public_key,
                api_secret=self.secret_key,
            )

        for url in self.servers:
            headers = {
                'User-Agent': client_string,
                'X-Sentry-Auth': auth_header,
                'Content-Type': 'application/octet-stream',
            }

            self.send_remote(url=url, data=message, headers=headers)
Exemplo n.º 8
0
    def send_encoded(self, message, auth_header=None, **kwargs):
        """
        Given an already serialized message, signs the message and passes the
        payload off to ``send_remote``.
        """
        client_string = 'raven-python/%s' % (raven.VERSION,)

        if not auth_header:
            timestamp = time.time()
            auth_header = get_auth_header(
                protocol=self.protocol_version,
                timestamp=timestamp,
                client=client_string,
                api_key=self.remote.public_key,
                api_secret=self.remote.secret_key,
            )

        headers = {
            'User-Agent': client_string,
            'X-Sentry-Auth': auth_header,
            'Content-Encoding': self.get_content_encoding(),
            'Content-Type': 'application/octet-stream',
        }

        self.send_remote(
            url=self.remote.store_endpoint,
            data=message,
            headers=headers,
            **kwargs
        )
Exemplo n.º 9
0
    def send(self, **data):
        """
        Sends the message to the server.

        If ``servers`` was passed into the constructor, this will serialize the data and pipe it to
        each server using ``send_remote()``. Otherwise, this will communicate with ``sentry.models.GroupedMessage``
        directly.
        """
        message = base64.b64encode(json.dumps(data).encode('zlib'))

        for url in self.servers:
            timestamp = time.time()
            signature = get_signature(message, timestamp, self.secret_key or self.key)
            headers = {
                'X-Sentry-Auth': get_auth_header(signature, timestamp, 'raven/%s' % (raven.VERSION,), self.public_key),
                'Content-Type': 'application/octet-stream',
            }

            try:
                self.send_remote(url=url, data=message, headers=headers)
            except urllib2.HTTPError, e:
                body = e.read()
                self.logger.error('Unable to reach Sentry log server: %s (url: %%s, body: %%s)' % (e,), url, body,
                             exc_info=True, extra={'data': {'body': body, 'remote_url': url}})
                self.logger.log(data.pop('level', None) or logging.ERROR, data.pop('message', None))
            except urllib2.URLError, e:
                self.logger.error('Unable to reach Sentry log server: %s (url: %%s)' % (e,), url,
                             exc_info=True, extra={'data': {'remote_url': url}})
                self.logger.log(data.pop('level', None) or logging.ERROR, data.pop('message', None))
Exemplo n.º 10
0
    def send_encoded(self, message, public_key=None, auth_header=None, **kwargs):
        """
        Given an already serialized message, signs the message and passes the
        payload off to ``send_remote`` for each server specified in the servers
        configuration.

        callback can be specified as a keyword argument
        """
        if not self.servers:
            warnings.warn("Raven client has no remote servers configured")
            return

        if not auth_header:
            timestamp = time.time()
            auth_header = get_auth_header(
                protocol=self.protocol_version,
                timestamp=timestamp,
                client="raven-python/%s" % (raven.VERSION,),
                api_key=public_key or self.public_key,
            )

        for url in self.servers:
            headers = {"X-Sentry-Auth": auth_header, "Content-Type": "application/octet-stream"}

            self.send_remote(url=url, data=message, headers=headers, callback=kwargs.get("callback", None))
    def send(self, **kwargs):
        # Report the issue to an upstream Sentry if active
        # NOTE: we don't want to check self.is_enabled() like normal, since
        # is_enabled behavior is overridden in this class. We explicitly
        # want to check if the remote is active.
        if self.remote.is_active():
            from sentry import options
            # Append some extra tags that are useful for remote reporting
            super_kwargs = copy.deepcopy(kwargs)
            super_kwargs['tags']['install-id'] = options.get(
                'sentry:install-id')
            super(SentryInternalClient, self).send(**super_kwargs)

        if not is_current_event_safe():
            return

        # These imports all need to be internal to this function as this class
        # is set up by django while still parsing LOGGING settings and we
        # cannot import this stuff until settings are finalized.
        from sentry.models import ProjectKey
        from sentry.web.api import StoreView
        from django.test import RequestFactory
        key = None
        if settings.SENTRY_PROJECT_KEY is not None:
            key = ProjectKey.objects.filter(
                id=settings.SENTRY_PROJECT_KEY,
                project=settings.SENTRY_PROJECT).first()
        if key is None:
            key = ProjectKey.get_default(settings.SENTRY_PROJECT)
        if key is None:
            return

        client_string = 'raven-python/%s' % (raven.VERSION, )
        headers = {
            'HTTP_X_SENTRY_AUTH':
            get_auth_header(
                protocol=self.protocol_version,
                timestamp=time.time(),
                client=client_string,
                api_key=key.public_key,
                api_secret=key.secret_key,
            ),
            'HTTP_CONTENT_ENCODING':
            self.get_content_encoding(),
        }
        self.request_factory = self.request_factory or RequestFactory()
        request = self.request_factory.post(
            '/api/store',
            data=self.encode(kwargs),
            content_type='application/octet-stream',
            **headers)
        StoreView.as_view()(
            request,
            project_id=six.text_type(settings.SENTRY_PROJECT),
        )
Exemplo n.º 12
0
    def send(self, **kwargs):
        # These imports all need to be internal to this function as this class
        # is set up by django while still parsing LOGGING settings and we
        # cannot import this stuff until settings are finalized.
        from sentry.web.api import StoreView
        from django.test import RequestFactory

        # Report the issue to an upstream Sentry if active
        # NOTE: we don't want to check self.is_enabled() like normal, since
        # is_enabled behavior is overridden in this class. We explicitly
        # want to check if the remote is active.
        if self.remote.is_active():
            from sentry import options
            # Append some extra tags that are useful for remote reporting
            super_kwargs = copy.deepcopy(kwargs)
            super_kwargs['tags']['install-id'] = options.get('sentry:install-id')
            super(SentryInternalClient, self).send(**super_kwargs)

        if not is_current_event_safe():
            self.error_logger.warn('internal-error.unsafe-stacktrace')
            return

        key = self.project_key
        if key is None:
            return

        client_string = 'raven-python/{}'.format(raven.VERSION)
        headers = {
            'HTTP_X_SENTRY_AUTH': get_auth_header(
                protocol=self.protocol_version,
                timestamp=time(),
                client=client_string,
                api_key=key.public_key,
                api_secret=key.secret_key,
            ),
            'HTTP_CONTENT_ENCODING': self.get_content_encoding(),
        }
        self.request_factory = self.request_factory or RequestFactory()
        request = self.request_factory.post(
            '/api/{}/store/'.format(key.project_id),
            data=self.encode(kwargs),
            content_type='application/octet-stream',
            **headers
        )
        resp = StoreView.as_view()(
            request,
            project_id=six.text_type(key.project_id),
        )
        if resp.status_code != 200:
            self.error_logger.warn('internal-error.invalid-response', extra={
                'project_id': settings.SENTRY_PROJECT,
                'project_key': settings.SENTRY_PROJECT_KEY,
                'status_code': resp.status_code,
            })
Exemplo n.º 13
0
    def send(self, **kwargs):
        # Report the issue to an upstream Sentry if active
        # NOTE: we don't want to check self.is_enabled() like normal, since
        # is_enabled behavior is overridden in this class. We explicitly
        # want to check if the remote is active.
        if self.remote.is_active():
            from sentry import options
            # Append some extra tags that are useful for remote reporting
            super_kwargs = copy.deepcopy(kwargs)
            super_kwargs['tags']['install-id'] = options.get('sentry:install-id')
            super(SentryInternalClient, self).send(**super_kwargs)

        if not is_current_event_safe():
            return

        # These imports all need to be internal to this function as this class
        # is set up by django while still parsing LOGGING settings and we
        # cannot import this stuff until settings are finalized.
        from sentry.models import ProjectKey
        from sentry.web.api import StoreView
        from django.test import RequestFactory
        key = None
        if settings.SENTRY_PROJECT_KEY is not None:
            key = ProjectKey.objects.filter(
                id=settings.SENTRY_PROJECT_KEY,
                project=settings.SENTRY_PROJECT).first()
        if key is None:
            key = ProjectKey.get_default(settings.SENTRY_PROJECT)
        if key is None:
            return

        client_string = 'raven-python/%s' % (raven.VERSION,)
        headers = {
            'HTTP_X_SENTRY_AUTH': get_auth_header(
                protocol=self.protocol_version,
                timestamp=time.time(),
                client=client_string,
                api_key=key.public_key,
                api_secret=key.secret_key,
            ),
            'HTTP_CONTENT_ENCODING': self.get_content_encoding(),
        }
        self.request_factory = self.request_factory or RequestFactory()
        request = self.request_factory.post(
            '/api/store',
            data=self.encode(kwargs),
            content_type='application/octet-stream',
            **headers
        )
        StoreView.as_view()(
            request,
            project_id=six.text_type(settings.SENTRY_PROJECT),
        )
Exemplo n.º 14
0
    def test_no_secret_key(self):
        dsn = 'https://[email protected]/1'
        res = RemoteConfig.from_string(dsn)
        assert res.project == '1'
        assert res.base_url == 'https://sentry.local'
        assert res.store_endpoint == 'https://sentry.local/api/1/store/'
        assert res.public_key == 'foo'
        assert res.secret_key is None
        assert res.options == {}
        assert res.is_active()

        assert get_auth_header(protocol=7, timestamp=42,
                               client='raven-python/1.0',
                               api_key=res.public_key) == (
            'Sentry sentry_timestamp=42, sentry_client=raven-python/1.0, '
            'sentry_version=7, sentry_key=foo')
Exemplo n.º 15
0
    def test_no_secret_key(self):
        dsn = 'https://[email protected]/1'
        res = RemoteConfig.from_string(dsn)
        assert res.project == '1'
        assert res.base_url == 'https://sentry.local'
        assert res.store_endpoint == 'https://sentry.local/api/1/store/'
        assert res.public_key == 'foo'
        assert res.secret_key is None
        assert res.options == {}

        assert get_auth_header(
            protocol=7,
            timestamp=42,
            client='raven-python/1.0',
            api_key=res.public_key) == (
                'Sentry sentry_timestamp=42, sentry_client=raven-python/1.0, '
                'sentry_version=7, sentry_key=foo')
Exemplo n.º 16
0
    def send(self, **data):
        """
        Sends the message to the server.

        If ``servers`` was passed into the constructor, this will serialize the data and pipe it to
        each server using ``send_remote()``. Otherwise, this will communicate with ``sentry.models.GroupedMessage``
        directly.
        """
        message = base64.b64encode(json.dumps(data).encode('zlib'))

        for url in self.servers:
            timestamp = time.time()
            signature = get_signature(message, timestamp, self.secret_key or self.key)
            headers = {
                'X-Sentry-Auth': get_auth_header(signature, timestamp, 'raven/%s' % (raven.VERSION,), self.public_key),
                'Content-Type': 'application/octet-stream',
            }

            self.send_remote(url=url, data=message, headers=headers)
Exemplo n.º 17
0
    def send_encoded(self, message):
        """
        Given an already serialized message, signs the message and passes the payload
        off to ``send_remote`` for each server specified in the servers configuration.
        """
        for url in self.servers:
            timestamp = time.time()
            signature = get_signature(message, timestamp, self.secret_key or self.key)
            headers = {
                'X-Sentry-Auth': get_auth_header(
                    protocol=self.protocol_version,
                    signature=signature,
                    timestamp=timestamp,
                    client='raven-python/%s' % (raven.VERSION,),
                    api_key=self.public_key
                ),
                'Content-Type': 'application/octet-stream',
            }

            self.send_remote(url=url, data=message, headers=headers)
Exemplo n.º 18
0
    def send_encoded(self, message):
        """
        Given an already serialized message, signs the message and passes the payload
        off to ``send_remote`` for each server specified in the servers configuration.
        """
        for url in self.servers:
            timestamp = time.time()
            signature = get_signature(message, timestamp, self.secret_key
                                      or self.key)
            headers = {
                'X-Sentry-Auth':
                get_auth_header(protocol=self.protocol_version,
                                signature=signature,
                                timestamp=timestamp,
                                client='raven-python/%s' % (raven.VERSION, ),
                                api_key=self.public_key),
                'Content-Type':
                'application/octet-stream',
            }

            self.send_remote(url=url, data=message, headers=headers)
Exemplo n.º 19
0
    def send(self, **kwargs):
        """
        Sends the message to the server.

        If ``servers`` was passed into the constructor, this will serialize the data and pipe it to
        each server using ``send_remote()``. Otherwise, this will communicate with ``sentry.models.GroupedMessage``
        directly.
        """
        message = base64.b64encode(json.dumps(kwargs).encode("zlib"))
        for url in self.servers:
            timestamp = time.time()
            signature = get_signature(self.key, message, timestamp)
            headers = {
                "Authorization": get_auth_header(
                    signature, timestamp, "%s/%s" % (self.__class__.__name__, raven.VERSION)
                ),
                "Content-Type": "application/octet-stream",
            }

            try:
                self.send_remote(url=url, data=message, headers=headers)
            except urllib2.HTTPError, e:
                body = e.read()
                logger.error(
                    "Unable to reach Sentry log server: %s (url: %%s, body: %%s)" % (e,),
                    url,
                    body,
                    exc_info=True,
                    extra={"data": {"body": body, "remote_url": url}},
                )
                logger.log(kwargs.pop("level", None) or logging.ERROR, kwargs.pop("message", None))
            except urllib2.URLError, e:
                logger.error(
                    "Unable to reach Sentry log server: %s (url: %%s)" % (e,),
                    url,
                    exc_info=True,
                    extra={"data": {"remote_url": url}},
                )
                logger.log(kwargs.pop("level", None) or logging.ERROR, kwargs.pop("message", None))