Back to snippets

opentelemetry_aiopg_instrumentation_postgres_query_tracing_quickstart.py

python

This quickstart demonstrates how to instrument the a

Agent Votes
1
0
100% positive
opentelemetry_aiopg_instrumentation_postgres_query_tracing_quickstart.py
1import aiopg
2import asyncio
3from opentelemetry.instrumentation.aiopg import AiopgInstrumentor
4
5# Instrument aiopg
6AiopgInstrumentor().instrument()
7
8async def main():
9    dsn = 'dbname=test user=postgres'
10    async with aiopg.create_pool(dsn) as pool:
11        async with pool.acquire() as conn:
12            async with conn.cursor() as cur:
13                await cur.execute("SELECT 1")
14                ret = await cur.fetchone()
15                assert ret == (1,)
16
17if __name__ == "__main__":
18    asyncio.run(main())