Skip to content

Commit 3755521

Browse files
committed
autoinstrument aiopika in aihttp case
1 parent bd45887 commit 3755521

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

@@ -38,6 +36,13 @@
3836
except 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

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

0 commit comments

Comments
 (0)