Chaos Toolkit OpenTracing Extension
Project description
Chaos Toolkit Extension for Open Tracing
This project is an extension for the Chaos Toolkit for OpenTracing.
Here is an example of what it could look like with the Jaeger backend.
Install
This package requires Python 3.5+
To be used from your experiment, this package must be installed in the Python environment where chaostoolkit already lives.
$ pip install -U chaostoolkit-opentracing
Usage
Currently, this extension only provides control support to send traces to your provider during the execution of the experiment. It does not yet expose any probes or actions per-se.
To use this control, add the following section to your experiment, at the top-level:
{
"configuration": {
"tracing_provider": "jaeger",
"tracing_host": "127.0.0.1",
"tracing_port": 6831
},
"controls": [
{
"name": "opentracing",
"provider": {
"type": "python",
"module": "chaostracing.control"
}
}
]
}
This will automatically create a Jaeger client to emit traces onto the
address 127.0.0.1:6831
.
Use from other extensions
You may also access the tracer from other extensions as follows:
import opentracing
def some_function(...):
opentracing.tracer
As not all Open Tracing providers support yet to fetch the active span from the tracer (Open Tracing 2 specification), we attach the following attributes to the tracer instance:
tracer.experiment_span # span during the lifetime of the experiment
tracer.hypothesis_span # span during the lifetime of the hypothesis
tracer.method_span # span during the lifetime of the method
tracer.rollback_span # span during the lifetime of the rollback
tracer.activity_span # span during the lifetime of an activity
For instance, assuming you have an extension that makes a HTTP call you want to trace specifically, you could do this from your extension's code:
import opentracing
import requests
def my_activity(...):
headers = {}
tracer = opentracing.tracer
parent_span = tracer.activity_span
span = 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()
Because the opentracing exposes a noop tracer when non has been initialized, it should be safe to have that code in your extensions without having to determine if the extension has been enabled in the experiment.
Open Tracing Provider Support
For now, only the Jaeger tracer is supported but other backends will be added as need be in the future.
Jaeger tracer
To install the necessary dependencies for the Jaeger tracer, please run:
$ pip install chaostoolkit-opentracing[jaeger]
Unfortunately, the Jaeger client does not yet support Open Tracing 2.0.
Test
To run the tests for the project execute the following:
$ pytest
Contribute
If you wish to contribute more functions to this package, you are more than welcome to do so. Please, fork this project, make your changes following the usual PEP 8 code style, sprinkling with tests and submit a PR for review.
The Chaos Toolkit projects require all contributors must sign a Developer Certificate of Origin on each commit they would like to merge into the master branch of the repository. Please, make sure you can abide by the rules of the DCO before submitting a PR.
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
Built Distribution
File details
Details for the file chaostoolkit-opentracing-0.1.2.tar.gz
.
File metadata
- Download URL: chaostoolkit-opentracing-0.1.2.tar.gz
- Upload date:
- Size: 11.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.5.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ba049cfd2745b50f9e4942356f1d4a84cb068439b428e75af60be10c5e0053bd |
|
MD5 | a26cecae9d1bc8241c5b47ec42566b5a |
|
BLAKE2b-256 | 6ac209acb125621854edf8053c6defee2b7540e964ebd12f8a3fb0edb514fe69 |
File details
Details for the file chaostoolkit_opentracing-0.1.2-py3-none-any.whl
.
File metadata
- Download URL: chaostoolkit_opentracing-0.1.2-py3-none-any.whl
- Upload date:
- Size: 5.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.5.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b1603b0a220399b0ce3a42295c37e6e9053587953a529f250af2c564fcef1fab |
|
MD5 | 8622c77486a81fa2784c6b634d89f9cd |
|
BLAKE2b-256 | 440a46f5bb3bee5e3aef84de0240321ccedc9be6f59f1cace6e78363cc995f68 |