flask jaeger
Project description
目的
方便flask app链路追踪集成
与flask-opentracing的不同之处:
flask-opentracing只支持视图前后进行trace,此插件支持任何地方trace
初始化
app = Flask(__name__)
app.config['SERVICE_NAME'] = "test_flask_jaeger"
app.config['JAEGER_HOST'] = '192.168.0.220'
tracer = FlaskJaeger(app)
打log
方式1
@tracer.log_decorator(trace_info={"route": "root api"})
方式2
tracer.trace_info(func_name=<your func name>, info={"trace_info": "测试测试"})
跨多个请求的时候
例如:
requ1返回一个jaeger_trace_id为123321 requ2返回一个jaeger_trace_id为456654
但是requ1和requ2都是hello_a() function下发出来的,那么就不会形成一个堆栈,解决方法:
response = requests.post("http://127.0.0.1:5000/", json={CUSTOM_TRACE_ID: trace_id})
jaeger_trace_id = response.headers.get(JAEGER_TRACE_ID)
print(jaeger_trace_id)
response = requests.post("http://127.0.0.1:5000/more", json={CUSTOM_TRACE_ID: trace_id}, headers={JAEGER_TRACE_ID: jaeger_trace_id}) # 使用上一个请求返回的jaeger_trace_id
print(response.headers.get(JAEGER_TRACE_ID))
可以看到,这两个请求返回的jaeger_trace_id都是一样的。
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
flask_jaeger-1.0.1.tar.gz
(3.8 kB
view hashes)
Built Distribution
Close
Hashes for flask_jaeger-1.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6ef9408d50ecf90387a918caf2def6d56053ed3b2e8fb90cff8f96898ba2a72b |
|
MD5 | d4816217cb0f79e5d8eb6b19894f5daa |
|
BLAKE2b-256 | 4f68c2cb3bf884f6c090957d0781fbd56d269f4fb5722949520c87b35e46845a |