混沌工具包opentracing扩展

chaostoolkit-opentracing的Python项目详细描述


用于开放跟踪的Chaos工具包扩展

Build StatusPython versions

这个项目是chaos工具包的一个扩展,用于OpenTracing

下面是一个关于jaeger后端的示例。

OpenTracing

安装

这个包需要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的规则。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java使用EntityManager有没有更有效的习惯用法?   Android上的java Google应用程序引擎(GAE)响应代码和cookie   如何在Java中创建单元测试?   java从DB获取特定列的最新行   java替换所有悬空元字符   java使用Hibernate删除SQL表中的数据   swing显示JComponent对象Java   java在确认内容类型后如何将URL保存到文件?   javascript如何从段落中选择大量单词?(硒)   java在Linux上使用BundleEnableTiveCode不起作用   java使用日志似然性来比较不同的mallet主题模型?   java无法在Tomcat7上运行Spring Boot 2.0:“由于缺少ServletWebServerFactory bean,无法启动ServletWebServerApplicationContext。”   java有办法显式引用非静态内部类实例吗?   java如何使用Spring的NamedParameterJdbcTemplate在MySQL数据库中创建和删除表?