Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 44 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -552,8 +552,36 @@ app.get('/:visibility/fdas/:fdaId/data', async (req, res) => {
app.post('/plugin/cda/api/doQuery', async (req, res) => {
const startTime = Date.now();

const { path, dataAccessId, ...rest } = req.body;
const requestId = Math.random().toString(36).substring(7);

logger.info('[CDA REQUEST]', {
requestId,
method: req.method,
url: req.originalUrl,
headers: {
contentType: req.get('Content-Type'),
accept: req.get('Accept'),
fiwareService: req.get('Fiware-Service'),
},
query: req.query,
bodyKeys: Object.keys(req.body || {}),
paramKeys: Object.keys(req.body || {}).filter((k) => k.startsWith('param')),
timestamp: new Date().toISOString(),
});

logger.debug('[CDA REQUEST BODY STRINGIFIED]', {
requestId,
body: JSON.stringify(req.body),
});

const { path, dataAccessId } = req.body;

if (!path || !dataAccessId) {
logger.warn('[CDA BAD REQUEST]', {
requestId,
reason: 'Missing path or dataAccessId',
});

return res.status(400).json({
error: 'BadRequest',
description: 'Missing params in the request',
Expand All @@ -575,6 +603,21 @@ app.post('/plugin/cda/api/doQuery', async (req, res) => {
outputType: rawOutputType,
});

logger.info('[CDA RESPONSE]', {
requestId,
status: 200,
durationMs: Date.now() - startTime,
rows: result?.resultset?.length,
totalRows: result?.queryInfo?.totalRows,
});

logger.debug('[CDA RESPONSE DETAIL]', {
requestId,
metadata: result?.metadata,
queryInfo: result?.queryInfo,
sampleRows: result?.resultset?.slice(0, 2),
});

return sendRowsByOutputType(res, result, rawOutputType);
} catch (err) {
logger.error('Error executing query:', err);
Expand Down
Loading