From 0245cd7b6a58bb6b4ab7f07e78b79e6dfefefc0b Mon Sep 17 00:00:00 2001 From: marcsello Date: Fri, 30 Jul 2021 12:17:18 +0200 Subject: [PATCH] Added tracing for requests --- cnn_classification_service/classifier_cache.py | 4 +++- cnn_classification_service/magic_doer.py | 5 ++++- cnn_classification_service/main.py | 11 +++++++++++ requirements.txt | 3 +++ 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/cnn_classification_service/classifier_cache.py b/cnn_classification_service/classifier_cache.py index aeec0e5..0a7cf3f 100644 --- a/cnn_classification_service/classifier_cache.py +++ b/cnn_classification_service/classifier_cache.py @@ -1,6 +1,8 @@ #!/usr/bin/env python3 import os import logging +from requests_opentracing import SessionTracing +import opentracing # ez kell ide hogy a session tracer jolegyen import requests import tempfile from typing import Tuple @@ -18,7 +20,7 @@ class ClassifierCache: self._current_classifier = None # Latest classifier is a classifier that uses the $default model self._downloaded_files = [] - self._session = requests.Session() + self._session = SessionTracing(propagate=True) def _cleanup(self): self._current_classifier = None diff --git a/cnn_classification_service/magic_doer.py b/cnn_classification_service/magic_doer.py index 0ed5004..4a191da 100644 --- a/cnn_classification_service/magic_doer.py +++ b/cnn_classification_service/magic_doer.py @@ -2,6 +2,8 @@ import os import logging import tempfile +from requests_opentracing import SessionTracing +import opentracing # ez kell ide hogy a session tracer jolegyen import requests import time from urllib.parse import urljoin @@ -13,6 +15,7 @@ from classifier_cache import ClassifierCache class MagicDoer: classifier_cache = ClassifierCache(Config.MODEL_INFO_URL) + requests_session = SessionTracing(propagate=True) @classmethod def run_everything(cls, parameters: dict) -> dict: @@ -25,7 +28,7 @@ class MagicDoer: object_path = urljoin(Config.STORAGE_SERVICE_URL, f"object/{tag}") logging.info(f"Downloading sample: {tag} from {object_path}") - r = requests.get(object_path) + r = cls.requests_session.get(object_path) with open(sample_file_handle, 'wb') as f: f.write(r.content) diff --git a/cnn_classification_service/main.py b/cnn_classification_service/main.py index 37e4598..6930dac 100644 --- a/cnn_classification_service/main.py +++ b/cnn_classification_service/main.py @@ -1,4 +1,7 @@ #!/usr/bin/env python3 +import jaeger_client +import opentracing + import logging import os import sys @@ -32,12 +35,16 @@ def message_callback(channel, method, properties, body): def main(): + # setup logging + logging.basicConfig( stream=sys.stdout, format="%(asctime)s - %(name)s [%(levelname)s]: %(message)s", level=Config.LOG_LEVEL ) + # setup observability stuffs + if Config.SENTRY_DSN: sentry_logging = LoggingIntegration( level=logging.DEBUG, # Capture info and above as breadcrumbs @@ -53,6 +60,10 @@ def main(): _experiments={"auto_enabling_integrations": True} ) + jaeger_client.Config(config={}, service_name='cnn-classification-service', validate=True).initialize_tracer() + + # Start the memes + logging.info("Connecting to MQ service...") connection = pika.BlockingConnection(pika.connection.URLParameters(Config.PIKA_URL)) channel = connection.channel() diff --git a/requirements.txt b/requirements.txt index 8fd9be4..3fa5213 100644 --- a/requirements.txt +++ b/requirements.txt @@ -11,3 +11,6 @@ keras_preprocessing tensorflow sndfile pillow + +jaeger-client +requests-opentracing