MCPcopy Index your code
hub / github.com/getsentry/sentry-javascript / createRouteHook

Function createRouteHook

packages/hono/src/shared/patchRoute.ts:35–58  ·  view source on GitHub ↗

* Creates the two-phase state machine for the route hook. * * - Pre-activation: collects sub-app references into a pending set. * - Post-activation: instruments sub-apps immediately at mount time.

()

Source from the content-addressed store, hash-verified

33 * - Post-activation: instruments sub-apps immediately at mount time.
34 */
35function createRouteHook(): { handle: RouteHookHandle; onSubAppMounted: (subApp: HonoAny) => void } {
36 const pendingSubApps = new Set<HonoAny>();
37 let activated = false;
38
39 return {
40 handle: {
41 activate: () => {
42 activated = true;
43 },
44 getPendingSubApps: () => pendingSubApps,
45 },
46 onSubAppMounted: (subApp: HonoAny) => {
47 if (activated) {
48 DEBUG_BUILD && debug.log(`[hono] Instrumenting sub-app at mount time (${subApp.routes.length} routes).`);
49 wrapSubAppMiddleware(subApp.routes as HonoRoute[]);
50 patchAppRequest(subApp);
51 } else {
52 DEBUG_BUILD &&
53 debug.log(`[hono] Collecting sub-app for deferred instrumentation (${subApp.routes.length} routes).`);
54 pendingSubApps.add(subApp);
55 }
56 },
57 };
58}
59
60/**
61 * Installs a hook on `HonoBase.prototype.route` to intercept sub-app mounting.

Callers 1

Calls 4

patchAppRequestFunction · 0.90
wrapSubAppMiddlewareFunction · 0.85
logMethod · 0.65
addMethod · 0.65

Tested by

no test coverage detected