From 691ad500c66f9a6d113df040ae2804caaf798b4d Mon Sep 17 00:00:00 2001 From: Thomas Sileo Date: Sat, 20 Aug 2022 09:11:48 +0200 Subject: [PATCH] Tweak logging --- app/activitypub.py | 3 +++ app/httpsig.py | 2 +- app/incoming_activities.py | 6 ++++++ app/main.py | 2 +- 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/app/activitypub.py b/app/activitypub.py index e06a999..f879647 100644 --- a/app/activitypub.py +++ b/app/activitypub.py @@ -5,6 +5,7 @@ from typing import TYPE_CHECKING from typing import Any import httpx +from loguru import logger from markdown import markdown from app import config @@ -135,6 +136,7 @@ async def fetch( params: dict[str, Any] | None = None, disable_httpsig: bool = False, ) -> RawObject: + logger.info(f"Fetching {url} ({params=})") check_url(url) async with httpx.AsyncClient() as client: @@ -342,6 +344,7 @@ def remove_context(raw_object: RawObject) -> RawObject: async def post(url: str, payload: dict[str, Any]) -> httpx.Response: + logger.info(f"Posting {url} ({payload=})") check_url(url) async with httpx.AsyncClient() as client: diff --git a/app/httpsig.py b/app/httpsig.py index 049a0fd..24515f6 100644 --- a/app/httpsig.py +++ b/app/httpsig.py @@ -187,7 +187,7 @@ async def httpsig_checker( server=server, ) - logger.debug(f"hsig={hsig}") + # logger.debug(f"hsig={hsig}") signed_string, signature_date = _build_signed_string( hsig["headers"], request.method, diff --git a/app/incoming_activities.py b/app/incoming_activities.py index ba4b186..b52fa92 100644 --- a/app/incoming_activities.py +++ b/app/incoming_activities.py @@ -3,6 +3,7 @@ import traceback from datetime import datetime from datetime import timedelta +import httpx from loguru import logger from sqlalchemy import func from sqlalchemy import select @@ -116,6 +117,11 @@ async def process_next_incoming_activity( next_activity.ap_object, next_activity.sent_by_ap_actor_id, ) + except httpx.TimeoutException as exc: + url = exc._request.url if exc._request else None + logger.error(f"HTTP timeout when fetching {url}") + next_activity.error = traceback.format_exc() + _set_next_try(next_activity) except Exception: logger.exception("Failed") next_activity.error = traceback.format_exc() diff --git a/app/main.py b/app/main.py index d4d6366..19d9fb3 100644 --- a/app/main.py +++ b/app/main.py @@ -760,7 +760,7 @@ async def inbox( db_session: AsyncSession = Depends(get_db_session), httpsig_info: httpsig.HTTPSigInfo = Depends(httpsig.enforce_httpsig), ) -> Response: - logger.info(f"headers={request.headers}") + # logger.info(f"headers={request.headers}") payload = await request.json() logger.info(f"{payload=}") await new_ap_incoming_activity(db_session, httpsig_info, payload)