Spaces:
Sleeping
Sleeping
Commit
·
2b72918
1
Parent(s):
e78b885
track status code
Browse files
index.ts
CHANGED
|
@@ -61,6 +61,7 @@ const requestTraces: {
|
|
| 61 |
arguments?: any;
|
| 62 |
provider?: string;
|
| 63 |
duration_ms?: number;
|
|
|
|
| 64 |
}[] = [];
|
| 65 |
|
| 66 |
let lastTraceBatchTime = Date.now();
|
|
@@ -246,11 +247,13 @@ app.get('/', (c) => {
|
|
| 246 |
}
|
| 247 |
});
|
| 248 |
|
| 249 |
-
async function storeStreamedResponse(streamToLog: ReadableStream<Uint8Array>, contentType: string | null, targetUrl: string, traceIndex: number) {
|
| 250 |
const reader = streamToLog.getReader();
|
| 251 |
const chunks: Uint8Array[] = [];
|
| 252 |
|
| 253 |
try {
|
|
|
|
|
|
|
| 254 |
while (true) {
|
| 255 |
const { done, value } = await reader.read();
|
| 256 |
if (done) break;
|
|
@@ -483,7 +486,7 @@ app.all('*', async (c) => {
|
|
| 483 |
const contentType = response.headers.get('content-type');
|
| 484 |
|
| 485 |
if (shouldCreateTrace && traceIndex >= 0) {
|
| 486 |
-
storeStreamedResponse(streamForStorage, contentType, targetUrl, traceIndex).catch(err => {
|
| 487 |
console.error("Error in background stream storage:", err);
|
| 488 |
});
|
| 489 |
}
|
|
@@ -498,6 +501,7 @@ app.all('*', async (c) => {
|
|
| 498 |
}
|
| 499 |
if (shouldCreateTrace && traceIndex >= 0) {
|
| 500 |
requestTraces[traceIndex].timestamp_end = new Date().toISOString();
|
|
|
|
| 501 |
|
| 502 |
// Calculate duration if we have both timestamps
|
| 503 |
if (requestTraces[traceIndex].timestamp_start && requestTraces[traceIndex].timestamp_end) {
|
|
|
|
| 61 |
arguments?: any;
|
| 62 |
provider?: string;
|
| 63 |
duration_ms?: number;
|
| 64 |
+
status_code?: number;
|
| 65 |
}[] = [];
|
| 66 |
|
| 67 |
let lastTraceBatchTime = Date.now();
|
|
|
|
| 247 |
}
|
| 248 |
});
|
| 249 |
|
| 250 |
+
async function storeStreamedResponse(streamToLog: ReadableStream<Uint8Array>, contentType: string | null, targetUrl: string, traceIndex: number, statusCode: number) {
|
| 251 |
const reader = streamToLog.getReader();
|
| 252 |
const chunks: Uint8Array[] = [];
|
| 253 |
|
| 254 |
try {
|
| 255 |
+
requestTraces[traceIndex].status_code = statusCode;
|
| 256 |
+
|
| 257 |
while (true) {
|
| 258 |
const { done, value } = await reader.read();
|
| 259 |
if (done) break;
|
|
|
|
| 486 |
const contentType = response.headers.get('content-type');
|
| 487 |
|
| 488 |
if (shouldCreateTrace && traceIndex >= 0) {
|
| 489 |
+
storeStreamedResponse(streamForStorage, contentType, targetUrl, traceIndex, response.status).catch(err => {
|
| 490 |
console.error("Error in background stream storage:", err);
|
| 491 |
});
|
| 492 |
}
|
|
|
|
| 501 |
}
|
| 502 |
if (shouldCreateTrace && traceIndex >= 0) {
|
| 503 |
requestTraces[traceIndex].timestamp_end = new Date().toISOString();
|
| 504 |
+
requestTraces[traceIndex].status_code = response.status;
|
| 505 |
|
| 506 |
// Calculate duration if we have both timestamps
|
| 507 |
if (requestTraces[traceIndex].timestamp_start && requestTraces[traceIndex].timestamp_end) {
|