Skip to content

Commit e0189e2

Browse files
andremmxrmx
andauthored
Improves aiohttp_client code snippet (#3306)
Co-authored-by: Riccardo Magliocchetti <[email protected]>
1 parent 2f4d4c5 commit e0189e2

File tree

1 file changed

+15
-7
lines changed
  • instrumentation/opentelemetry-instrumentation-aiohttp-client/src/opentelemetry/instrumentation/aiohttp_client

1 file changed

+15
-7
lines changed

instrumentation/opentelemetry-instrumentation-aiohttp-client/src/opentelemetry/instrumentation/aiohttp_client/__init__.py

+15-7
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,29 @@
2222
2323
.. code:: python
2424
25+
import asyncio
2526
import aiohttp
2627
from opentelemetry.instrumentation.aiohttp_client import create_trace_config
2728
import yarl
2829
2930
def strip_query_params(url: yarl.URL) -> str:
3031
return str(url.with_query(None))
3132
32-
async with aiohttp.ClientSession(trace_configs=[create_trace_config(
33+
async def get(url):
34+
async with aiohttp.ClientSession(trace_configs=[create_trace_config(
3335
# Remove all query params from the URL attribute on the span.
3436
url_filter=strip_query_params,
35-
)]) as session:
36-
async with session.get(url) as response:
37-
await response.text()
37+
)]) as session:
38+
async with session.get(url) as response:
39+
await response.text()
40+
41+
asyncio.run(get("https://example.com"))
3842
3943
Instrumenting all client sessions:
4044
4145
.. code:: python
4246
47+
import asyncio
4348
import aiohttp
4449
from opentelemetry.instrumentation.aiohttp_client import (
4550
AioHttpClientInstrumentor
@@ -49,9 +54,12 @@ def strip_query_params(url: yarl.URL) -> str:
4954
AioHttpClientInstrumentor().instrument()
5055
5156
# Create a session and make an HTTP get request
52-
async with aiohttp.ClientSession() as session:
53-
async with session.get(url) as response:
54-
await response.text()
57+
async def get(url):
58+
async with aiohttp.ClientSession() as session:
59+
async with session.get(url) as response:
60+
await response.text()
61+
62+
asyncio.run(get("https://example.com"))
5563
5664
Configuration
5765
-------------

0 commit comments

Comments
 (0)