Instrumenting custom Python code

Opbeat instruments a host of libraries out of the box, but sometimes you need to know how long a specific function took or how often it gets called.

You can apply the decorator @opbeat.trace() to achieve exactly that. It can also be used as a context manager in the following way:

import opbeat

@opbeat.trace()
def coffee_maker(strength):
    fetch_water()

    with opbeat.trace('near-to-machine'):
        insert_filter()
        for i in range(strengh):
            pour_coffee()

        start_drip()

    fresh_pots()

Note: Remember to have parenthesis at the end, like so @opbeat.trace().

The Opbeat interface will show something like the following:

Custom Instrumentation