All Projects → opentracing-contrib → python-flask

opentracing-contrib / python-flask

Licence: BSD-3-Clause license
OpenTracing instrumentation for the Flask microframework

Programming Languages

python
139335 projects - #7 most used programming language
Makefile
30231 projects

Projects that are alternatives of or similar to python-flask

Apollo Opentracing
Performance trace your Apollo GraphQL server with Opentracing
Stars: ✭ 154 (+15.79%)
Mutual labels:  opentracing
Dd Trace Js
JavaScript APM Tracer
Stars: ✭ 212 (+59.4%)
Mutual labels:  opentracing
java-concurrent
OpenTracing-aware helpers related to java.util.concurrent
Stars: ✭ 36 (-72.93%)
Mutual labels:  opentracing
Go Stdlib
OpenTracing instrumentation for packages in the Go stdlib
Stars: ✭ 176 (+32.33%)
Mutual labels:  opentracing
Kanali
A Kubernetes Native API Management Solution
Stars: ✭ 192 (+44.36%)
Mutual labels:  opentracing
Csharp Netcore
OpenTracing instrumentation for .NET Core & .NET 5 apps
Stars: ✭ 225 (+69.17%)
Mutual labels:  opentracing
Stagemonitor
an open source solution to application performance monitoring for java server applications
Stars: ✭ 1,664 (+1151.13%)
Mutual labels:  opentracing
Petabridge.Tracing.ApplicationInsights
OpenTracing adapter for Microsoft Application Insights
Stars: ✭ 30 (-77.44%)
Mutual labels:  opentracing
Dd Trace Php
Datadog Tracing PHP Client
Stars: ✭ 203 (+52.63%)
Mutual labels:  opentracing
Dd Trace Go
A Go tracing package for Datadog APM
Stars: ✭ 244 (+83.46%)
Mutual labels:  opentracing
Jaeger Php
Jaeger Bindings for PHP OpenTracing API
Stars: ✭ 185 (+39.1%)
Mutual labels:  opentracing
Mastering Distributed Tracing
"Mastering Distributed Tracing" by Yuri Shkuro, published by Packt
Stars: ✭ 189 (+42.11%)
Mutual labels:  opentracing
Crnk Framework
JSON API library for Java
Stars: ✭ 234 (+75.94%)
Mutual labels:  opentracing
Java Specialagent
Automatic instrumentation for 3rd-party libraries in Java applications with OpenTracing.
Stars: ✭ 156 (+17.29%)
Mutual labels:  opentracing
haystack-docker
Repository with docker-compose files to start Haystack components in sandbox
Stars: ✭ 17 (-87.22%)
Mutual labels:  opentracing
Hawkular Apm
This project is now deprecated, in favor of CNCF's Jaeger (was: Distributed Tracing and Application Performance Management)
Stars: ✭ 131 (-1.5%)
Mutual labels:  opentracing
Natchez
functional tracing for cats
Stars: ✭ 214 (+60.9%)
Mutual labels:  opentracing
opentracing-gorm
OpenTracing instrumentation for GORM.
Stars: ✭ 46 (-65.41%)
Mutual labels:  opentracing
datadog-tracer-js
[DEPRECATED] OpenTracing tracer implementation for Datadog in JavaScript.
Stars: ✭ 39 (-70.68%)
Mutual labels:  opentracing
Instrumentedsql
A sql driver that will wrap any other driver and log/trace all its calls
Stars: ✭ 244 (+83.46%)
Mutual labels:  opentracing

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.

If you are migrating from the 0.x series, you may want to read the list of breaking changes.

Installation

Run the following command:

$ 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

FlaskTracing wraps the tracer instance that's supported by opentracing. To create a FlaskTracing object, you can either pass in a tracer object directly or a callable that returns the tracer object. For example:

import opentracing
from flask_opentracing import FlaskTracing

opentracing_tracer = ## some OpenTracing tracer implementation
tracing = FlaskTracing(opentracing_tracer, ...)

or

import opentracing
from flask_opentracing import FlaskTracing

def initialize_tracer():
    ...
    return opentracing_tracer

tracing = FlaskTracing(initialize_tracer, ...)

Trace All Requests

import opentracing
from flask_opentracing import FlaskTracing

app = Flask(__name__)

opentracing_tracer = ## some OpenTracing tracer implementation
tracing = FlaskTracing(opentracing_tracer, True, app, [optional_args])

Trace Individual Requests

import opentracing
from flask_opentracing import FlaskTracing

app = Flask(__name__)

opentracing_tracer = ## some OpenTracing tracer implementation
tracing = FlaskTracing(opentracing_tracer)

@app.route('/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 FlaskTracing.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

Examples

See examples to view and run an example of two Flask applications with integrated OpenTracing tracers.

This tutorial has a step-by-step guide for using Flask-Opentracing with Jaeger.

Breaking changes from 0.x

Starting with the 1.0 version, a few changes have taken place from previous versions:

  • FlaskTracer has been renamed to FlaskTracing, although FlaskTracing can be used still as a deprecated name.
  • When passing an Application object at FlaskTracing creation time, trace_all_requests defaults to True.
  • When no opentracing.Tracer is provided, FlaskTracing will rely on the global tracer.

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 [email protected].

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].