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
3836except ImportError :
3937 HAS_REQUESTS = False
4038
39+ try :
40+ from opentelemetry .instrumentation .aio_pika import AioPikaInstrumentor
41+
42+ HAS_AIO_PIKA = True
43+ except ImportError :
44+ HAS_AIO_PIKA = False
45+
4146
4247def setup_tracing (
4348 app : web .Application ,
@@ -68,7 +73,9 @@ def setup_tracing(
6873 trace .set_tracer_provider (TracerProvider (resource = resource ))
6974 tracer_provider : trace .TracerProvider = trace .get_tracer_provider ()
7075
71- tracing_destination : str = f"{ URL (opentelemetry_collector_endpoint ).with_port (opentelemetry_collector_port ).with_path ('/v1/traces' )} "
76+ tracing_destination : str = (
77+ f"{ URL (opentelemetry_collector_endpoint ).with_port (opentelemetry_collector_port ).with_path ('/v1/traces' )} "
78+ )
7279
7380 _logger .info (
7481 "Trying to connect service %s to tracing collector at %s." ,
@@ -116,3 +123,11 @@ def setup_tracing(
116123 msg = "Attempting to add requests opentelemetry autoinstrumentation..." ,
117124 ):
118125 RequestsInstrumentor ().instrument ()
126+
127+ if HAS_AIO_PIKA :
128+ with log_context (
129+ _logger ,
130+ logging .INFO ,
131+ msg = "Attempting to add aio_pika opentelemetry autoinstrumentation..." ,
132+ ):
133+ AioPikaInstrumentor ().instrument ()
You can’t perform that action at this time.
0 commit comments