Skip to content

carlosalberto/python-sqlalchemy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SQLAlchemy Opentracing

This package enables OpenTracing support for SQLAlchemy.

Installation

Run the following command:

$ pip install sqlalchemy_opentracing

Getting started

Please see the examples directory. Overall, basic usage requires that a tracer gets set, an Engine (or Connection) is registered, and statements get their parent spans assigned (if any):

import sqlalchemy_opentracing

sqlalchemy_opentracing.init_tracing(tracer) # A OpenTracing compatible tracer.
sqlalchemy_opentracing.register_connectable(engine) # A valid SQLAlchemy Engine object.

with engine.begin() as conn:
    sel = select([users])
    sqlalchemy_opentracing.set_traced(sel)
    conn.execute(sel)

By default, only statements marked to be traced are taken into account (explicitly through set_traced() or implicitly when registering its parent span through set_parent_span()). Alternatively, you can enable tracing of all queries under the registered Engine/Connection:

sqlalchemy_opentracing.init_tracing(tracer, trace_all=True)
sqlalchemy_opentracing.register_connectable(engine)

# this statement will be traced too (without a parent span, though)
with engine.begin() as conn:
    sel = select([users])
    conn.execute(sel)

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.

About

OpenTracing instrumentation for SQLAlchemy

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published