Skip to content

Commit

Permalink
Disable async hook performance monitoring
Browse files Browse the repository at this point in the history
  • Loading branch information
a3957273 committed May 3, 2024
1 parent 93c800e commit fd39442
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 17 deletions.
16 changes: 2 additions & 14 deletions backend/src/routes/middleware/requestId.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,8 @@
import { createNamespace, getNamespace } from 'cls-hooked'
import { NextFunction, Request, Response } from 'express'
import { v4 as uuidv4 } from 'uuid'

export async function requestId(req: Request, res: Response, next: NextFunction) {
req.reqId = (req.headers['x-request-id'] as string) || uuidv4()
const session = createNamespace('bailo')
if (!session) {
next()
}
session.bindEmitter(req)
session.bindEmitter(res)
session.run(() => {
const ns = getNamespace('bailo')
if (ns) {
ns.set('reqId', req.reqId)
}
next()
})

next()
}
4 changes: 1 addition & 3 deletions backend/src/services/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { WritableStream } from 'node:stream/web'
import { OpenTelemetryBunyanStream } from '@opentelemetry/instrumentation-bunyan'
import bunyan from 'bunyan'
import chalk from 'chalk'
import { getNamespace } from 'cls-hooked'
import { omit } from 'lodash-es'
import path, { join } from 'path'
import util from 'util'
Expand Down Expand Up @@ -134,8 +133,7 @@ export class Writer extends WritableStream {
function productionStream() {
return {
write: (log) => {
const namespace = getNamespace('bailo')
process.stdout.write(`${JSON.stringify({ ...log, requestId: namespace?.get('reqId') })}\n`)
process.stdout.write(`${JSON.stringify(log)}\n`)
},
}
}
Expand Down

0 comments on commit fd39442

Please sign in to comment.