mozilla

Decorators

This module contains a Heka decorator base class and some additional helper code. The primary reason for these abstractions is ‘deferred configuration’. Decorators are evaluated by Python at import time, but often the configuration needed for a Heka client, which might negate (or change) the behavior of a Heka decorator, isn’t available until later, after some config parsing code has executed. This code provides a mechanism to have a function get wrapped in one way (or not at all) when the decorator is originally evaluated, but then to be wrapped differently once the config has loaded and the desired final behavior has been established.

class heka.decorators.base.HekaDecorator(*args, **kwargs)[source]

Base class for Heka decorators

Designed to support ‘rebinding’ of the actual decorator method once Heka configuration has actually been loaded. The first time the decorated function is invoked, the predicate method will be called. If the result is True, then heka_call (intended to be implemented by subclasses) will be used as the decorator. If the predicate returns False, then _invoke (which by default does nothing but call the wrapped function) will be used as the decorator.

heka_call(*args, **kwargs)[source]

Actual heka activity happens here. Implemented by subclasses.

predicate()[source]

Predicate used to determine if function is rebound during the rebind process

True return value will rebind such that self.heka_call becomes the decorator function, False will rebind such that self._invoke becomes the decorator function.

set_fn(fn)[source]

Sets the function and stores the full dotted notation fn name for later use.#

Parameters:fn – Actual function that we are decorating.
heka.decorators.util.return_fq_name(func, klass=None)[source]

Resolve a fully qualified name for a function or method

class heka.decorators.stats.incr_count(*args, **kwargs)[source]

Lazily decorate any callable w/ a wrapper that will increment a heka counter whenever the callable is invoked.

class heka.decorators.stats.timeit(*args, **kwargs)[source]

Lazily decorate any callable with a heka timer.