Skip to content

Commit 0f685de

Browse files
committed
autoinstrument aiopika in aihttp case
1 parent 273896e commit 0f685de

File tree

1 file changed

+19
-4
lines changed
  • packages/service-library/src/servicelib/aiohttp

1 file changed

+19
-4
lines changed

packages/service-library/src/servicelib/aiohttp/tracing.py

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
""" Adds aiohttp middleware for tracing using opentelemetry instrumentation.
2-
3-
"""
1+
"""Adds aiohttp middleware for tracing using opentelemetry instrumentation."""
42

53
import logging
64

@@ -44,6 +42,13 @@
4442
except 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

4853
def 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()

0 commit comments

Comments
 (0)