a flask zipkin extension based on py_zipkin.
pip install flask_zipkinyou 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"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.textflask_zipkin will use http transport by default. You could define a transport, like:
@zipkin.transport_handler
def default_handler(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(ex):
raise exand 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)ZIPKIN_DISABLE disable zipkin tracking if value is True
ZIPKIN_DSN http transport dsn: such as http://localhost:9411/api/v1/spans