OpenTracing support for Flask applications
Project description
Description-Content-Type: UNKNOWN
Description: #################
Flask-OpenTracing
#################
This package enables distributed tracing in Flask applications via `The 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 python `source code`_.
.. _The OpenTracing Project: http://opentracing.io/
.. _source code: https://github.com/opentracing/opentracing-python
Installation
============
Run the following command:
.. code-block::
$ pip install Flask-Opentracing
Usage
=====
This Flask extension allows for tracing of Flask apps using the OpenTracing API. All
that it requires is for a FlaskTracing 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 `flask.Request` that you wish to set as tags on the created span
Initialize
----------
`FlaskTracer` wraps the tracer instance that's supported by opentracing. To create a `FlaskTracer` object, you can either pass in a tracer object directly or a callable that returns the tracer object. For example:
.. code-block:: python
import opentracing
from flask_opentracing import FlaskTracer
opentracing_tracer = ## some OpenTracing tracer implementation
tracer = FlaskTracer(opentracing_tracer, ...)
or
.. code-block:: python
import opentracing
from flask_opentracing import FlaskTracer
def initialize_tracer():
...
return opentracing_tracer
tracer = FlaskTracer(initialize_tracer, ...)
Trace All Requests
------------------
.. code-block:: python
import opentracing
from flask_opentracing import FlaskTracer
app = Flask(__name__)
opentracing_tracer = ## some OpenTracing tracer implementation
tracer = FlaskTracer(opentracing_tracer, True, app, [optional_args])
Trace Individual Requests
-------------------------
.. code-block:: python
import opentracing
from flask_opentracing import FlaskTracer
app = Flask(__name__)
opentracing_tracer = ## some OpenTracing tracer implementation
tracer = FlaskTracer(opentracing_tracer)
@app.route('/some_url')
@tracer.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 `FlaskTracer.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:
.. code-block:: python
@tracer.trace()
def some_view_func(request):
new_request = some_http_request
current_span = tracer.get_span(request)
text_carrier = {}
opentracing_tracer.inject(span, opentracing.Format.TEXT_MAP, text_carrier)
for k, v in text_carrier.iteritems():
request.add_header(k,v)
... # make request
Examples
========
See `examples`_ to view and run an example of two Flask applications
with integrated OpenTracing tracers.
.. _examples: https://github.com/opentracing-contrib/python-flask/tree/master/example
Further Information
===================
If you're interested in learning more about the OpenTracing standard, please visit `opentracing.io`_ or `join the mailing list`_. If you would like to implement OpenTracing in your project and need help, feel free to send us a note at `community@opentracing.io`_.
.. _opentracing.io: http://opentracing.io/
.. _join the mailing list: http://opentracing.us13.list-manage.com/subscribe?u=180afe03860541dae59e84153&id=19117aa6cd
.. _community@opentracing.io: community@opentracing.io
Platform: any
Classifier: Environment :: Web Environment
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: BSD License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Description: #################
Flask-OpenTracing
#################
This package enables distributed tracing in Flask applications via `The 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 python `source code`_.
.. _The OpenTracing Project: http://opentracing.io/
.. _source code: https://github.com/opentracing/opentracing-python
Installation
============
Run the following command:
.. code-block::
$ pip install Flask-Opentracing
Usage
=====
This Flask extension allows for tracing of Flask apps using the OpenTracing API. All
that it requires is for a FlaskTracing 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 `flask.Request` that you wish to set as tags on the created span
Initialize
----------
`FlaskTracer` wraps the tracer instance that's supported by opentracing. To create a `FlaskTracer` object, you can either pass in a tracer object directly or a callable that returns the tracer object. For example:
.. code-block:: python
import opentracing
from flask_opentracing import FlaskTracer
opentracing_tracer = ## some OpenTracing tracer implementation
tracer = FlaskTracer(opentracing_tracer, ...)
or
.. code-block:: python
import opentracing
from flask_opentracing import FlaskTracer
def initialize_tracer():
...
return opentracing_tracer
tracer = FlaskTracer(initialize_tracer, ...)
Trace All Requests
------------------
.. code-block:: python
import opentracing
from flask_opentracing import FlaskTracer
app = Flask(__name__)
opentracing_tracer = ## some OpenTracing tracer implementation
tracer = FlaskTracer(opentracing_tracer, True, app, [optional_args])
Trace Individual Requests
-------------------------
.. code-block:: python
import opentracing
from flask_opentracing import FlaskTracer
app = Flask(__name__)
opentracing_tracer = ## some OpenTracing tracer implementation
tracer = FlaskTracer(opentracing_tracer)
@app.route('/some_url')
@tracer.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 `FlaskTracer.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:
.. code-block:: python
@tracer.trace()
def some_view_func(request):
new_request = some_http_request
current_span = tracer.get_span(request)
text_carrier = {}
opentracing_tracer.inject(span, opentracing.Format.TEXT_MAP, text_carrier)
for k, v in text_carrier.iteritems():
request.add_header(k,v)
... # make request
Examples
========
See `examples`_ to view and run an example of two Flask applications
with integrated OpenTracing tracers.
.. _examples: https://github.com/opentracing-contrib/python-flask/tree/master/example
Further Information
===================
If you're interested in learning more about the OpenTracing standard, please visit `opentracing.io`_ or `join the mailing list`_. If you would like to implement OpenTracing in your project and need help, feel free to send us a note at `community@opentracing.io`_.
.. _opentracing.io: http://opentracing.io/
.. _join the mailing list: http://opentracing.us13.list-manage.com/subscribe?u=180afe03860541dae59e84153&id=19117aa6cd
.. _community@opentracing.io: community@opentracing.io
Platform: any
Classifier: Environment :: Web Environment
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: BSD License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
Classifier: Topic :: Software Development :: Libraries :: Python Modules
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 Flask-OpenTracing-0.1.8.tar.gz
.
File metadata
- Download URL: Flask-OpenTracing-0.1.8.tar.gz
- Upload date:
- Size: 6.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1babcb000b90cb217bf36372a1326d24c7e3c65805fa8e67850ab39528fab0db |
|
MD5 | 401ef2d9e34122b55856e95934b02699 |
|
BLAKE2b-256 | 948c6142dca2f70069ae7457890b373e4f1cfd4114f819a5886e092dc5d9a84e |
File details
Details for the file Flask_OpenTracing-0.1.8-py2.py3-none-any.whl
.
File metadata
- Download URL: Flask_OpenTracing-0.1.8-py2.py3-none-any.whl
- Upload date:
- Size: 8.7 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f322b3e05fdee62ca6cc19d5d683a5669672af30590a48099be28ed5cb902414 |
|
MD5 | 016ef610af93ec050e5a34121bce3355 |
|
BLAKE2b-256 | 5d8c59ddf49c45b157516d09ee0cd9dd1304c5531146180eb27dc4c715a381e1 |