Skip to content

Commit 65ed659

Browse files
committed
chore: log cubesql queries
1 parent 085b54f commit 65ed659

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

packages/cubejs-api-gateway/src/gateway.ts

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,17 +381,48 @@ class ApiGateway {
381381
`${this.basePath}/v1/cubesql`,
382382
userMiddlewares,
383383
userAsyncHandler(async (req, res) => {
384+
const requestStarted = new Date();
385+
384386
res.setHeader('Content-Type', 'application/json');
385387
res.setHeader('Transfer-Encoding', 'chunked');
386388

387389
try {
388390
await this.assertApiScope('data', req.context?.securityContext);
391+
392+
const { query } = req.body;
393+
394+
this.log({
395+
type: 'Load Request',
396+
query: {
397+
sql: query,
398+
},
399+
apiType: 'sql',
400+
streaming: true
401+
}, req.context);
402+
389403
await this.sqlServer.execSql(req.body.query, res, req.context?.securityContext);
404+
405+
this.log(
406+
{
407+
type: 'Load Request Success',
408+
query: {
409+
sql: query,
410+
},
411+
duration: this.duration(requestStarted),
412+
apiType: 'sql',
413+
isDataQuery: true,
414+
isPlayground: Boolean(
415+
req.context?.signedWithPlaygroundAuthSecret
416+
),
417+
},
418+
req.context,
419+
);
390420
} catch (e: any) {
391421
this.handleError({
392422
e,
393423
context: req.context,
394-
res: this.resToResultFn(res)
424+
res: this.resToResultFn(res),
425+
requestStarted
395426
});
396427
}
397428
})

0 commit comments

Comments
 (0)