( request: FastifyRequest, reply: FastifyReply )
| 16 | }; |
| 17 | |
| 18 | export async function requestLoggingHook( |
| 19 | request: FastifyRequest, |
| 20 | reply: FastifyReply |
| 21 | ) { |
| 22 | if (ignoreMethods.includes(request.method)) { |
| 23 | return; |
| 24 | } |
| 25 | if (ignoreLog.some((path) => request.url.startsWith(path))) { |
| 26 | return; |
| 27 | } |
| 28 | if (request.url.includes('trpc')) { |
| 29 | request.log.info( |
| 30 | { |
| 31 | url: request.url.split('?')[0], |
| 32 | method: request.method, |
| 33 | input: getTrpcInput(request), |
| 34 | elapsed: reply.elapsedTime, |
| 35 | }, |
| 36 | 'request done', |
| 37 | ); |
| 38 | } else { |
| 39 | const payload: { |
| 40 | url: string; |
| 41 | method: string; |
| 42 | elapsed: number; |
| 43 | headers: Record<string, string | string[] | undefined>; |
| 44 | body?: unknown; |
| 45 | } = { |
| 46 | url: request.url, |
| 47 | method: request.method, |
| 48 | elapsed: reply.elapsedTime, |
| 49 | headers: pick( |
| 50 | ['openpanel-client-id', 'openpanel-sdk-name', 'openpanel-sdk-version'], |
| 51 | request.headers |
| 52 | ), |
| 53 | }; |
| 54 | |
| 55 | if (payload.url.startsWith('/track')) { |
| 56 | payload.body = request.body; |
| 57 | } |
| 58 | |
| 59 | request.log.info(payload, 'request done'); |
| 60 | } |
| 61 | } |
nothing calls this directly
no test coverage detected