An zipkin extension for Flask based on py_zipkin.
Project description
flask-zipkin
a flask zipkin extension based on py_zipkin.
Installation
pip install flask_zipkin
usage
you can simply use it as other flask extensions.
from flask_zipkin import Zipkin
zipkin = Zipkin(app, sample_rate=10)
app.config['ZIPKIN_DSN'] = "http://127.0.0.1:9411/api/v1/spans"
Advance Usage
you could gen a header to pass it to other services, the downstream service will recieve this header.
@bp.route('/')
def hello():
headers = {}
headers.update(zipkin.create_http_headers_for_new_span())
r = requests.get('http://localhost:5001', headers=headers)
return r.text
flask_zipkin
will use http transport by default. You could define a transport, like:
@zipkin.transport_handler
def default_handler(self, encoded_span):
#body = str.encode('\x0c\x00\x00\x00\x01') + encoded_span
return requests.post(
'your transport dsn',
data=encoded_span,
headers={'Content-Type': 'application/x-thrift'},
)
flask_zipkin
eats all transport exception by default. You could define an exception handler, like:
@zipkin.transport_exception_handler
def default_ex_handler(self, ex):
raise ex
and also, you could exempt some views, like:
@zipkin.exempt
@bp.route('/')
def hello():
return 'hello world'
add key, value for your tracing record, like:
zipkin.update_tags(id=1, user_id=2)
app configs
ZIPKIN_DISABLE
disable zipkin tracking if value is True
ZIPKIN_DSN
http transport dsn: such as http://localhost:9411/api/v1/spans
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for Flask_Zipkin-0.0.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9d4fd5216ce412e65468c524c909c9ebcb527ee3c21922c79b027ed218d7f175 |
|
MD5 | a91565319151a2a885940ad8741f338a |
|
BLAKE2b-256 | d518d53b64c402f1c7e870020d4393c8322a06b6cb22c29faaf26c0a513d1f37 |