Package: chaostoolkit-opentracing
Chaos Toolkit Extension for Open TracingThis project is an extension for the Chaos Toolkit forOpenTracingandOpenTelemetry.Here is an example of what it could look like with the Jaeger backend.InstallThis package requires Python 3.6+To be used from your experiment, this package must be installed in the Python
environment wherechaostoolkitalready lives.$ pip install -U chaostoolkit-opentracingUsageThis extension provides two controls to trace your Chaos Toolkit experiment:Open TelemetryOpen Tracing (legacy)The only supported one is Open Telemetry as the Open Tracing is no longer
maintained.Open TelemetryTo enable Open Telemetry tracing, simply add the following control to
your experiment:{"controls":[{"name":"opentelemetry","provider":{"type":"python","module":"chaostracing.oltp"}}]}We suggest you make it the first extension so it runs before and after all
other extensions.To configure the various Open Telemetry settings, please use the standard
OLTP environment variables:thesdk variablestheexporter variablesMostly, you should set:OTEL_EXPORTER_OTLP_TRACES_ENDPOINTto point to your collector (for instance:http://localhost:4318/v1/traces)OTEL_EXPORTER_OTLP_TRACES_HEADERSto set any headers to pass to the exporterNOTE: This extension supports OLTP over HTTP but not gRPC.You can also instrument a variety of frameworks like this:{"controls":[{"name":"opentelemetry","provider":{"type":"python","module":"chaostracing.oltp","arguments":{"trace_httpx":true,"trace_requests":true,"trace_botocore":true}}}]}This will enable the according instrumentation automatically.AWSThis extension supports AWS X-Ray directly. Simply set the following
variable:export OTEL_VENDOR=awsThis can also be set in the configuration block:{"configuration":{"otel_vendor":"aws"}}Google Cloud Platform TracesIf you intend on using Google Cloud Platform to export your traces to, please
consider also installing the followings:$ pip install opentelemetry-exporter-gcp-trace \
    opentelemetry-resourcedetector-gcp \
    opentelemetry-propagator-gcpTo authenticate the client, you can either:setGOOGLE_APPLICATION_CREDENTIALSenvironment variablepass theotel_gcp_service_accountandotel_gcp_project_idvariables
in the configuration blockset theCHAOSTOOLKIT_OTEL_GCP_SAandCHAOSTOOLKIT_OTEL_GCP_PROJECT_IDenvironment variablesIn all cases, point to a service account which has
theroles/cloudtrace.agentrole as nthe name of the target project.Finally, set the following variable:export OTEL_VENDOR=gcpThis can also be set in the configuration block:{"configuration":{"otel_vendor":"gcp"}}Azure TracesTo use this package to send traces to Azure monitors, please install the
dependencies as follows:$ pip install chaostoolkit-opentracing[azure]Then set theAPPLICATIONINSIGHTS_CONNECTION_STRINGenvironment variable
appropriately.Finally, set the following variable:export OTEL_VENDOR=azureThis can also be set in the configuration block:{"configuration":{"otel_vendor":"azure"}}See Azure documentation for more details:https://learn.microsoft.com/en-us/python/api/overview/azure/core-tracing-opentelemetry-readmehttps://learn.microsoft.com/en-us/python/api/overview/azure/monitor-opentelemetry-exporter-readmeOther Open Telemetry vendorsOther vendors should work out of the box with the default settings. Otherwise,
feel free to open an issue.Legacy Open TracingThis extensions supports theOpen Tracingexport
format but highly recommends you to switch to Open Telemetry instead. There will
be no support for Open Tracing support.NOTE: Please see at the bottom of the page all the supported clients and
exporters this control supports.Declare within the experimentTo 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 aJaegerclient to emit traces onto the
address127.0.0.1:6831(over UDP).Declare within the settingsYou may also declare the control to be applied to all experiments by declaring
the control from within theChaos 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:pythonmodule:chaostracing.controlarguments:provider:jaegerhost:127.0.0.1port:6831propagation:b3Send traces from other extensionsYou 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:fromchaoslibimportConfiguration,Secretsimportrequestsimportopentracingdefsome_function(configuration:Configuration,secrets:Secrets):tracer=opentracing.global_tracer()scope=tracer.scope_manager.activeparent=scope.spanwithtracer.start_span("call-service1",child_of=parent)asspan: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 SupportJaeger tracerThe Jager tracer relies on the OpenTracing protocol which has now be superseded
by OpenTelemetry. However, we still provide support for it.To install the necessary dependencies for the Jaeger tracer, please run:$ pip install -U jaeger-client~=4.8Use the following configuration:{"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"}}]}TestTo run the tests for the project execute the following:$ pytestContributeIf 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
usualPEP 8code style, sprinkling with tests and submit a PR for
review.The Chaos Toolkit projects require all contributors must sign aDeveloper Certificate of Originon 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.