Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable async hook performance monitoring #1260

Merged
merged 1 commit into from
May 7, 2024
Merged
Show file tree
Hide file tree
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
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
Loading