Skip to content

Commit

Permalink
chore: improve sidecar logs (#1109)
Browse files Browse the repository at this point in the history
* improve logging

* remove f-strings from logs
  • Loading branch information
Jiloc authored Dec 12, 2024
1 parent 1c0b804 commit 5355367
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions emily_sidecar/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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("Using chainstate URL: %s", url)
logger.info("Using deployer address: %s", deployer_address)

headers = {
"Content-Type": "application/json",
"x-api-key": api_key
Expand All @@ -37,22 +40,24 @@ 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"])
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("Failed to validate new block event: %s", e)
return jsonify(str(e)), 400

chainstate = {
Expand All @@ -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("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: {validated_data}")
logger.info("Successfully processed new block for chainstate: %s", chainstate)
return jsonify({}), 200


Expand Down

0 comments on commit 5355367

Please sign in to comment.