Added tracing for requests
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Pünkösd Marcell 2021-07-30 12:17:18 +02:00
parent 0bf778e473
commit 0245cd7b6a
4 changed files with 21 additions and 2 deletions

View File

@ -1,6 +1,8 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import os import os
import logging import logging
from requests_opentracing import SessionTracing
import opentracing # ez kell ide hogy a session tracer jolegyen
import requests import requests
import tempfile import tempfile
from typing import Tuple 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._current_classifier = None # Latest classifier is a classifier that uses the $default model
self._downloaded_files = [] self._downloaded_files = []
self._session = requests.Session() self._session = SessionTracing(propagate=True)
def _cleanup(self): def _cleanup(self):
self._current_classifier = None self._current_classifier = None

View File

@ -2,6 +2,8 @@
import os import os
import logging import logging
import tempfile import tempfile
from requests_opentracing import SessionTracing
import opentracing # ez kell ide hogy a session tracer jolegyen
import requests import requests
import time import time
from urllib.parse import urljoin from urllib.parse import urljoin
@ -13,6 +15,7 @@ from classifier_cache import ClassifierCache
class MagicDoer: class MagicDoer:
classifier_cache = ClassifierCache(Config.MODEL_INFO_URL) classifier_cache = ClassifierCache(Config.MODEL_INFO_URL)
requests_session = SessionTracing(propagate=True)
@classmethod @classmethod
def run_everything(cls, parameters: dict) -> dict: def run_everything(cls, parameters: dict) -> dict:
@ -25,7 +28,7 @@ class MagicDoer:
object_path = urljoin(Config.STORAGE_SERVICE_URL, f"object/{tag}") object_path = urljoin(Config.STORAGE_SERVICE_URL, f"object/{tag}")
logging.info(f"Downloading sample: {tag} from {object_path}") 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: with open(sample_file_handle, 'wb') as f:
f.write(r.content) f.write(r.content)

View File

@ -1,4 +1,7 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import jaeger_client
import opentracing
import logging import logging
import os import os
import sys import sys
@ -32,12 +35,16 @@ def message_callback(channel, method, properties, body):
def main(): def main():
# setup logging
logging.basicConfig( logging.basicConfig(
stream=sys.stdout, stream=sys.stdout,
format="%(asctime)s - %(name)s [%(levelname)s]: %(message)s", format="%(asctime)s - %(name)s [%(levelname)s]: %(message)s",
level=Config.LOG_LEVEL level=Config.LOG_LEVEL
) )
# setup observability stuffs
if Config.SENTRY_DSN: if Config.SENTRY_DSN:
sentry_logging = LoggingIntegration( sentry_logging = LoggingIntegration(
level=logging.DEBUG, # Capture info and above as breadcrumbs level=logging.DEBUG, # Capture info and above as breadcrumbs
@ -53,6 +60,10 @@ def main():
_experiments={"auto_enabling_integrations": True} _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...") logging.info("Connecting to MQ service...")
connection = pika.BlockingConnection(pika.connection.URLParameters(Config.PIKA_URL)) connection = pika.BlockingConnection(pika.connection.URLParameters(Config.PIKA_URL))
channel = connection.channel() channel = connection.channel()

View File

@ -11,3 +11,6 @@ keras_preprocessing
tensorflow tensorflow
sndfile sndfile
pillow pillow
jaeger-client
requests-opentracing