Skip to content

Failed to Instrumenting Async and Sync engine #1105

@rcourivaud

Description

@rcourivaud

Description

Hello, I have in my FastAPI two sqlalchemy engines one async and one sync. And it fails to instrument the two at the same time. According to the documentation when letting empty, it should instrument the two.
But when letting empty it's doesn't instrument nothing, no logs are in logfire interface.

logfire.configure(
    token=Config.LOGIFIRE_TOKEN,
    service_name=Config.SERVICE_NAME,
    service_version=Config.API_VERSION,
    environment=Config.APP_ENV,
    distributed_tracing=True,
)
logfire.instrument_sqlalchemy()

Above, instrument nothing. When removing and setup the instrument method in contextmanager of FastAPI
It instrument nothing too

@asynccontextmanager
async def lifespan(app: FastAPI):
    async_engine = await get_async_engine()
    engine = get_sync_engine()
    logfire.instrument_sqlalchemy()

This only instrument async

@asynccontextmanager
async def lifespan(app: FastAPI):
    async_engine = await get_async_engine()
    engine = get_sync_engine()
    logfire.instrument_sqlalchemy(engine=async_engine)
    logfire.instrument_sqlalchemy(engine=engine)

This only instrument sync

@asynccontextmanager
async def lifespan(app: FastAPI):
    async_engine = await get_async_engine()
    engine = get_sync_engine()
    logfire.instrument_sqlalchemy(engine=engine)
    logfire.instrument_sqlalchemy(engine=async_engine)

Can you help me understand or if you have any idea

Python, Logfire & OS Versions, related packages (not required)

logfire="3.16.0"
platform="macOS-15.1.1-arm64-arm-64bit-Mach-O"
python="3.13.3 (main, Apr  8 2025, 13:54:08) [Clang 16.0.0 (clang-1600.0.26.6)]"
[related_packages]
requests="2.32.3"
pydantic="2.11.0"
fastapi="0.115.12"
openai="1.78.1"
protobuf="5.29.4"
rich="14.0.0"
executing="2.2.0"
opentelemetry-api="1.33.0"
opentelemetry-exporter-otlp-proto-common="1.33.0"
opentelemetry-exporter-otlp-proto-http="1.33.0"
opentelemetry-instrumentation="0.54b0"
opentelemetry-instrumentation-asgi="0.54b0"
opentelemetry-instrumentation-asyncpg="0.54b0"
opentelemetry-instrumentation-fastapi="0.54b0"
opentelemetry-instrumentation-sqlalchemy="0.54b0"
opentelemetry-proto="1.33.0"
opentelemetry-sdk="1.33.0"
opentelemetry-semantic-conventions="0.54b0"
opentelemetry-util-http="0.54b0"

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentationgood first issueGood for newcomers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions