File tree Expand file tree Collapse file tree 1 file changed +19
-4
lines changed
packages/service-library/src/servicelib/aiohttp Expand file tree Collapse file tree 1 file changed +19
-4
lines changed Original file line number Diff line number Diff line change 1- """ Adds aiohttp middleware for tracing using opentelemetry instrumentation.
2-
3- """
1+ """Adds aiohttp middleware for tracing using opentelemetry instrumentation."""
42
53import logging
64
4442except ImportError :
4543 HAS_REQUESTS = False
4644
45+ try :
46+ from opentelemetry .instrumentation .aio_pika import AioPikaInstrumentor
47+
48+ HAS_AIO_PIKA = True
49+ except ImportError :
50+ HAS_AIO_PIKA = False
51+
4752
4853def setup_tracing (
4954 app : web .Application ,
@@ -74,7 +79,9 @@ def setup_tracing(
7479 trace .set_tracer_provider (TracerProvider (resource = resource ))
7580 tracer_provider : trace .TracerProvider = trace .get_tracer_provider ()
7681
77- tracing_destination : str = f"{ URL (opentelemetry_collector_endpoint ).with_port (opentelemetry_collector_port ).with_path ('/v1/traces' )} "
82+ tracing_destination : str = (
83+ f"{ URL (opentelemetry_collector_endpoint ).with_port (opentelemetry_collector_port ).with_path ('/v1/traces' )} "
84+ )
7885
7986 _logger .info (
8087 "Trying to connect service %s to tracing collector at %s." ,
@@ -128,3 +135,11 @@ def setup_tracing(
128135 msg = "Attempting to add requests opentelemetry autoinstrumentation..." ,
129136 ):
130137 RequestsInstrumentor ().instrument ()
138+
139+ if HAS_AIO_PIKA :
140+ with log_context (
141+ _logger ,
142+ logging .INFO ,
143+ msg = "Attempting to add aio_pika opentelemetry autoinstrumentation..." ,
144+ ):
145+ AioPikaInstrumentor ().instrument ()
You can’t perform that action at this time.
0 commit comments