feat(logging): enhance HTTP request logging with additional payload details

- Introduced new fields in the HttpPageFetchLog model to capture request and response headers, bodies, and method for improved logging granularity.
- Updated the logging service to serialize and store these new details during HTTP fetch operations, enhancing traceability and debugging capabilities.
- Modified the clickTtHttpPageRoutes to include the new logging features, allowing for optional payload inclusion in log queries.
This commit is contained in:
Torsten Schulz (local)
2026-03-10 22:26:37 +01:00
parent 4f3a1829ca
commit 0e4d1707fd
6 changed files with 143 additions and 23 deletions

View File

@@ -24,6 +24,32 @@ const ASSOCIATION_TO_DOMAIN = {
const SNIPPET_MAX_LEN = 2000;
function serializeHeaders(headers) {
if (!headers) return null;
if (typeof headers.raw === 'function') {
try {
return JSON.stringify(headers.raw());
} catch {
// Fallback below
}
}
try {
const entries = {};
if (typeof headers.forEach === 'function') {
headers.forEach((value, key) => {
entries[key] = value;
});
} else {
Object.assign(entries, headers);
}
return JSON.stringify(entries);
} catch {
return null;
}
}
/**
* Ermittelt die click-TT-Domain für einen Verband
*/
@@ -134,6 +160,8 @@ async function fetchWithLogging(options) {
const responseBody = await response.text();
const success = response.ok;
const snippet = createResponseSnippet(responseBody);
const requestHeaders = serializeHeaders(headers);
const responseHeaders = serializeHeaders(response.headers);
await HttpPageFetchLog.create({
userId,
@@ -143,10 +171,16 @@ async function fetchWithLogging(options) {
association,
championship,
clubIdParam,
requestMethod: method,
requestHeaders,
requestBody: body,
httpStatus: response.status,
success,
responseSnippet: snippet,
contentType,
responseHeaders,
responseBody,
responseUrl: response.url || url,
errorMessage: success ? null : `HTTP ${response.status}: ${response.statusText}`,
executionTimeMs,
});
@@ -172,10 +206,16 @@ async function fetchWithLogging(options) {
association,
championship,
clubIdParam,
requestMethod: method,
requestHeaders: serializeHeaders(headers),
requestBody: body,
httpStatus: null,
success: false,
responseSnippet: null,
contentType: null,
responseHeaders: null,
responseBody: null,
responseUrl: null,
errorMessage: error.message,
executionTimeMs,
});