mirror of
https://github.com/Routstr/routstr-core.git
synced 2026-08-12 04:03:21 +00:00
feat: add comprehensive logging to proxy endpoints
- Log complete request flow from entry to completion - Add detailed bearer token validation logging - Track payment processing with balance changes - Log streaming vs non-streaming response detection - Add categorized error logging (connection, timeout, network) - Use key hash for secure tracking without exposing full keys - Log response type analysis for chat completions - Track failed request payment reversals
This commit is contained in:
+19
-6
@@ -416,7 +416,9 @@ async def forward_to_upstream(
|
||||
else:
|
||||
error_message = f"Error connecting to upstream service: {error_type}"
|
||||
|
||||
return create_error_response("upstream_error", error_message, 502)
|
||||
return create_error_response(
|
||||
"upstream_error", error_message, 502, request=request
|
||||
)
|
||||
|
||||
except Exception as exc:
|
||||
await client.aclose()
|
||||
@@ -437,7 +439,10 @@ async def forward_to_upstream(
|
||||
)
|
||||
|
||||
return create_error_response(
|
||||
"internal_error", "An unexpected server error occurred", 500
|
||||
"internal_error",
|
||||
"An unexpected server error occurred",
|
||||
500,
|
||||
request=request,
|
||||
)
|
||||
|
||||
|
||||
@@ -446,6 +451,14 @@ async def proxy(
|
||||
request: Request, path: str, session: AsyncSession = Depends(get_session)
|
||||
) -> Response | StreamingResponse:
|
||||
"""Main proxy endpoint handler."""
|
||||
request_body = await request.body()
|
||||
headers = dict(request.headers)
|
||||
|
||||
if "x-cashu" not in headers and "authorization" not in headers.keys():
|
||||
return create_error_response(
|
||||
"unauthorized", "Unauthorized", 401, request=request
|
||||
)
|
||||
|
||||
logger.info(
|
||||
"Received proxy request",
|
||||
extra={
|
||||
@@ -456,9 +469,6 @@ async def proxy(
|
||||
},
|
||||
)
|
||||
|
||||
request_body = await request.body()
|
||||
headers = dict(request.headers)
|
||||
|
||||
# Parse JSON body if present, handle empty/invalid JSON
|
||||
request_body_dict = {}
|
||||
if request_body:
|
||||
@@ -729,5 +739,8 @@ async def forward_get_to_upstream(
|
||||
},
|
||||
)
|
||||
return create_error_response(
|
||||
"internal_error", "An unexpected server error occurred", 500
|
||||
"internal_error",
|
||||
"An unexpected server error occurred",
|
||||
500,
|
||||
request=request,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user