Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
([#3941](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3941))
- `opentelemetry-instrumentation-pymongo`: Fix invalid mongodb collection attribute type
([#3942](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3942))
- `opentelemetry-instrumentation-aiohttp-client`: Update instrumentor to respect suppressing http instrumentation
([#3957](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3957))

## Version 1.38.0/0.59b0 (2025-10-16)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def response_hook(span: Span, params: typing.Union[
from opentelemetry.instrumentation.aiohttp_client.version import __version__
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
from opentelemetry.instrumentation.utils import (
is_instrumentation_enabled,
is_http_instrumentation_enabled,
unwrap,
)
from opentelemetry.metrics import MeterProvider, get_meter
Expand Down Expand Up @@ -325,7 +325,7 @@ async def on_request_start(
params: aiohttp.TraceRequestStartParams,
):
if (
not is_instrumentation_enabled()
not is_http_instrumentation_enabled()
or trace_config_ctx.excluded_urls.url_disabled(str(params.url))
):
trace_config_ctx.span = None
Expand Down Expand Up @@ -485,9 +485,6 @@ def _instrument(

# pylint:disable=unused-argument
def instrumented_init(wrapped, instance, args, kwargs):
if not is_instrumentation_enabled():
return wrapped(*args, **kwargs)

client_trace_configs = list(kwargs.get("trace_configs") or [])
client_trace_configs.extend(trace_configs)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@
from opentelemetry.instrumentation.aiohttp_client import (
AioHttpClientInstrumentor,
)
from opentelemetry.instrumentation.utils import suppress_instrumentation
from opentelemetry.instrumentation.utils import (
suppress_http_instrumentation,
suppress_instrumentation,
)
from opentelemetry.semconv._incubating.attributes.http_attributes import (
HTTP_HOST,
HTTP_METHOD,
Expand Down Expand Up @@ -1068,33 +1071,60 @@ async def uninstrument_request(server: aiohttp.test_utils.TestServer):
self._assert_spans(1)

def test_suppress_instrumentation(self):
with suppress_instrumentation():
run_with_test_server(
self.get_default_request(), self.URL, self.default_handler
)
self._assert_spans(0)
for suppress_ctx in (
suppress_instrumentation,
suppress_http_instrumentation,
):
with self.subTest(suppress_ctx=suppress_ctx.__name__):
with suppress_ctx():
run_with_test_server(
self.get_default_request(),
self.URL,
self.default_handler,
)
self._assert_spans(0)
self._assert_metrics(0)

@staticmethod
async def suppressed_request(server: aiohttp.test_utils.TestServer):
async with aiohttp.test_utils.TestClient(server) as client:
with suppress_instrumentation():
await client.get(TestAioHttpClientInstrumentor.URL)
def make_suppressed_request(suppress_ctx):
async def suppressed_request(server: aiohttp.test_utils.TestServer):
async with aiohttp.test_utils.TestClient(server) as client:
with suppress_ctx():
await client.get(TestAioHttpClientInstrumentor.URL)

return suppressed_request

def test_suppress_instrumentation_after_creation(self):
run_with_test_server(
self.suppressed_request, self.URL, self.default_handler
)
self._assert_spans(0)
for suppress_ctx in (
suppress_instrumentation,
suppress_http_instrumentation,
):
with self.subTest(suppress_ctx=suppress_ctx.__name__):
run_with_test_server(
self.make_suppressed_request(suppress_ctx),
self.URL,
self.default_handler,
)
self._assert_spans(0)
self._assert_metrics(0)

def test_suppress_instrumentation_with_server_exception(self):
# pylint:disable=unused-argument
async def raising_handler(request):
raise aiohttp.web.HTTPFound(location=self.URL)

run_with_test_server(
self.suppressed_request, self.URL, raising_handler
)
self._assert_spans(0)
for suppress_ctx in (
suppress_instrumentation,
suppress_http_instrumentation,
):
with self.subTest(suppress_ctx=suppress_ctx.__name__):
run_with_test_server(
self.make_suppressed_request(suppress_ctx),
self.URL,
raising_handler,
)
self._assert_spans(0)
self._assert_metrics(0)

def test_url_filter(self):
def strip_query_params(url: yarl.URL) -> str:
Expand Down