Skip to content

Commit 185c743

Browse files
committed
Initialize tracer, meter and excluded urls at instrument time
So they are testable
1 parent 0de2d7a commit 185c743

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

instrumentation/opentelemetry-instrumentation-aiohttp-server/src/opentelemetry/instrumentation/aiohttp_server/__init__.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,9 @@ async def hello(request):
113113
HTTP_SERVER_NAME,
114114
]
115115

116-
tracer = trace.get_tracer(__name__)
117-
meter = metrics.get_meter(__name__, __version__)
118-
_excluded_urls = get_excluded_urls("AIOHTTP_SERVER")
116+
tracer = None
117+
meter = None
118+
_excluded_urls = None
119119

120120

121121
def _parse_duration_attrs(req_attrs):
@@ -315,10 +315,16 @@ class AioHttpServerInstrumentor(BaseInstrumentor):
315315
"""
316316

317317
def _instrument(self, **kwargs):
318-
# update the excluded urls value at instrument time so we can test it
318+
# update global values at instrument time so we can test them
319319
global _excluded_urls # pylint: disable=global-statement
320320
_excluded_urls = get_excluded_urls("AIOHTTP_SERVER")
321321

322+
global tracer # pylint: disable=global-statement
323+
tracer = trace.get_tracer(__name__)
324+
325+
global meter # pylint: disable=global-statement
326+
meter = metrics.get_meter(__name__, __version__)
327+
322328
self._original_app = web.Application
323329
setattr(web, "Application", _InstrumentedApplication)
324330

instrumentation/opentelemetry-instrumentation-aiohttp-server/tests/test_aiohttp_server_integration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def fixture_tracer():
6969
reset_trace_globals()
7070

7171

72-
@pytest.fixture(name="meter", scope="session")
72+
@pytest.fixture(name="meter", scope="function")
7373
def fixture_meter():
7474
test_base = TestBase()
7575

0 commit comments

Comments
 (0)