Skip to content

Commit 8d08bfe

Browse files
committed
ensure logs are json serializable
1 parent da7fc9d commit 8d08bfe

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

typescript/logging/fireworks-transport.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,23 @@ export class FireworksTransport extends Transport {
9292
const baseUrl = this.gatewayBaseUrl.replace(/\/$/, '');
9393
const url = `${baseUrl}/logs`;
9494

95+
let payloadJson: string;
96+
try {
97+
payloadJson = JSON.stringify(payload);
98+
} catch (e: any) {
99+
const msg = `Fireworks logging payload is not JSON-serializable (rollout_id=${rolloutId}): ${e?.message || e}`;
100+
console.error(`[FW_LOG] ${msg}`);
101+
this.emit('error', new Error(msg));
102+
return;
103+
}
104+
95105
// Debug logging
96106
if (process.env.EP_DEBUG === 'true') {
97107
const tagsLen = Array.isArray(payload.tags) ? payload.tags.length : 0;
98108
const msgPreview = typeof payload.message === 'string'
99109
? payload.message.substring(0, 80)
100110
: payload.message;
101-
const payloadSize = JSON.stringify(payload).length;
111+
const payloadSize = payloadJson.length;
102112
const hasStatus = !!payload.status;
103113
console.log(`[FW_LOG] POST ${url} rollout_id=${rolloutId} tags=${tagsLen} msg=${msgPreview} size=${payloadSize} hasStatus=${hasStatus}`);
104114
}
@@ -116,7 +126,7 @@ export class FireworksTransport extends Transport {
116126
const response = await fetch(url, {
117127
method: 'POST',
118128
headers,
119-
body: JSON.stringify(payload),
129+
body: payloadJson,
120130
// No timeout signal for compatibility
121131
});
122132

@@ -136,7 +146,7 @@ export class FireworksTransport extends Transport {
136146
const retryResponse = await fetch(altUrl, {
137147
method: 'POST',
138148
headers,
139-
body: JSON.stringify(payload),
149+
body: payloadJson,
140150
// No timeout signal for compatibility
141151
});
142152

@@ -149,7 +159,7 @@ export class FireworksTransport extends Transport {
149159
// Silently handle errors - logging should not break the application
150160
if (process.env.EP_DEBUG === 'true') {
151161
console.error(`[FW_LOG] Error sending to Fireworks:`, error.message);
152-
console.error(`[FW_LOG] Payload was:`, JSON.stringify(payload, null, 2));
162+
console.error(`[FW_LOG] Payload was:`, payloadJson);
153163
}
154164
}
155165
}

typescript/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"files": [
1313
"dist"
1414
],
15-
"version": "0.1.11",
15+
"version": "0.1.12",
1616
"peerDependencies": {
1717
"typescript": "^5",
1818
"@vercel/functions": "^1.4.0",

0 commit comments

Comments
 (0)