Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,29 @@

.. code:: python

import asyncio
import aiohttp
from opentelemetry.instrumentation.aiohttp_client import create_trace_config
import yarl

def strip_query_params(url: yarl.URL) -> str:
return str(url.with_query(None))

async with aiohttp.ClientSession(trace_configs=[create_trace_config(
async def get(url):
async with aiohttp.ClientSession(trace_configs=[create_trace_config(
# Remove all query params from the URL attribute on the span.
url_filter=strip_query_params,
)]) as session:
async with session.get(url) as response:
await response.text()
)]) as session:
async with session.get(url) as response:
await response.text()

asyncio.run(get("https://example.com"))

Instrumenting all client sessions:

.. code:: python

import asyncio
import aiohttp
from opentelemetry.instrumentation.aiohttp_client import (
AioHttpClientInstrumentor
Expand All @@ -49,9 +54,12 @@ def strip_query_params(url: yarl.URL) -> str:
AioHttpClientInstrumentor().instrument()

# Create a session and make an HTTP get request
async with aiohttp.ClientSession() as session:
async with session.get(url) as response:
await response.text()
async def get(url):
async with aiohttp.ClientSession() as session:
async with session.get(url) as response:
await response.text()

asyncio.run(get("https://example.com"))

Configuration
-------------
Expand Down