Judgment Labs Logo
Other

SQLAlchemy

Trace SQLAlchemy database spans with Judgment.

SQLAlchemy tracing uses the standard OpenTelemetry SQLAlchemy instrumentation and routes database spans through Judgment.

uv add judgeval sqlalchemy opentelemetry-instrumentation-sqlalchemy
pip install judgeval sqlalchemy opentelemetry-instrumentation-sqlalchemy
sqlalchemy_tracing.py
from judgeval import Tracer
from opentelemetry.instrumentation.sqlalchemy import SQLAlchemyInstrumentor
from sqlalchemy import create_engine, text

Tracer.init(project_name="sqlalchemy_app")

engine = create_engine("sqlite:///:memory:")
SQLAlchemyInstrumentor().instrument(engine=engine)

with engine.connect() as connection:
    connection.execute(text("select 1"))

Tracer.force_flush()

On this page

No Headings