Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
pcrespov committed Oct 21, 2021
1 parent 9c572fd commit 99e1d73
Showing 1 changed file with 3 additions and 28 deletions.
31 changes: 3 additions & 28 deletions packages/service-library/src/servicelib/aiohttp/tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
"""
import asyncio
import logging
import time
from contextlib import contextmanager
from typing import Iterable, Optional, Union

import aiozipkin as az
Expand All @@ -16,28 +14,6 @@
log = logging.getLogger(__name__)


DEFAULT_JAEGER_BASE_URL = "http://jaeger:9411"


@contextmanager
def _timeit(what: str, minimum_expected_secs: int = 2):
"""Small helper to time and log"""
try:
_tic = time.time()

yield

_elapsed = time.time() - _tic
msg = f"{what}: elapsed {_elapsed:3.2f} sec"
if _elapsed > minimum_expected_secs:
log.debug(msg)
else:
log.warning(msg)
except:
log.warning("Failed %s", what)
raise


def setup_tracing(
app: web.Application,
*,
Expand All @@ -63,10 +39,9 @@ def setup_tracing(

endpoint = az.create_endpoint(service_name, ipv4=host, port=port)

with _timeit("Created aiozipkin.tracer.Tracer"):
tracer: Tracer = asyncio.get_event_loop().run_until_complete(
az.create(f"{zipkin_address}", endpoint, sample_rate=1.0)
)
tracer: Tracer = asyncio.get_event_loop().run_until_complete(
az.create(f"{zipkin_address}", endpoint, sample_rate=1.0)
)

# WARNING: adds a middleware that should be the outermost since
# it expects stream responses while we allow data returns from a handler
Expand Down

0 comments on commit 99e1d73

Please sign in to comment.