This package enables OpenTracing support for SQLAlchemy.
Run the following command:
$ pip install sqlalchemy_opentracing
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)
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.