@webtypen/webframez-core 0.3.41 → 0.3.43

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.
@@ -54,6 +54,8 @@ export declare class BuildApplication {
54
54
  private readonly buildId;
55
55
  constructor(projectRoot: string, config: WebframezAppConfig, options: BuildApplicationOptions);
56
56
  run(): Promise<void>;
57
+ private logBuildStep;
58
+ private runStep;
57
59
  private createContext;
58
60
  private callHook;
59
61
  private runTypescriptBuild;
@@ -20,6 +20,9 @@ const node_child_process_1 = require("node:child_process");
20
20
  function timestamp() {
21
21
  return new Date().toISOString().replace(/[-:TZ.]/g, "");
22
22
  }
23
+ function logTimestamp() {
24
+ return new Date().toISOString();
25
+ }
23
26
  function normalizePackageWebframezPlugins(value) {
24
27
  if (!value) {
25
28
  return [];
@@ -52,19 +55,21 @@ class BuildApplication {
52
55
  return __awaiter(this, void 0, void 0, function* () {
53
56
  const context = this.createContext();
54
57
  const plugins = this.loadPlugins();
58
+ const startedAt = Date.now();
59
+ this.logBuildStep("start", `outDir=${this.outDir}`);
55
60
  yield promises_1.default.rm(this.stagingDir, { recursive: true, force: true });
56
61
  yield promises_1.default.mkdir(this.stagingDir, { recursive: true });
57
62
  try {
58
63
  yield this.callHook(plugins, "beforeBuild", context);
59
- yield this.runTypescriptBuild(context);
64
+ yield this.runStep("typescript", () => this.runTypescriptBuild(context));
60
65
  yield this.callHook(plugins, "afterTypescriptBuild", context);
61
- yield this.copyRuntimeFiles();
66
+ yield this.runStep("runtime files", () => this.copyRuntimeFiles());
62
67
  yield this.callHook(plugins, "afterRuntimeFilesCopied", context);
63
68
  yield this.callHook(plugins, "buildAssets", context);
64
- yield this.validateCoreBuild();
69
+ yield this.runStep("core validation", () => this.validateCoreBuild());
65
70
  yield this.callHook(plugins, "validateBuild", context);
66
- yield this.promoteBuild();
67
- console.log(`[webframez] Build ready: ${node_path_1.default.relative(this.projectRoot, this.outDir) || this.outDir}`);
71
+ yield this.runStep("promote", () => this.promoteBuild());
72
+ console.log(`[webframez] Build ready: ${node_path_1.default.relative(this.projectRoot, this.outDir) || this.outDir} (${Math.round((Date.now() - startedAt) / 1000)}s)`);
68
73
  }
69
74
  catch (error) {
70
75
  yield promises_1.default.rm(this.stagingDir, { recursive: true, force: true });
@@ -72,6 +77,24 @@ class BuildApplication {
72
77
  }
73
78
  });
74
79
  }
80
+ logBuildStep(label, details = "") {
81
+ console.log(`[webframez] [${logTimestamp()}] ${label}${details ? `: ${details}` : ""}`);
82
+ }
83
+ runStep(label, callback) {
84
+ return __awaiter(this, void 0, void 0, function* () {
85
+ const startedAt = Date.now();
86
+ this.logBuildStep(`${label}:start`);
87
+ try {
88
+ const result = yield callback();
89
+ this.logBuildStep(`${label}:done`, `${Math.round((Date.now() - startedAt) / 1000)}s`);
90
+ return result;
91
+ }
92
+ catch (error) {
93
+ this.logBuildStep(`${label}:failed`, `${Math.round((Date.now() - startedAt) / 1000)}s`);
94
+ throw error;
95
+ }
96
+ });
97
+ }
75
98
  createContext() {
76
99
  return {
77
100
  projectRoot: this.projectRoot,
@@ -236,7 +259,13 @@ class BuildApplication {
236
259
  env: Object.assign(Object.assign({}, process.env), envAdditions),
237
260
  });
238
261
  child.on("error", reject);
239
- child.on("close", (code) => resolve(code || 0));
262
+ child.on("close", (code, signal) => {
263
+ if (signal) {
264
+ reject(new Error(`${binaryName} exited with signal ${signal}`));
265
+ return;
266
+ }
267
+ resolve(code !== null && code !== void 0 ? code : 0);
268
+ });
240
269
  });
241
270
  }
242
271
  resolveBinary(name) {
@@ -15,6 +15,8 @@ export type WebframezOperationContext = {
15
15
  timestamp: Date;
16
16
  attributes?: WebframezHookAttributes;
17
17
  error?: unknown;
18
+ request?: unknown;
19
+ response?: unknown;
18
20
  };
19
21
  export type WebframezLifecycleEvent<TEventName extends WebframezHookEventName = WebframezHookEventName> = {
20
22
  type: TEventName;
@@ -20,6 +20,18 @@ const querystring_1 = __importDefault(require("querystring"));
20
20
  const url_1 = __importDefault(require("url"));
21
21
  const ErrorHandler_1 = require("../ErrorHandling/ErrorHandler");
22
22
  const WebframezHooks_1 = require("../Hooks/WebframezHooks");
23
+ function requestTelemetryAttributes(request) {
24
+ if (!request || !request.url) {
25
+ return {};
26
+ }
27
+ const target = request.url;
28
+ const path = target.indexOf("?") >= 0 ? target.substring(0, target.indexOf("?")) : target;
29
+ return {
30
+ "url.path": path,
31
+ "http.target": target,
32
+ "webframez.request.path": path,
33
+ };
34
+ }
23
35
  class RouterFacade {
24
36
  constructor() {
25
37
  /**
@@ -467,11 +479,9 @@ class RouterFacade {
467
479
  name: `${fallbackRequest.method || "HTTP"} unmatched`,
468
480
  status: "error",
469
481
  error: e,
470
- attributes: {
471
- "http.request.method": fallbackRequest.method || null,
472
- "http.response.status_code": statusCode,
473
- "webframez.mode": this.mode,
474
- },
482
+ request: fallbackRequest,
483
+ response,
484
+ attributes: Object.assign(Object.assign({ "http.request.method": fallbackRequest.method || null, "http.response.status_code": statusCode }, requestTelemetryAttributes(fallbackRequest)), { "webframez.mode": this.mode }),
475
485
  });
476
486
  return errorResult;
477
487
  }
@@ -486,11 +496,9 @@ class RouterFacade {
486
496
  operationId: httpOperationId,
487
497
  name: `${request.method} unmatched`,
488
498
  status: "ok",
489
- attributes: {
490
- "http.request.method": request.method,
491
- "http.response.status_code": 404,
492
- "webframez.mode": this.mode,
493
- },
499
+ request,
500
+ response,
501
+ attributes: Object.assign(Object.assign({ "http.request.method": request.method, "http.response.status_code": 404 }, requestTelemetryAttributes(request)), { "webframez.mode": this.mode }),
494
502
  });
495
503
  return notFoundResult;
496
504
  }
@@ -500,13 +508,9 @@ class RouterFacade {
500
508
  operationId: httpOperationId,
501
509
  name: `${request.method} ${route.path}`,
502
510
  status: "ok",
503
- attributes: {
504
- "http.request.method": request.method,
505
- "http.response.status_code": 404,
506
- "url.template": route.path,
507
- "webframez.route": route.path,
508
- "webframez.mode": this.mode,
509
- },
511
+ request,
512
+ response,
513
+ attributes: Object.assign(Object.assign({ "http.request.method": request.method, "http.response.status_code": 404, "url.template": route.path, "webframez.route": route.path }, requestTelemetryAttributes(request)), { "webframez.mode": this.mode }),
510
514
  });
511
515
  return missingRouteResult;
512
516
  }
@@ -518,13 +522,9 @@ class RouterFacade {
518
522
  operationId: httpOperationId,
519
523
  name: `${request.method} ${route.path}`,
520
524
  status: "ok",
521
- attributes: {
522
- "http.request.method": request.method,
523
- "http.response.status_code": response.statusCode || 200,
524
- "url.template": route.path,
525
- "webframez.route": route.path,
526
- "webframez.mode": this.mode,
527
- },
525
+ request,
526
+ response,
527
+ attributes: Object.assign(Object.assign({ "http.request.method": request.method, "http.response.status_code": response.statusCode || 200, "url.template": route.path, "webframez.route": route.path }, requestTelemetryAttributes(request)), { "webframez.mode": this.mode }),
528
528
  });
529
529
  return optionsResult;
530
530
  }
@@ -565,13 +565,9 @@ class RouterFacade {
565
565
  operationId: httpOperationId,
566
566
  name: `${request.method} ${route.path}`,
567
567
  status: "ok",
568
- attributes: {
569
- "http.request.method": request.method,
570
- "http.response.status_code": 404,
571
- "url.template": route.path,
572
- "webframez.route": route.path,
573
- "webframez.mode": this.mode,
574
- },
568
+ request,
569
+ response,
570
+ attributes: Object.assign(Object.assign({ "http.request.method": request.method, "http.response.status_code": 404, "url.template": route.path, "webframez.route": route.path }, requestTelemetryAttributes(request)), { "webframez.mode": this.mode }),
575
571
  });
576
572
  return unknownMethodResult;
577
573
  }
@@ -597,13 +593,9 @@ class RouterFacade {
597
593
  operationId: httpOperationId,
598
594
  name: `${request.method} ${route.path}`,
599
595
  status: "ok",
600
- attributes: {
601
- "http.request.method": request.method,
602
- "http.response.status_code": response.statusCode || 200,
603
- "url.template": route.path,
604
- "webframez.route": route.path,
605
- "webframez.mode": this.mode,
606
- },
596
+ request,
597
+ response,
598
+ attributes: Object.assign(Object.assign({ "http.request.method": request.method, "http.response.status_code": response.statusCode || 200, "url.template": route.path, "webframez.route": route.path }, requestTelemetryAttributes(request)), { "webframez.mode": this.mode }),
607
599
  });
608
600
  return returnResult;
609
601
  }
@@ -615,13 +607,9 @@ class RouterFacade {
615
607
  name: `${request.method} ${route.path}`,
616
608
  status: "error",
617
609
  error: e.reason || e,
618
- attributes: {
619
- "http.request.method": request.method,
620
- "http.response.status_code": 500,
621
- "url.template": route.path,
622
- "webframez.route": route.path,
623
- "webframez.mode": this.mode,
624
- },
610
+ request,
611
+ response,
612
+ attributes: Object.assign(Object.assign({ "http.request.method": request.method, "http.response.status_code": 500, "url.template": route.path, "webframez.route": route.path }, requestTelemetryAttributes(request)), { "webframez.mode": this.mode }),
625
613
  });
626
614
  return middlewareErrorResult;
627
615
  }
@@ -659,13 +647,9 @@ class RouterFacade {
659
647
  name: `${request.method} ${route.path}`,
660
648
  status: "error",
661
649
  error: e,
662
- attributes: {
663
- "http.request.method": request.method,
664
- "http.response.status_code": 500,
665
- "url.template": route.path,
666
- "webframez.route": route.path,
667
- "webframez.mode": this.mode,
668
- },
650
+ request,
651
+ response,
652
+ attributes: Object.assign(Object.assign({ "http.request.method": request.method, "http.response.status_code": 500, "url.template": route.path, "webframez.route": route.path }, requestTelemetryAttributes(request)), { "webframez.mode": this.mode }),
669
653
  });
670
654
  return errorResult;
671
655
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webtypen/webframez-core",
3
- "version": "0.3.41",
3
+ "version": "0.3.43",
4
4
  "description": "The core package of the typescript based webframez (web-framework) by webtypen.de",
5
5
  "homepage": "https://webtypen.de/",
6
6
  "license": "MIT",