From 7dada87e725d378680b584d15d2199799e670c3a Mon Sep 17 00:00:00 2001 From: Francesco Leacche Date: Thu, 12 Dec 2024 12:18:56 +0000 Subject: [PATCH 1/2] improve logging --- emily_sidecar/app.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/emily_sidecar/app.py b/emily_sidecar/app.py index 9f430b9a2..3f3d5456d 100644 --- a/emily_sidecar/app.py +++ b/emily_sidecar/app.py @@ -24,6 +24,9 @@ class Meta: url = os.getenv("EMILY_CHAINSTATE_URL", "http://host.docker.internal:3031/chainstate") deployer_address = os.getenv("DEPLOYER_ADDRESS", "SN3R84XZYA63QS28932XQF3G1J8R9PC3W76P9CSQS") +logger.info(f"Using chainstate URL: {url}") +logger.info(f"Using deployer address: {deployer_address}") + headers = { "Content-Type": "application/json", "x-api-key": api_key @@ -42,17 +45,19 @@ def validate_json(schema, data): @app.route("/new_block", methods=["POST"]) def handle_new_block(): + logger.debug(f"Received new_block event") if not request.is_json: + logger.error("Request was not JSON") return jsonify({"error": "Request must be JSON"}), 400 data = request.get_json() - logger.debug(f"Received new-block event: {data}") schema = NewBlockEventSchema() try: validated_data = validate_json(schema, data) except ValueError as e: + logger.error(f"Failed to validate new block event: {e}") return jsonify(str(e)), 400 chainstate = { @@ -64,11 +69,11 @@ def handle_new_block(): resp = requests.post(url, headers=headers, json=chainstate) resp.raise_for_status() # This will raise an HTTPError if the response was an error except requests.RequestException as e: - logger.error(f"Failed to send chainstate to {url}: {e}") + logger.error(f"Failed to send chainstate {chainstate} to {url}: {e}") # lets return an error so that the node will retry return jsonify({"error": "Failed to send chainstate"}), 500 - logger.info(f"Successfully processed new block: {validated_data}") + logger.info(f"Successfully processed new block for chainstate: {chainstate}") return jsonify({}), 200 From 7136abf8a6efddf12262a8ca97b1ee27cfb58aeb Mon Sep 17 00:00:00 2001 From: Francesco Leacche Date: Thu, 12 Dec 2024 14:07:52 +0000 Subject: [PATCH 2/2] remove f-strings from logs --- emily_sidecar/app.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/emily_sidecar/app.py b/emily_sidecar/app.py index 3f3d5456d..ac4186c3d 100644 --- a/emily_sidecar/app.py +++ b/emily_sidecar/app.py @@ -24,8 +24,8 @@ class Meta: url = os.getenv("EMILY_CHAINSTATE_URL", "http://host.docker.internal:3031/chainstate") deployer_address = os.getenv("DEPLOYER_ADDRESS", "SN3R84XZYA63QS28932XQF3G1J8R9PC3W76P9CSQS") -logger.info(f"Using chainstate URL: {url}") -logger.info(f"Using deployer address: {deployer_address}") +logger.info("Using chainstate URL: %s", url) +logger.info("Using deployer address: %s", deployer_address) headers = { "Content-Type": "application/json", @@ -40,7 +40,7 @@ def validate_json(schema, data): try: return schema.load(data) except ValidationError as err: - logger.warning(f"Validation error: {err.messages}") + logger.warning("Validation error: %s", err.messages) raise ValueError({"error": "Invalid data", "messages": err.messages}) @app.route("/new_block", methods=["POST"]) @@ -57,7 +57,7 @@ def handle_new_block(): try: validated_data = validate_json(schema, data) except ValueError as e: - logger.error(f"Failed to validate new block event: {e}") + logger.error("Failed to validate new block event: %s", e) return jsonify(str(e)), 400 chainstate = { @@ -69,11 +69,11 @@ def handle_new_block(): resp = requests.post(url, headers=headers, json=chainstate) resp.raise_for_status() # This will raise an HTTPError if the response was an error except requests.RequestException as e: - logger.error(f"Failed to send chainstate {chainstate} to {url}: {e}") + logger.error("Failed to send chainstate %s to %s: %s", chainstate, url, e) # lets return an error so that the node will retry return jsonify({"error": "Failed to send chainstate"}), 500 - logger.info(f"Successfully processed new block for chainstate: {chainstate}") + logger.info("Successfully processed new block for chainstate: %s", chainstate) return jsonify({}), 200