mirror of
https://github.com/open-telemetry/opentelemetry-python-contrib.git
synced 2025-08-03 04:10:48 +08:00
Improve asyncpg instrumentation example (#3349)
Co-authored-by: Emídio Neto <9735060+emdneto@users.noreply.github.com> Co-authored-by: Riccardo Magliocchetti <riccardo.magliocchetti@gmail.com>
This commit is contained in:

committed by
GitHub

parent
3d37106115
commit
27d5d93a6a
@ -19,16 +19,31 @@ This library allows tracing PostgreSQL queries made by the
|
||||
Usage
|
||||
-----
|
||||
|
||||
Start PostgreSQL:
|
||||
|
||||
::
|
||||
|
||||
docker run -e POSTGRES_USER=user -e POSTGRES_PASSWORD=password -e POSTGRES_DATABASE=database -p 5432:5432 postgres
|
||||
|
||||
Run instrumented code:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
import asyncio
|
||||
import asyncpg
|
||||
from opentelemetry.instrumentation.asyncpg import AsyncPGInstrumentor
|
||||
|
||||
# You can optionally pass a custom TracerProvider to AsyncPGInstrumentor.instrument()
|
||||
AsyncPGInstrumentor().instrument()
|
||||
conn = await asyncpg.connect(user='user', password='password',
|
||||
database='database', host='127.0.0.1')
|
||||
values = await conn.fetch('''SELECT 42;''')
|
||||
|
||||
async def main():
|
||||
conn = await asyncpg.connect(user='user', password='password')
|
||||
|
||||
await conn.fetch('''SELECT 42;''')
|
||||
|
||||
await conn.close()
|
||||
|
||||
asyncio.run(main())
|
||||
|
||||
API
|
||||
---
|
||||
|
Reference in New Issue
Block a user