Skip to content
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
5 changes: 5 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ const DashboardFinancialHistoryScreen = lazy(() => import('./screens/dashboard-f
const DashboardFinancialLiveScreen = lazy(() => import('./screens/dashboard-financial-live.screen'));
const DashboardFinancialExpensesScreen = lazy(() => import('./screens/dashboard-financial-expenses.screen'));
const DashboardFinancialLiquidityScreen = lazy(() => import('./screens/dashboard-financial-liquidity.screen'));
const DashboardRealunitTracingScreen = lazy(() => import('./screens/dashboard-realunit-tracing.screen'));
const SitemapScreen = lazy(() => import('./screens/sitemap.screen'));

setupLanguages();
Expand Down Expand Up @@ -548,6 +549,10 @@ export const Routes = [
},
],
},
{
path: 'realunit-tracing',
element: withSuspense(<DashboardRealunitTracingScreen />),
},
],
},
],
Expand Down
72 changes: 72 additions & 0 deletions src/hooks/realunit-tracing.hook.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { useApi } from '@dfx.swiss/react';
import { useMemo } from 'react';

export interface LogQueryColumn {
name: string;
type: string;
}

export interface LogQueryResult {
columns: LogQueryColumn[];
rows: unknown[][];
}

export interface ParsedTrace {
timestamp: string;
method: string;
url: string;
pathPattern: string;
status: number;
durationMs: number;
client: string;
ip: string;
}

const TRACE_HEADLINE_RE =
/^\[RealUnitTrace\]\s+([A-Z]+)\s+(\S+)\s+→\s+(\d{3})\s+\((\d+)ms\)\s+client=(\S+?)\s+ip=(\S+)/;

function normalizePath(url: string): string {
const path = url.split('?')[0];
return path
.split('/')
.map((seg) => {
if (/^0x[a-f0-9]{40}$/i.test(seg)) return ':address';
if (/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/i.test(seg)) return ':uuid';
if (/^\d+$/.test(seg)) return ':id';
return seg;
})
.join('/');
}

export function parseTrace(timestamp: string, message: string): ParsedTrace | null {
const m = message.match(TRACE_HEADLINE_RE);
if (!m) return null;
return {
timestamp,
method: m[1],
url: m[2],
pathPattern: normalizePath(m[2]),
status: parseInt(m[3], 10),
durationMs: parseInt(m[4], 10),
client: m[5],
ip: m[6],
};
}

export function useRealunitTracing() {
const { call } = useApi();

async function getRealunitTraces(hours: number): Promise<LogQueryResult> {
return call<LogQueryResult>({
url: 'gs/debug/logs',
method: 'POST',
data: {
template: 'traces-by-message',
messageFilter: 'RealUnitTrace',
hours,
},
});
}

return useMemo(() => ({ getRealunitTraces }), [call]);
}
Loading
Loading