{"id":24150,"library":"opencensus-ext-sqlalchemy","title":"OpenCensus SQLAlchemy Integration","description":"OpenCensus SQLAlchemy Integration provides tracing instrumentation for SQLAlchemy queries. It wraps SQLAlchemy engine events to capture spans for each executed query, including bind parameters and execution time. Version 0.1.3 is current, with irregular releases.","status":"active","version":"0.1.3","language":"python","source_language":"en","source_url":"https://github.com/census-instrumentation/opencensus-python/tree/master/contrib/opencensus-ext-sqlalchemy","tags":["opencensus","sqlalchemy","tracing","instrumentation","monitoring"],"install":[{"cmd":"pip install opencensus-ext-sqlalchemy","lang":"bash","label":"PyPI"}],"dependencies":[{"reason":"Core OpenCensus library for tracing and exporting","package":"opencensus","optional":false},{"reason":"Instrumented ORM/engine","package":"sqlalchemy","optional":false},{"reason":"Export traces to Azure Monitor (common exporter)","package":"opencensus-ext-azure","optional":true}],"imports":[{"note":"","wrong":"","symbol":"SQLAlchemyTrace","correct":"from opencensus.ext.sqlalchemy.trace import SQLAlchemyTrace"}],"quickstart":{"code":"import os\nfrom opencensus.ext.sqlalchemy.trace import SQLAlchemyTrace\nfrom sqlalchemy import create_engine\n\n# Create engine\nengine = create_engine('sqlite:///:memory:')\n\n# Instrument with OpenCensus tracer\ntracer = SQLAlchemyTrace(engine)\n\n# Now every query executed via this engine will be traced\nwith engine.connect() as conn:\n    conn.execute(\"SELECT 1\")\n","lang":"python","description":"Instrument a SQLAlchemy engine to trace queries."},"warnings":[{"fix":"Apply SQLAlchemyTrace immediately after engine creation, before first use.","message":"SQLAlchemyTrace must wrap the engine before any queries are executed. Instrumentation after connections have been created will not capture traces for those connections.","severity":"gotcha","affected_versions":"all"},{"fix":"Set up OpenCensus tracing with an exporter, e.g., 'from opencensus.trace import tracer as tracer_module' and configure with a sampler and exporter.","message":"The package does not automatically export traces; you must configure an exporter (e.g., Azure Monitor, Zipkin) via OpenCensus tracing. Without an exporter, no data is sent anywhere.","severity":"gotcha","affected_versions":"all"},{"fix":"Migrate to OpenTelemetry with opentelemetry-instrumentation-sqlalchemy.","message":"OpenCensus Python is in maintenance mode and no longer actively developed. Google recommends using OpenTelemetry instead. However, the extension still works for existing users.","severity":"deprecated","affected_versions":">=0.11.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Ensure the engine is created normally (e.g., sqlite:///:memory:) and that no custom event listeners interfere.","cause":"Triggered when SQLAlchemyTrace wraps an engine that has not been fully initialized or is a null pool.","error":"ValueError: not enough values to unpack (expected 2, got 0)"},{"fix":"Change import to: from opencensus.ext.sqlalchemy.trace import SQLAlchemyTrace","cause":"Incorrect import path; the module is actually 'opencensus.ext.sqlalchemy.trace'.","error":"AttributeError: module 'opencensus.ext.sqlalchemy' has no attribute 'trace'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}