import os
import statsd as _statsd


__all__ = ['statsd']


class StatsClient(object):
    """Wrap statsd.StatsClient to allow data_set to be added to stat"""
    def __init__(self, statsd):
        self._statsd = statsd

    def __getattr__(self, item):
        if item in ['timer', 'timing', 'incr', 'decr', 'gauge']:
            def func(stat, *args, **kwargs):
                data_set = kwargs.pop('data_set', 'unknown')
                stat = '%s.%s' % (data_set, stat)

                return getattr(self._statsd, item)(stat, *args, **kwargs)
            return func
        else:
            return getattr(self._statsd, item)

statsd = StatsClient(
    _statsd.StatsClient(prefix=os.getenv("GOVUK_STATSD_PREFIX")))

import os
import statsd as _statsd


__all__ = ['statsd']


class StatsClient(object):
    """Wrap statsd.StatsClient to allow data_set to be added to stat"""
    def __init__(self, statsd):
        self._statsd = statsd

    def __getattr__(self, item):
        if item in ['timer', 'timing', 'incr', 'decr', 'gauge']:
            def func(stat, *args, **kwargs):
                data_set = kwargs.pop('data_set', 'unknown')
                stat = '%s.%s' % (data_set, stat)

                return getattr(self._statsd, item)(stat, *args, **kwargs)
            return func
        else:
            return getattr(self._statsd, item)

statsd = StatsClient(
    _statsd.StatsClient(prefix=os.getenv(
        "GOVUK_STATSD_PREFIX", "pp.apps.backdrop")))

Add a prefix to the statsd key
Add a prefix to the statsd key

We have loads of stats at the top leve of our statsd stats in graphite.
It makes looking for things that aren't created by backdrop really
hard.
