Add comprehensive server-side logging for Wren API calls
All checks were successful
Build and Push Docker Images / docker (push) Successful in 49s

- Added detailed request/response logging for createWrenOffsetOrder
- Added detailed request/response logging for getWrenOffsetOrder
- Logs include timestamp, duration, status, parameters, and full responses
- API token is masked for security (shows first 8 and last 4 chars)
- Logs will appear in Docker container logs with [WREN API SERVER] prefix
- Makes it easier to track and debug Wren API calls from webhooks
This commit is contained in:
Matt 2025-10-30 16:40:27 +01:00
parent f35e82c72a
commit 569cf84cde

View File

@ -21,9 +21,25 @@ export async function createWrenOffsetOrder({
amountCents,
dryRun = false
}) {
const startTime = Date.now();
const apiToken = process.env.WREN_API_TOKEN;
console.log('🔵 [WREN API SERVER] ========================================');
console.log('🔵 [WREN API SERVER] POST /offset_orders - Request initiated');
console.log('🔵 [WREN API SERVER] Timestamp:', new Date().toISOString());
console.log('🔵 [WREN API SERVER] API Token:', apiToken ? `${apiToken.substring(0, 8)}...${apiToken.substring(apiToken.length - 4)}` : 'NOT SET');
console.log('🔵 [WREN API SERVER] Request URL:', `${WREN_API_BASE_URL}/offset_orders`);
console.log('🔵 [WREN API SERVER] Parameters:', JSON.stringify({
tons: parseFloat(tons),
portfolioId,
customerEmail,
currency: currency.toUpperCase(),
amountCents,
dryRun
}, null, 2));
if (!apiToken) {
console.error('❌ [WREN API SERVER] WREN_API_TOKEN not configured');
throw new Error('WREN_API_TOKEN environment variable is required');
}
@ -49,10 +65,25 @@ export async function createWrenOffsetOrder({
}
);
console.log('✅ Wren offset order created:', response.data.id);
const duration = Date.now() - startTime;
console.log('✅ [WREN API SERVER] POST /offset_orders - Success');
console.log('✅ [WREN API SERVER] Status:', response.status);
console.log('✅ [WREN API SERVER] Duration:', duration + 'ms');
console.log('✅ [WREN API SERVER] Order ID:', response.data.id);
console.log('✅ [WREN API SERVER] Response:', JSON.stringify(response.data, null, 2));
console.log('🔵 [WREN API SERVER] ========================================');
return response.data;
} catch (error) {
console.error('❌ Wren API error:', error.response?.data || error.message);
const duration = Date.now() - startTime;
console.error('❌ [WREN API SERVER] POST /offset_orders - Failed');
console.error('❌ [WREN API SERVER] Status:', error.response?.status || 'No response');
console.error('❌ [WREN API SERVER] Duration:', duration + 'ms');
console.error('❌ [WREN API SERVER] Error message:', error.message);
console.error('❌ [WREN API SERVER] Error response:', JSON.stringify(error.response?.data, null, 2));
console.error('❌ [WREN API SERVER] Full error:', error);
console.log('🔵 [WREN API SERVER] ========================================');
throw new Error(`Wren API failed: ${error.response?.data?.message || error.message}`);
}
}
@ -63,9 +94,18 @@ export async function createWrenOffsetOrder({
* @returns {Promise<Object>} Wren order details
*/
export async function getWrenOffsetOrder(orderId) {
const startTime = Date.now();
const apiToken = process.env.WREN_API_TOKEN;
console.log('🔵 [WREN API SERVER] ========================================');
console.log('🔵 [WREN API SERVER] GET /offset_orders/:id - Request initiated');
console.log('🔵 [WREN API SERVER] Timestamp:', new Date().toISOString());
console.log('🔵 [WREN API SERVER] API Token:', apiToken ? `${apiToken.substring(0, 8)}...${apiToken.substring(apiToken.length - 4)}` : 'NOT SET');
console.log('🔵 [WREN API SERVER] Request URL:', `${WREN_API_BASE_URL}/offset_orders/${orderId}`);
console.log('🔵 [WREN API SERVER] Order ID:', orderId);
if (!apiToken) {
console.error('❌ [WREN API SERVER] WREN_API_TOKEN not configured');
throw new Error('WREN_API_TOKEN environment variable is required');
}
@ -80,9 +120,24 @@ export async function getWrenOffsetOrder(orderId) {
}
);
const duration = Date.now() - startTime;
console.log('✅ [WREN API SERVER] GET /offset_orders/:id - Success');
console.log('✅ [WREN API SERVER] Status:', response.status);
console.log('✅ [WREN API SERVER] Duration:', duration + 'ms');
console.log('✅ [WREN API SERVER] Response:', JSON.stringify(response.data, null, 2));
console.log('🔵 [WREN API SERVER] ========================================');
return response.data;
} catch (error) {
console.error('❌ Wren API error:', error.response?.data || error.message);
const duration = Date.now() - startTime;
console.error('❌ [WREN API SERVER] GET /offset_orders/:id - Failed');
console.error('❌ [WREN API SERVER] Status:', error.response?.status || 'No response');
console.error('❌ [WREN API SERVER] Duration:', duration + 'ms');
console.error('❌ [WREN API SERVER] Error message:', error.message);
console.error('❌ [WREN API SERVER] Error response:', JSON.stringify(error.response?.data, null, 2));
console.error('❌ [WREN API SERVER] Full error:', error);
console.log('🔵 [WREN API SERVER] ========================================');
throw new Error(`Wren API failed: ${error.response?.data?.message || error.message}`);
}
}