Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added aiohttp-server instrumentation injection to module web_app #3218

Closed
wants to merge 1 commit into from
Closed
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- Added `opentelemetry-instrumentation-aiohttp-server` injection to `aiohttp` module `web_app`.
- `opentelemetry-instrumentation-confluent-kafka` Add support for confluent-kafka <=2.7.0
([#3100](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/3100))
- Add support to database stability opt-in in `_semconv` utilities and add tests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from timeit import default_timer
from typing import Dict, List, Tuple, Union

from aiohttp import web
from aiohttp import web, web_app
from multidict import CIMultiDictProxy

from opentelemetry import metrics, trace
Expand Down Expand Up @@ -257,10 +257,12 @@ class AioHttpServerInstrumentor(BaseInstrumentor):
"""

def _instrument(self, **kwargs):
self._original_app = web.Application
self._original_app = web_app.Application
setattr(web_app, "Application", _InstrumentedApplication)
setattr(web, "Application", _InstrumentedApplication)

def _uninstrument(self, **kwargs):
setattr(web_app, "Application", self._original_app)
setattr(web, "Application", self._original_app)

def instrumentation_dependencies(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from opentelemetry import trace as trace_api
from opentelemetry.instrumentation.aiohttp_server import (
AioHttpServerInstrumentor,
_InstrumentedApplication,
)
from opentelemetry.instrumentation.utils import suppress_http_instrumentation
from opentelemetry.semconv.trace import SpanAttributes
Expand Down Expand Up @@ -70,13 +71,20 @@ def fixture_suppress():
return False


@pytest.mark.asyncio
async def test_aiohttp_app_instrumented():
AioHttpServerInstrumentor().instrument()
from aiohttp import web, web_app # pylint: disable=C0415

assert web.Application is _InstrumentedApplication
assert web_app.Application is _InstrumentedApplication


@pytest_asyncio.fixture(name="server_fixture")
async def fixture_server_fixture(tracer, aiohttp_server, suppress):
_, memory_exporter = tracer

AioHttpServerInstrumentor().instrument()

app = aiohttp.web.Application()
app = _InstrumentedApplication()
app.add_routes([aiohttp.web.get("/test-path", default_handler)])
if suppress:
with suppress_http_instrumentation():
Expand All @@ -88,8 +96,6 @@ async def fixture_server_fixture(tracer, aiohttp_server, suppress):

memory_exporter.clear()

AioHttpServerInstrumentor().uninstrument()


def test_checking_instrumentor_pkg_installed():
(instrumentor_entrypoint,) = entry_points(
Expand Down