OpenTracing support for Bottle applications
Project description
Bottle-OpenTracing
This package enables distributed tracing in Bottle applications via The OpenTracing Project
.
It is heavily influenced by the Flask Opentracing implementation.
Installation
Run the following command:
$ pip install Bottle-Opentracing
Usage
This Bottle extension allows for tracing of Bottle apps using the OpenTracing API. All
that it requires is for a BottleTracing
tracer to be initialized using an
instance of an OpenTracing tracer. You can either trace all requests to your site, or use function decorators to trace certain individual requests.
Note: optional_args
in both cases are any number of attributes (as strings) of bottle.Request
that you wish to set as tags on the created span
Initialize
BottleTracing
wraps the tracer instance that's supported by opentracing. To create a BottleTracing
object, you can either pass in a tracer object directly or a callable that returns the tracer object. For example:
import opentracing
from bottle_opentracing import BottleTracing
opentracing_tracer = ## some OpenTracing tracer implementation
tracing = BottleTracing(opentracing_tracer, ...)
or
import opentracing
from bottle_opentracing import BottleTracing
def initialize_tracer():
...
return opentracing_tracer
tracing = BottleTracing(initialize_tracer, ...)
Trace All Requests
import opentracing
from bottle_opentracing import BottleTracing
app = bottle.app()
opentracing_tracer = ## some OpenTracing tracer implementation
tracing = BottleTracing(opentracing_tracer, True, app, [optional_args])
Trace Individual Requests
import opentracing
from bottle_opentracing import BottleTracing
app = bottle.app()
opentracing_tracer = ## some OpenTracing tracer implementation
tracing = BottleTracing(opentracing_tracer)
@app.get('/some_url')
@tracing.trace(optional_args)
def some_view_func():
...
return some_view
Accessing Spans Manually
In order to access the span for a request, we've provided an method BottleTracing.get_span(request)
that returns the span for the request, if it is exists and is not finished. This can be used to log important events to the span, set tags, or create child spans to trace non-RPC events. If no request is passed in, the current request will be used.
Tracing an RPC
If you want to make an RPC and continue an existing trace, you can inject the current span into the RPC. For example, if making an http request, the following code will continue your trace across the wire:
@tracing.trace()
def some_view_func(request):
new_request = some_http_request
current_span = tracing.get_span(request)
text_carrier = {}
opentracing_tracer.inject(span, opentracing.Format.TEXT_MAP, text_carrier)
for k, v in text_carrier.iteritems():
new_request.add_header(k,v)
... # make request
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
File details
Details for the file Bottle-OpenTracing-0.0.5.tar.gz
.
File metadata
- Download URL: Bottle-OpenTracing-0.0.5.tar.gz
- Upload date:
- Size: 6.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | dd5782fb5db46efc98ca7461e31e4596d52a2fde50023a0bdb71bb1d9614583c |
|
MD5 | bda0e87d9269e6e19e448dbf3cb6899b |
|
BLAKE2b-256 | 40f1406b4f5765fb50b23d37aa1ef03956665c00e9955177c787daac61a91446 |