Package: pyramid-opentracing
This package enables distributed tracing in Pyramid projects viaThe OpenTracing Project. Once a production system contends with real concurrency or splits into many services, crucial (and formerly easy) tasks become difficult: user-facing latency optimization, root-cause analysis of backend errors, communication about distinct pieces of a now-distributed system, etc. Distributed tracing follows a request on its journey from inception to completion from mobile/browser all the way to the microservices.As core services and libraries adopt OpenTracing, the application builder is no longer burdened with the task of adding basic tracing instrumentation to their own code. In this way, developers can build their applications with the tools they prefer and benefit from built-in tracing instrumentation. OpenTracing implementations exist for major distributed tracing systems and can be bound or swapped with a one-line configuration change.If you want to learn more about the underlying python API, visit the pythonsource code.If you are migrating from the 0.x series, you may want to read the list ofbreaking changes.InstallationRun the following command:$ pip install pyramid_opentracingSetting up Tracing for All RequestsIn order to implement tracing in your system (for all the requests), add the following lines of code to your site’s Configuration section to enable the tracing tween:# OpenTracing settings# defaults to Trueconfig.add_attributes({'ot.trace_all':True})# defaults to []# only valid if 'opentracing_trace_all' == Trueconfig.add_attributes({'ot.traced_attributes':['host','method',...]})# an optional module-level callable invoked after Span is created, taking# span and request as parameters.config.add_attributes({'ot.start_span_cb':'my_main_module.start_span_cb'})# One valid underlying OpenTracing implementation as# one either ONE of these three values:# 1. A PyramidTracing object.config.add_attributes({'ot.tracing':PyramidTracing(my_ot_tracer)})# 2. A module-level callable, invoked once, returning a PyramidTracing#    and receiving the settings, such as: create_tracing(**settings).config.add_attributes({'ot.tracing_callable','my_main_module.utils.create_tracing')# 3. OR a module-level callable, invoked once, returning an opentracing#    compliant Tracer with optional parameters.config.add_attributes({'ot.tracer_callable','opentracing.Tracer'})config.add_attributes({'ot.tracer_parameters',...})# enable the tweenconfig.include('pyramid_opentracing')Alternatively, you can configure the tween through an INI file:[app:myapp]ot.trace_all=trueot.start_span_cb=my_main_module.start_span_cbot.traced_attributes=hostmethodot.tracing_callable=my_main_module.utils.create_tracingpyramid.includes=pyramid_opentracingOnce the tween has been included,ifot.tracingwas not directly set, a new instance will be created and will exist inregistry.settings['ot.tracing']for any further consumption.Note:Valid request attributes to trace are listed [here](http://docs.pylonsproject.org/projects/pyramid/en/latest/api/request.html#pyramid.request.Request). When you trace an attribute, this means that created spans will have tags with the attribute name and the request’s value.Tracing Individual RequestsIf you don’t want to trace all requests to your site, you can use function decorators to trace individual view functions. This can be done by managing a globally uniquePyramidTracingobject yourself, and then adding the following lines of code to  any file that has view functions:# get_tracer() should return a globally-unique PyramidTracing object.frommy_tracing_modimportget_tracingtracing=get_tracing()# put the decorator after @view_config, if used@tracing.trace(optional_args)defsome_view_func(request):...#do some stuffThis tracing method doesn’t use the tween, so there’s no need to include that one.The optional arguments allow for tracing of request attributes. For example, if you want to trace metadata, you could pass in@tracing.trace(‘headers’)and request.headers would be set as a tag on all spans for this view function.ExamplesHere is antween exampleof a Pyramid application that uses the Pyramid tween to log all
requests:Here is anclient server exampleof an application that acts as both a client and server,
with a manually managed tracer (you will need to install thewaitressmodule).Other examples are included under the examples directrory.Breaking changes from 0.xStarting with the 1.0 version, a few changes have taken place from previous versions:PyramidTracerhas been renamed toPyramidTracing, althoughPyramidTracercan be used still as a deprecated name.ot.base_tracerandot.base_tracer_funcstill work, but have been deprecated.When using the Tween layer,ot.trace_alldefaults toTrue.When noopentracing.Traceris provided,PyramidTracingwill rely on the
global tracer.Further InformationIf you’re interested in learning more about the OpenTracing standard, please visitopentracing.ioorjoin the mailing list. If you would like to implement OpenTracing in your project and need help, feel free to send us a note atcommunity@opentracing.io.