@mandujs/core 0.20.7 → 0.20.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mandujs/core",
3
- "version": "0.20.7",
3
+ "version": "0.20.8",
4
4
  "description": "Mandu Framework Core - Spec, Generator, Guard, Runtime",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
@@ -12,6 +12,7 @@
12
12
  "./testing": "./src/testing/index.ts",
13
13
  "./plugins": "./src/plugins/index.ts",
14
14
  "./error": "./src/error/index.ts",
15
+ "./observability": "./src/observability/index.ts",
15
16
  "./bundler/prerender": "./src/bundler/prerender.ts",
16
17
  "./*": "./src/*"
17
18
  },
@@ -40,6 +40,7 @@ import {
40
40
  } from "./cors";
41
41
  import { validateImportPath } from "./security";
42
42
  import { KITCHEN_PREFIX, KitchenHandler, recordRequest } from "../kitchen/kitchen-handler";
43
+ import { eventBus } from "../observability/event-bus";
43
44
  import {
44
45
  type MiddlewareFn,
45
46
  type MiddlewareConfig,
@@ -1021,6 +1022,8 @@ async function handleInternalCacheControlRequest(
1021
1022
 
1022
1023
  async function handleRequest(req: Request, router: Router, registry: ServerRegistry): Promise<Response> {
1023
1024
  const requestStart = Date.now();
1025
+ // Phase 1-4: Correlation ID — 한 요청에서 발생하는 모든 이벤트를 추적
1026
+ const correlationId = req.headers.get("x-mandu-request-id") ?? crypto.randomUUID();
1024
1027
  const result = await handleRequestInternal(req, router, registry);
1025
1028
 
1026
1029
  if (!result.ok) {
@@ -1035,7 +1038,17 @@ async function handleRequest(req: Request, router: Router, registry: ServerRegis
1035
1038
  if (!p.startsWith("/.mandu/") && !p.startsWith("/__kitchen")) {
1036
1039
  const elapsed = Date.now() - requestStart;
1037
1040
  console.log(`[${new Date().toLocaleTimeString()}] ${req.method} ${p} ${errorResponse.status} ${elapsed}ms`);
1038
- recordRequest({ id: crypto.randomUUID(), method: req.method, path: p, status: errorResponse.status, duration: elapsed, timestamp: Date.now() });
1041
+ recordRequest({ id: correlationId, method: req.method, path: p, status: errorResponse.status, duration: elapsed, timestamp: Date.now() });
1042
+ // Phase 1-2: HTTP 요청 → EventBus
1043
+ eventBus.emit({
1044
+ type: "http",
1045
+ severity: errorResponse.status >= 500 ? "error" : errorResponse.status >= 400 ? "warn" : "info",
1046
+ source: "server",
1047
+ correlationId,
1048
+ message: `${req.method} ${p} ${errorResponse.status}`,
1049
+ duration: elapsed,
1050
+ data: { method: req.method, path: p, status: errorResponse.status, error: true },
1051
+ });
1039
1052
  }
1040
1053
  }
1041
1054
  return errorResponse;
@@ -1057,7 +1070,17 @@ async function handleRequest(req: Request, router: Router, registry: ServerRegis
1057
1070
  const cacheHdr = result.value.headers.get("X-Mandu-Cache") ?? "";
1058
1071
  const cacheTag = cacheHdr ? ` ${cacheHdr}` : "";
1059
1072
  console.log(`[${new Date().toLocaleTimeString()}] ${req.method} ${p} ${status} ${elapsed}ms${cacheTag}`);
1060
- recordRequest({ id: crypto.randomUUID(), method: req.method, path: p, status, duration: elapsed, timestamp: Date.now(), cacheStatus: cacheHdr || undefined });
1073
+ recordRequest({ id: correlationId, method: req.method, path: p, status, duration: elapsed, timestamp: Date.now(), cacheStatus: cacheHdr || undefined });
1074
+ // Phase 1-2: HTTP 요청 → EventBus
1075
+ eventBus.emit({
1076
+ type: "http",
1077
+ severity: status >= 500 ? "error" : status >= 400 ? "warn" : "info",
1078
+ source: "server",
1079
+ correlationId,
1080
+ message: `${req.method} ${p} ${status}${cacheTag}`,
1081
+ duration: elapsed,
1082
+ data: { method: req.method, path: p, status, cache: cacheHdr || undefined },
1083
+ });
1061
1084
  }
1062
1085
  }
1063
1086