From 1359eb8a3dfbfbd832d189b5b3e3b4c01a4bff10 Mon Sep 17 00:00:00 2001 From: Cyber MacGeddon Date: Wed, 30 Jul 2025 22:59:44 +0100 Subject: [PATCH] Logging strategy updates --- trustgraph-base/trustgraph/base/agent_service.py | 8 ++++++-- .../trustgraph/base/document_embeddings_client.py | 7 ++++++- .../base/document_embeddings_query_service.py | 15 ++++++++++----- .../base/document_embeddings_store_service.py | 7 ++++++- .../trustgraph/base/graph_embeddings_client.py | 7 ++++++- .../base/graph_embeddings_query_service.py | 15 ++++++++++----- .../base/graph_embeddings_store_service.py | 7 ++++++- .../trustgraph/base/triples_query_service.py | 10 +++++----- 8 files changed, 55 insertions(+), 21 deletions(-) diff --git a/trustgraph-base/trustgraph/base/agent_service.py b/trustgraph-base/trustgraph/base/agent_service.py index 0dbe728e..0d38114b 100644 --- a/trustgraph-base/trustgraph/base/agent_service.py +++ b/trustgraph-base/trustgraph/base/agent_service.py @@ -4,12 +4,16 @@ Agent manager service completion base class """ import time +import logging from prometheus_client import Histogram from .. schema import AgentRequest, AgentResponse, Error from .. exceptions import TooManyRequests from .. base import FlowProcessor, ConsumerSpec, ProducerSpec +# Module logger +logger = logging.getLogger(__name__) + default_ident = "agent-manager" class AgentService(FlowProcessor): @@ -76,9 +80,9 @@ class AgentService(FlowProcessor): except Exception as e: # Apart from rate limits, treat all exceptions as unrecoverable - print(f"on_request Exception: {e}") + logger.error(f"Exception in agent service on_request: {e}", exc_info=True) - print("Send error response...", flush=True) + logger.info("Sending error response...") await flow.producer["response"].send( AgentResponse( diff --git a/trustgraph-base/trustgraph/base/document_embeddings_client.py b/trustgraph-base/trustgraph/base/document_embeddings_client.py index 86370c52..80c9d789 100644 --- a/trustgraph-base/trustgraph/base/document_embeddings_client.py +++ b/trustgraph-base/trustgraph/base/document_embeddings_client.py @@ -1,8 +1,13 @@ +import logging + from . request_response_spec import RequestResponse, RequestResponseSpec from .. schema import DocumentEmbeddingsRequest, DocumentEmbeddingsResponse from .. knowledge import Uri, Literal +# Module logger +logger = logging.getLogger(__name__) + class DocumentEmbeddingsClient(RequestResponse): async def query(self, vectors, limit=20, user="trustgraph", collection="default", timeout=30): @@ -17,7 +22,7 @@ class DocumentEmbeddingsClient(RequestResponse): timeout=timeout ) - print(resp, flush=True) + logger.debug(f"Document embeddings response: {resp}") if resp.error: raise RuntimeError(resp.error.message) diff --git a/trustgraph-base/trustgraph/base/document_embeddings_query_service.py b/trustgraph-base/trustgraph/base/document_embeddings_query_service.py index 0dee7001..b8e7be4c 100644 --- a/trustgraph-base/trustgraph/base/document_embeddings_query_service.py +++ b/trustgraph-base/trustgraph/base/document_embeddings_query_service.py @@ -4,6 +4,8 @@ Document embeddings query service. Input is vectors. Output is list of embeddings. """ +import logging + from .. schema import DocumentEmbeddingsRequest, DocumentEmbeddingsResponse from .. schema import Error, Value @@ -11,6 +13,9 @@ from . flow_processor import FlowProcessor from . consumer_spec import ConsumerSpec from . producer_spec import ProducerSpec +# Module logger +logger = logging.getLogger(__name__) + default_ident = "ge-query" class DocumentEmbeddingsQueryService(FlowProcessor): @@ -47,21 +52,21 @@ class DocumentEmbeddingsQueryService(FlowProcessor): # Sender-produced ID id = msg.properties()["id"] - print(f"Handling input {id}...", flush=True) + logger.debug(f"Handling document embeddings query request {id}...") docs = await self.query_document_embeddings(request) - print("Send response...", flush=True) + logger.debug("Sending document embeddings query response...") r = DocumentEmbeddingsResponse(documents=docs, error=None) await flow("response").send(r, properties={"id": id}) - print("Done.", flush=True) + logger.debug("Document embeddings query request completed") except Exception as e: - print(f"Exception: {e}") + logger.error(f"Exception in document embeddings query service: {e}", exc_info=True) - print("Send error response...", flush=True) + logger.info("Sending error response...") r = DocumentEmbeddingsResponse( error=Error( diff --git a/trustgraph-base/trustgraph/base/document_embeddings_store_service.py b/trustgraph-base/trustgraph/base/document_embeddings_store_service.py index fbf58869..1d33ee94 100644 --- a/trustgraph-base/trustgraph/base/document_embeddings_store_service.py +++ b/trustgraph-base/trustgraph/base/document_embeddings_store_service.py @@ -3,10 +3,15 @@ Document embeddings store base class """ +import logging + from .. schema import DocumentEmbeddings from .. base import FlowProcessor, ConsumerSpec from .. exceptions import TooManyRequests +# Module logger +logger = logging.getLogger(__name__) + default_ident = "document-embeddings-write" class DocumentEmbeddingsStoreService(FlowProcessor): @@ -40,7 +45,7 @@ class DocumentEmbeddingsStoreService(FlowProcessor): except Exception as e: - print(f"Exception: {e}") + logger.error(f"Exception in document embeddings store service: {e}", exc_info=True) raise e @staticmethod diff --git a/trustgraph-base/trustgraph/base/graph_embeddings_client.py b/trustgraph-base/trustgraph/base/graph_embeddings_client.py index e89364f2..e25d76c7 100644 --- a/trustgraph-base/trustgraph/base/graph_embeddings_client.py +++ b/trustgraph-base/trustgraph/base/graph_embeddings_client.py @@ -1,8 +1,13 @@ +import logging + from . request_response_spec import RequestResponse, RequestResponseSpec from .. schema import GraphEmbeddingsRequest, GraphEmbeddingsResponse from .. knowledge import Uri, Literal +# Module logger +logger = logging.getLogger(__name__) + def to_value(x): if x.is_uri: return Uri(x.value) return Literal(x.value) @@ -21,7 +26,7 @@ class GraphEmbeddingsClient(RequestResponse): timeout=timeout ) - print(resp, flush=True) + logger.debug(f"Graph embeddings response: {resp}") if resp.error: raise RuntimeError(resp.error.message) diff --git a/trustgraph-base/trustgraph/base/graph_embeddings_query_service.py b/trustgraph-base/trustgraph/base/graph_embeddings_query_service.py index fb2e8dc5..f3afdba2 100644 --- a/trustgraph-base/trustgraph/base/graph_embeddings_query_service.py +++ b/trustgraph-base/trustgraph/base/graph_embeddings_query_service.py @@ -4,6 +4,8 @@ Graph embeddings query service. Input is vectors. Output is list of embeddings. """ +import logging + from .. schema import GraphEmbeddingsRequest, GraphEmbeddingsResponse from .. schema import Error, Value @@ -11,6 +13,9 @@ from . flow_processor import FlowProcessor from . consumer_spec import ConsumerSpec from . producer_spec import ProducerSpec +# Module logger +logger = logging.getLogger(__name__) + default_ident = "ge-query" class GraphEmbeddingsQueryService(FlowProcessor): @@ -47,21 +52,21 @@ class GraphEmbeddingsQueryService(FlowProcessor): # Sender-produced ID id = msg.properties()["id"] - print(f"Handling input {id}...", flush=True) + logger.debug(f"Handling graph embeddings query request {id}...") entities = await self.query_graph_embeddings(request) - print("Send response...", flush=True) + logger.debug("Sending graph embeddings query response...") r = GraphEmbeddingsResponse(entities=entities, error=None) await flow("response").send(r, properties={"id": id}) - print("Done.", flush=True) + logger.debug("Graph embeddings query request completed") except Exception as e: - print(f"Exception: {e}") + logger.error(f"Exception in graph embeddings query service: {e}", exc_info=True) - print("Send error response...", flush=True) + logger.info("Sending error response...") r = GraphEmbeddingsResponse( error=Error( diff --git a/trustgraph-base/trustgraph/base/graph_embeddings_store_service.py b/trustgraph-base/trustgraph/base/graph_embeddings_store_service.py index 911b90c1..6d3fdf72 100644 --- a/trustgraph-base/trustgraph/base/graph_embeddings_store_service.py +++ b/trustgraph-base/trustgraph/base/graph_embeddings_store_service.py @@ -3,10 +3,15 @@ Graph embeddings store base class """ +import logging + from .. schema import GraphEmbeddings from .. base import FlowProcessor, ConsumerSpec from .. exceptions import TooManyRequests +# Module logger +logger = logging.getLogger(__name__) + default_ident = "graph-embeddings-write" class GraphEmbeddingsStoreService(FlowProcessor): @@ -40,7 +45,7 @@ class GraphEmbeddingsStoreService(FlowProcessor): except Exception as e: - print(f"Exception: {e}") + logger.error(f"Exception in graph embeddings store service: {e}", exc_info=True) raise e @staticmethod diff --git a/trustgraph-base/trustgraph/base/triples_query_service.py b/trustgraph-base/trustgraph/base/triples_query_service.py index 880c5a37..0d8affcb 100644 --- a/trustgraph-base/trustgraph/base/triples_query_service.py +++ b/trustgraph-base/trustgraph/base/triples_query_service.py @@ -50,21 +50,21 @@ class TriplesQueryService(FlowProcessor): # Sender-produced ID id = msg.properties()["id"] - print(f"Handling input {id}...", flush=True) + logger.debug(f"Handling triples query request {id}...") triples = await self.query_triples(request) - print("Send response...", flush=True) + logger.debug("Sending triples query response...") r = TriplesQueryResponse(triples=triples, error=None) await flow("response").send(r, properties={"id": id}) - print("Done.", flush=True) + logger.debug("Triples query request completed") except Exception as e: - print(f"Exception: {e}") + logger.error(f"Exception in triples query service: {e}", exc_info=True) - print("Send error response...", flush=True) + logger.info("Sending error response...") r = TriplesQueryResponse( error = Error(