MCPcopy Create free account
hub / github.com/Openpanel-dev/openpanel / requestLoggingHook

Function requestLoggingHook

apps/api/src/hooks/request-logging.hook.ts:18–61  ·  view source on GitHub ↗
(
  request: FastifyRequest,
  reply: FastifyReply
)

Source from the content-addressed store, hash-verified

16};
17
18export 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}

Callers

nothing calls this directly

Calls 4

getTrpcInputFunction · 0.85
infoMethod · 0.80
pickFunction · 0.50
someMethod · 0.45

Tested by

no test coverage detected