Skip to content

Commit 27d5d93

Browse files
andremmemdnetoxrmx
authored
Improve asyncpg instrumentation example (#3349)
Co-authored-by: Emídio Neto <[email protected]> Co-authored-by: Riccardo Magliocchetti <[email protected]>
1 parent 3d37106 commit 27d5d93

File tree

1 file changed

+18
-3
lines changed
  • instrumentation/opentelemetry-instrumentation-asyncpg/src/opentelemetry/instrumentation/asyncpg

1 file changed

+18
-3
lines changed

instrumentation/opentelemetry-instrumentation-asyncpg/src/opentelemetry/instrumentation/asyncpg/__init__.py

+18-3
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,31 @@
1919
Usage
2020
-----
2121
22+
Start PostgreSQL:
23+
24+
::
25+
26+
docker run -e POSTGRES_USER=user -e POSTGRES_PASSWORD=password -e POSTGRES_DATABASE=database -p 5432:5432 postgres
27+
28+
Run instrumented code:
29+
2230
.. code-block:: python
2331
32+
import asyncio
2433
import asyncpg
2534
from opentelemetry.instrumentation.asyncpg import AsyncPGInstrumentor
2635
2736
# You can optionally pass a custom TracerProvider to AsyncPGInstrumentor.instrument()
2837
AsyncPGInstrumentor().instrument()
29-
conn = await asyncpg.connect(user='user', password='password',
30-
database='database', host='127.0.0.1')
31-
values = await conn.fetch('''SELECT 42;''')
38+
39+
async def main():
40+
conn = await asyncpg.connect(user='user', password='password')
41+
42+
await conn.fetch('''SELECT 42;''')
43+
44+
await conn.close()
45+
46+
asyncio.run(main())
3247
3348
API
3449
---

0 commit comments

Comments
 (0)