Skip to content

Commit

Permalink
Allow to use the 'sent response' log messages to monitor page perform…
Browse files Browse the repository at this point in the history
…ance
  • Loading branch information
thewilkybarkid committed May 15, 2024
1 parent 6d20f16 commit 7304a27
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ export const app = (config: ConfigEnv) => {
.use((req, res, next) => {
const requestId = req.header('Fly-Request-Id') ?? null

const startTime = Date.now()

pipe(
{
method: req.method,
Expand All @@ -145,7 +147,16 @@ export const app = (config: ConfigEnv) => {
)(config)()

res.once('finish', () => {
pipe({ status: res.statusCode, requestId }, L.infoP('Sent HTTP response'))(config)()
pipe(
{
method: req.method,
url: req.url,
status: res.statusCode,
requestId,
time: Date.now() - startTime,
},
L.infoP('Sent HTTP response'),
)(config)()
})

res.once('close', () => {
Expand All @@ -154,7 +165,13 @@ export const app = (config: ConfigEnv) => {
}

pipe(
{ status: res.statusCode, requestId },
{
method: req.method,
url: req.url,
status: res.statusCode,
requestId,
time: Date.now() - startTime,
},
L.warnP('HTTP response may not have been completely sent'),
)(config)()
})
Expand Down

0 comments on commit 7304a27

Please sign in to comment.