chore(logging): add detailed debug logging to instance start and tunnel creation

Add comprehensive logging to trace 500 error:
- Log each step of docker compose up (returncode, stdout, stderr)
- Log container ID and name after start
- Log tool type and port being used
- Log each step of Cloudflare tunnel creation with API responses
- Log cloudflared config updates

This will help identify exactly where the failure occurs.
This commit is contained in:
Fusion
2026-05-20 15:27:55 +02:00
parent 1d33735e2f
commit 7a88639250
2 changed files with 35 additions and 2 deletions
@@ -45,11 +45,17 @@ async def create_tunnel(
if not settings.cloudflare_api_token:
raise ValueError("CLOUDFLARE_API_TOKEN not configured")
logger.info("Creating Cloudflare tunnel for instance_name=%s, instance_id=%s, port=%d",
instance_name, instance_id, instance_port)
logger.info("Cloudflare config: account_id=%s, zone_id=%s, base_domain=%s",
settings.cloudflare_account_id, settings.cloudflare_zone_id, settings.cloudflare_base_domain)
headers = _get_headers(settings)
account_id = settings.cloudflare_account_id
# Create tunnel
async with httpx.AsyncClient() as client:
logger.info("Step 1: Creating tunnel via Cloudflare API...")
response = await client.post(
f"{CLOUDFLARE_API_BASE}/accounts/{account_id}/cfd_tunnel",
headers=headers,
@@ -58,6 +64,7 @@ async def create_tunnel(
"config_src": "cloudflare",
},
)
logger.info("Tunnel creation response: status=%d, body=%s", response.status_code, response.text[:500])
response.raise_for_status()
data = response.json()
@@ -66,19 +73,24 @@ async def create_tunnel(
tunnel = data["result"]
tunnel_id = tunnel["id"]
logger.info("Step 1 complete: tunnel_id=%s", tunnel_id)
# Get tunnel token
logger.info("Step 2: Getting tunnel token...")
token_response = await client.get(
f"{CLOUDFLARE_API_BASE}/accounts/{account_id}/cfd_tunnel/{tunnel_id}/token",
headers=headers,
)
logger.info("Token response: status=%d", token_response.status_code)
token_response.raise_for_status()
token_data = token_response.json()
tunnel_token = token_data["result"]
logger.info("Step 2 complete: got tunnel token")
# Create DNS record for the tunnel
subdomain = f"instance-{instance_id[:8]}"
hostname = f"{subdomain}.{settings.cloudflare_base_domain}"
logger.info("Step 3: Creating DNS record for subdomain=%s, hostname=%s", subdomain, hostname)
dns_response = await client.post(
f"{CLOUDFLARE_API_BASE}/zones/{settings.cloudflare_zone_id}/dns_records",
@@ -91,9 +103,12 @@ async def create_tunnel(
"proxied": True,
},
)
logger.info("DNS response: status=%d, body=%s", dns_response.status_code, dns_response.text[:500])
dns_response.raise_for_status()
logger.info("Step 3 complete: DNS record created")
# Update cloudflared config
logger.info("Step 4: Updating cloudflared config...")
await update_cloudflared_config(
tunnel_id=tunnel_id,
tunnel_token=tunnel_token,
@@ -102,7 +117,9 @@ async def create_tunnel(
instance_port=instance_port,
settings=settings,
)
logger.info("Step 4 complete: cloudflared config updated")
logger.info("Tunnel creation complete: tunnel_id=%s, public_url=https://%s", tunnel_id, hostname)
return {
"tunnel_id": tunnel_id,
"public_url": f"https://{hostname}",