Skip to content

Commit 5dcfaf6

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

File tree

1 file changed

+11
-5
lines changed
  • instrumentation/opentelemetry-instrumentation-aiohttp-server/src/opentelemetry/instrumentation/aiohttp_server

1 file changed

+11
-5
lines changed

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

Lines changed: 11 additions & 5 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
319-
global _excluded_urls # pylint: disable=global-statement
318+
# update global values at instrument time so we can test them
319+
global _excluded_urls
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

0 commit comments

Comments
 (0)