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.
Declare within the experiment
To use this control, you can declare it on a per experiment basis like this:
{
"configuration": {
"tracing_provider": "jaeger",
"tracing_host": "127.0.0.1",
"tracing_port": 6831,
"tracing_propagation": "b3"
},
"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
(over UDP).
Declare within the settings
You may also declare the control to be applied to all experiments by declaring the control from within the Chaos Toolkit settings file. In that case, you do not need to set the configuration or the controls at the experiment level and the control will be applied to every experiments you run.
controls:
opentracing:
provider:
type: python
module: chaostracing.control
arguments:
provider: jaeger
host: 127.0.0.1
port: 6831
propagation: b3
Send traces from other extensions
You may also access the tracer from other extensions as follows.
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:
from chaoslib import Configuration, Secrets
import requests
import opentracing
def some_function(configuration: Configuration, secrets: Secrets):
tracer = opentracing.global_tracer()
scope = tracer.scope_manager.active
parent = scope.span
with tracer.start_span("call-service1", child_of=parent) as 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)
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.
Please note that, Open Tracing scope cannot be shared across threads (while spans can). So, when running this in a background activity, the tracer will not actually be set to the one that was initialized.
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.2.0.tar.gz
.
File metadata
- Download URL: chaostoolkit-opentracing-0.2.0.tar.gz
- Upload date:
- Size: 13.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.6.3 requests-toolbelt/0.9.1 tqdm/4.37.0 CPython/3.5.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | db958fbc78d1c2ba3f61329fb912768f4f4c44b776ee3044483e4ced27ab4449 |
|
MD5 | 1cc42ca7e641eaacff5847da2952639a |
|
BLAKE2b-256 | 1eb78e64cf44aa3cdac4d21bb0369cd920c87848844e5790ab7e96d6a1379296 |
File details
Details for the file chaostoolkit_opentracing-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: chaostoolkit_opentracing-0.2.0-py3-none-any.whl
- Upload date:
- Size: 10.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.6.3 requests-toolbelt/0.9.1 tqdm/4.37.0 CPython/3.5.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 779d396131dde9b863ed1c6dbb6bd092c93d03824f3b7611366bd0ec9e10b157 |
|
MD5 | 1622019a3e6a980bb17571a867712f3d |
|
BLAKE2b-256 | 05a820dd53e27d0bae61f0179cb992c2fb169f51e1576c6848d06979fa8d8405 |