Skip to content

andrey-avdeev/telemetry

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Telemetry

Description

Simple wrapper of loguru and statsd.

Easy to use telemetry is simple

Easy to visualize statsd integration

Installation

pip install git+https://github.com/andrey-avdeev/telemetry#egg=telemetry

Configuration

Telemetry looking for these environment variables or use default values:

  • LOG_LEVEL=DEBUG
  • STATSD_ON=false
  • STATSD_HOST=localhost
  • STATSD_PORT=8125
  • STATSD_PREFIX=dev.app
  • STATSD_MAXUDPSIZE=512

Usage

Decorator

@tel.catch is equivalent of:

tel.method_call(function._name)
try:
    function()
    tel.method_success(function._name, timedelta=execution_time)
except Exception as err:
    tel.method_error(function._name, err)
from telemetry import telemetry

tel = telemetry(__name__)

class Monty:
    
    @tel.catch
    def python(self):
        print('python')
    
    @tel.catch(reraise=False)
    def java(self):
        raise Exception('java')

monty = Monty()

monty.python() # output: python
monty.java() # exception will be suppressed

Context Manager

with tel: is equivalent of:

tel.method_call(function._name)
try:
    function()
    tel.method_success(function._name, timedelta=execution_time)
except Exception as err:
    tel.method_error(function._name, err)
from telemetry import telemetry

tel = telemetry(__name__)

class Monty:
    
    def python(self):
        with tel:
            print('python')
    
    def java(self):
        with telemetry('java'):
            raise Exception('java')
    
    @tel.catch
    def cpp(self):
        with telemetry(__name__, method='cpp'):
            print('cpp')

    def php(self):
        with telemetry(__name__, reraise=False):
            raise Exception('php')


monty = Monty()

monty.python() # output: python  
monty.java() # output: Exception
monty.cpp() # ouput: cpp
monty.php() # exception will be suppressed

Direct

from telemetry import telemetry

tel = telemetry(__name__)

tel.method_call('method_name')
tel.method_success('method_name')

try:
    1/0
except Exception as err:
    tel.method_error('method_name', err)

tel.log.debug('debug message') # access to loguru's logger directly
tel.stat.inc('service_name.eval.call.total', 1) # access to statsd client directly

Infrastructure

You can up grafana and statsd+carbon+grafana by docker-compose file They will be available on 3000 and 80 ports

git clone https://github.com/andrey-avdeev/telemetry.git && \
cd telemetry && \
docker-compose up

How to install docker

How to install docker-compose

How to connect grafana to graphite