Example #1
0
def log_client(client):
    """Safely log client creation at INFO level."""
    if not client.is_enabled():
        # raven already logs a *disabled* client at INFO level
        return

    # base_url shouldn't have secrets in, but just in case, clean it
    public_dsn = client.remote.get_public_dsn()
    scheme = parse_url(client.remote.base_url).scheme
    url = scheme + ':' + public_dsn
    clean_url = sanitize_url(url)
    msg = 'configured raven DSN'
    extra = {'dsn': clean_url}
    config = talisker.get_config()
    env_cfg = config.raw.get('SENTRY_DSN')
    if env_cfg:
        # make a full url look like a public dsn
        clean_env = sanitize_url(re.sub(r'://(.*):.*@', r'://\1@', env_cfg))
        if clean_env == clean_url:
            msg += ' from SENTRY_DSN config'
            extra['from_env'] = True
        else:
            msg += ' overriding SENTRY_DSN config'
            extra['SENTRY_DSN'] = clean_env
    logging.getLogger(__name__).info(msg, extra=extra)
Example #2
0
def log_client(client):
    """Safely log client creation at INFO level."""
    if not client.is_enabled():
        # raven already logs a *disabled* client at INFO level
        return

    # base_url shouldn't have secrets in, but just in case, clean it
    public_dsn = client.remote.get_public_dsn()
    scheme = parse_url(client.remote.base_url).scheme
    url = scheme + ':' + public_dsn
    clean_url = sanitize_url(url)
    msg = 'configured raven DSN'
    extra = {'dsn': clean_url}
    config = talisker.get_config()
    env_cfg = config.raw.get('SENTRY_DSN')
    if env_cfg:
        # make a full url look like a public dsn
        clean_env = sanitize_url(re.sub(r'://(.*):.*@', r'://\1@', env_cfg))
        if clean_env == clean_url:
            msg += ' from SENTRY_DSN config'
            extra['from_env'] = True
        else:
            msg += ' overriding SENTRY_DSN config'
            extra['SENTRY_DSN'] = clean_env
    logging.getLogger(__name__).info(msg, extra=extra)
Example #3
0
def test_sanitize_url():
    source = 'https://*****:*****@host/path?q=bar'
    expected = 'https://*****:*****@host/path?'
    assert util.sanitize_url(source) == expected

    # with port
    assert (util.sanitize_url('https://host:1234/path') ==
            'https://host:1234/path')

    # no user
    assert util.sanitize_url('https://host/path') == 'https://host/path'
Example #4
0
    def workers(self, request):
        """Information about workers resource usage."""
        import psutil
        arbiter = psutil.Process(os.getppid())
        workers = arbiter.children()
        workers.sort(key=lambda p: p.pid)

        rows = [format_psutil_row('Gunicorn Master', arbiter)]
        for i, worker in enumerate(workers):
            rows.append(format_psutil_row('Worker {}'.format(i), worker))

        master = arbiter.as_dict(MASTER_FIELDS)
        master['cmdline'] = ' '.join(master['cmdline'])

        environ = master.pop('environ')
        if 'SENTRY_DSN' in environ:
            environ['SENTRY_DSN'] = sanitize_url(environ['SENTRY_DSN'])
        clean_environ = [
            (k, v) for k, v in sorted(environ.items())
            if k in TALISKER_ENV_VARS
        ]
        sorted_master = [(k, master[k]) for k in MASTER_FIELDS if k in master]

        return info_response(
            request,
            'Workers',
            Content('Workers', 'h2'),
            Table(rows, headers=HEADERS),
            Content('Process Information', 'h2'),
            Table(sorted_master),
            Content('Process Environment (whitelist)', 'h2'),
            Table(clean_environ),
        )
Example #5
0
def log_client(client, from_env=False):
    """Safely log client creation at INFO level."""
    if not client.is_enabled():
        # raven already logs a *disabled* client at INFO level
        return

    # base_url shouldn't have secrets in, but just in case, clean it
    public_dsn = client.remote.get_public_dsn()
    scheme = parse_url(client.remote.base_url).scheme
    url = scheme + ':' + public_dsn
    clean_url = sanitize_url(url)
    msg = 'configured raven'
    extra = {'dsn': clean_url}
    if from_env:
        msg += ' from SENTRY_DSN environment'
        extra['from_env'] = True
    logging.getLogger(__name__).info(msg, extra=extra)
Example #6
0
 def metadata(self):
     meta = collections.OrderedDict()
     for raw_name, (attr, doc) in self.METADATA.items():
         value = getattr(self, attr)
         if value:
             if raw_name in self.SANITISE_URLS:
                 value = sanitize_url(value)
             elif isinstance(value, list):
                 value = ', '.join(str(v) for v in value)
         meta[raw_name] = self.Metadata(
             raw_name,
             value,
             self.raw.get(raw_name),
             self.DEFAULTS.get(raw_name),
             doc,
             CONFIG_ERRORS.get(raw_name),
         )
     return meta
Example #7
0
 def metadata(self):
     meta = collections.OrderedDict()
     for raw_name, (attr, doc) in self.METADATA.items():
         value = getattr(self, attr)
         if value:
             if raw_name in self.SANITISE_URLS:
                 value = sanitize_url(value)
             elif isinstance(value, list):
                 value = ', '.join(str(v) for v in value)
         meta[raw_name] = self.Metadata(
             raw_name,
             value,
             self.raw.get(raw_name),
             self.DEFAULTS.get(raw_name),
             doc,
             CONFIG_ERRORS.get(raw_name),
         )
     return meta