diff --git a/email_api/email_api/app.py b/email_api/email_api/app.py index e58bbfd..8af1c4f 100644 --- a/email_api/email_api/app.py +++ b/email_api/email_api/app.py @@ -52,6 +52,8 @@ def mark_email_as_processed(bucket, key): @app.route('/process/', methods=['POST']) def process_email(domain): + logger.info(f"[{request_id}] INCOMING POST /process/{domain}: " + f"payload_keys={list(data.keys())}") auth = request.headers.get('Authorization') if auth != f'Bearer {API_TOKEN}': return jsonify({'error': 'Unauthorized'}), 401 @@ -67,6 +69,7 @@ def process_email(domain): msg = BytesParser(policy=default).parsebytes(email_bytes) from_addr = getaddresses(msg.get_all('from', []))[0][1] if msg.get_all('from') else f'lambda@{domain}' + logger.debug(f"[{request_id}] Parsed email: from={from_addr}, recipients={recipients}") recipients = [] for hdr in ('to', 'cc', 'bcc'): recipients += [addr for _n, addr in getaddresses(msg.get_all(hdr, []))] @@ -94,7 +97,9 @@ def retry_domain_emails(domain): head = s3_client.head_object(Bucket=bucket, Key=obj['Key']) if head.get('Metadata', {}).get('processed') != 'true': unprocessed.append(obj['Key']) - + + logger.info(f"[{request_id}] RETRY processing for domain={domain}, keys={unprocessed}") + results = {'processed': [], 'failed': []} for key in unprocessed: try: diff --git a/ses-lambda/lambda-function.py b/ses-lambda/lambda-function.py index cf4276c..c685446 100644 --- a/ses-lambda/lambda-function.py +++ b/ses-lambda/lambda-function.py @@ -55,6 +55,7 @@ def call_api_with_retry(payload, domain, request_id, max_retries=3): payload_json = json.dumps(payload).encode('utf-8') for attempt in range(max_retries): try: + logger.info(f"[{request_id}] Attempt {attempt+1}: POST payload to {sync_url}") req = urllib.request.Request(sync_url, data=payload_json, method="POST") req.add_header('Authorization', f'Bearer {API_TOKEN}') req.add_header('Content-Type', 'application/json') @@ -65,6 +66,7 @@ def call_api_with_retry(payload, domain, request_id, max_retries=3): with urllib.request.urlopen(req, timeout=timeout, context=context) as response: code = response.getcode() if code == 200: + logger.info(f"[{request_id}] API response: {response_code}") return True except urllib.error.HTTPError as e: if 400 <= e.code < 500: @@ -113,6 +115,10 @@ def lambda_handler(event, context): 'original_size': len(body), 'compressed_size': len(compressed) } + + logger.info(f"[{request_id}] OUTGOING payload to {API_BASE_URL}/process/{domain}: " + f"domain={domain}, key={key}, bucket={bucket}, " + f"orig_size={len(body)}, comp_size={len(compressed)}") if call_api_with_retry(payload, domain, request_id): # Inline metadata marking statt Löschung