混沌工具包opentracing扩展
chaostoolkit-opentracing的Python项目详细描述
用于开放跟踪的Chaos工具包扩展
这个项目是chaos工具包的一个扩展,用于OpenTracing。
下面是一个关于jaeger后端的示例。
安装
这个包需要python 3.5+
要从实验中使用,此包必须安装在python中 chaostoolkit已经存在的环境。
$ pip install -U chaostoolkit-opentracing
用法
当前,此扩展仅提供控件支持,以将跟踪发送到 实验执行期间的提供者。它还没有暴露 任何探测或动作本身。
若要使用此控件,请将以下部分添加到实验中 顶层:
{"configuration":{"tracing_provider":"jaeger","tracing_host":"127.0.0.1","tracing_port":6831},"controls":[{"name":"opentracing","provider":{"type":"python","module":"chaostracing.control"}}]}
这将自动创建一个Jaeger客户端,以便向
地址127.0.0.1:6831
。
从其他扩展使用
您还可以从其他扩展访问跟踪程序,如下所示:
importopentracingdefsome_function(...):opentracing.tracer
因为并非所有打开的跟踪提供程序都支持从 tracer(open tracing 2规范),我们附加了以下属性 跟踪程序实例:
tracer.experiment_span# span during the lifetime of the experimenttracer.hypothesis_span# span during the lifetime of the hypothesistracer.method_span# span during the lifetime of the methodtracer.rollback_span# span during the lifetime of the rollbacktracer.activity_span# span during the lifetime of an activity
例如,假设您有一个扩展,可以进行所需的http调用 具体来说,您可以从扩展的代码中进行跟踪:
importopentracingimportrequestsdefmy_activity(...):headers={}tracer=opentracing.tracerparent_span=tracer.activity_spanspan=tracer.start_span("my-inner-span",child_of=parent_span)span.set_tag('http.method','GET')span.set_tag('http.url',url)span.set_tag('span.kind','client')span.tracer.inject(span,'http_headers',headers)r=requests.get(url,headers=headers)span.set_tag('http.status_code',r.status_code)span.finish()
因为opentracing在初始化non时会公开noop跟踪程序, 在扩展中包含这些代码应该是安全的,而不必 确定是否在实验中启用了扩展。
打开跟踪提供程序支持
目前,只支持jaeger跟踪程序,但是other backends 将在将来根据需要添加。
杰格示踪剂
要安装Jaeger跟踪器所需的依赖项,请运行:
$ pip install chaostoolkit-opentracing[jaeger]
不幸的是,jaeger客户端还不支持open tracing 2.0。
测试
要运行项目的测试,请执行以下操作:
$ pytest
贡献
如果您希望为这个包贡献更多的功能,那么 欢迎这么做。请,派生此项目,按照 通常的PEP 8代码样式,洒上测试并提交 回顾。
混沌工具包项目要求所有贡献者必须签署 Developer Certificate of Origin每次提交时,它们都希望合并 进入存储库的主分支。请确保你能遵守 提交PR前DCO的规则。