@forklaunch/core 0.9.21 → 0.9.22

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/lib/http/index.js CHANGED
@@ -90,36 +90,6 @@ function cors(corsOptions) {
90
90
  };
91
91
  }
92
92
 
93
- // src/http/middleware/request/createContext.middleware.ts
94
- var import_api = require("@opentelemetry/api");
95
- var import_uuid = require("uuid");
96
-
97
- // src/http/telemetry/constants.ts
98
- var import_semantic_conventions = require("@opentelemetry/semantic-conventions");
99
- var ATTR_API_NAME = "api.name";
100
- var ATTR_CORRELATION_ID = "correlation.id";
101
-
102
- // src/http/middleware/request/createContext.middleware.ts
103
- function createContext(schemaValidator) {
104
- return function setContext(req, res, next) {
105
- req.schemaValidator = schemaValidator;
106
- let correlationId = (0, import_uuid.v4)();
107
- if (req.headers["x-correlation-id"]) {
108
- correlationId = req.headers["x-correlation-id"];
109
- }
110
- res.setHeader("x-correlation-id", correlationId);
111
- req.context = {
112
- correlationId
113
- };
114
- const span = import_api.trace.getActiveSpan();
115
- if (span != null) {
116
- req.context.span = span;
117
- req.context.span?.setAttribute(ATTR_CORRELATION_ID, correlationId);
118
- }
119
- next?.();
120
- };
121
- }
122
-
123
93
  // src/http/guards/isForklaunchRouter.ts
124
94
  function isForklaunchRouter(maybeForklaunchRouter) {
125
95
  return maybeForklaunchRouter != null && typeof maybeForklaunchRouter === "object" && "basePath" in maybeForklaunchRouter && "routes" in maybeForklaunchRouter && Array.isArray(maybeForklaunchRouter.routes);
@@ -295,6 +265,36 @@ async function parseRequestAuth(req, res, next) {
295
265
  next?.();
296
266
  }
297
267
 
268
+ // src/http/middleware/request/createContext.middleware.ts
269
+ var import_api = require("@opentelemetry/api");
270
+ var import_uuid = require("uuid");
271
+
272
+ // src/http/telemetry/constants.ts
273
+ var import_semantic_conventions = require("@opentelemetry/semantic-conventions");
274
+ var ATTR_API_NAME = "api.name";
275
+ var ATTR_CORRELATION_ID = "correlation.id";
276
+
277
+ // src/http/middleware/request/createContext.middleware.ts
278
+ function createContext(schemaValidator) {
279
+ return function setContext(req, res, next) {
280
+ req.schemaValidator = schemaValidator;
281
+ let correlationId = (0, import_uuid.v4)();
282
+ if (req.headers["x-correlation-id"]) {
283
+ correlationId = req.headers["x-correlation-id"];
284
+ }
285
+ res.setHeader("x-correlation-id", correlationId);
286
+ req.context = {
287
+ correlationId
288
+ };
289
+ const span = import_api.trace.getActiveSpan();
290
+ if (span != null) {
291
+ req.context.span = span;
292
+ req.context.span?.setAttribute(ATTR_CORRELATION_ID, correlationId);
293
+ }
294
+ next?.();
295
+ };
296
+ }
297
+
298
298
  // src/http/middleware/request/enrichDetails.middleware.ts
299
299
  var import_common4 = require("@forklaunch/common");
300
300
 
@@ -546,7 +546,7 @@ function enrichDetails(path, contractDetails, requestSchema, responseSchemas, op
546
546
  req.requestSchema = requestSchema;
547
547
  res.responseSchemas = responseSchemas;
548
548
  req.openTelemetryCollector = openTelemetryCollector;
549
- req.context.span?.setAttribute(ATTR_API_NAME, req.contractDetails?.name);
549
+ req.context?.span?.setAttribute(ATTR_API_NAME, req.contractDetails?.name);
550
550
  const startTime = process.hrtime();
551
551
  res.on("finish", () => {
552
552
  const [seconds, nanoseconds] = process.hrtime(startTime);
@@ -758,6 +758,25 @@ var ForklaunchExpressLikeRouter = class {
758
758
  this.postEnrichMiddleware = postEnrichMiddleware;
759
759
  this.openTelemetryCollector = openTelemetryCollector;
760
760
  this.basePath = basePath;
761
+ process.on("uncaughtException", (err) => {
762
+ this.openTelemetryCollector.log("error", `Uncaught exception: ${err}`);
763
+ process.exit(1);
764
+ });
765
+ process.on("unhandledRejection", (reason) => {
766
+ this.openTelemetryCollector.log(
767
+ "error",
768
+ `Unhandled rejection: ${reason}`
769
+ );
770
+ process.exit(1);
771
+ });
772
+ process.on("exit", () => {
773
+ this.openTelemetryCollector.log("info", "Shutting down application");
774
+ });
775
+ process.on("SIGINT", () => {
776
+ this.openTelemetryCollector.log("info", "Shutting down application");
777
+ process.exit(0);
778
+ });
779
+ this.internal.use(createContext(this.schemaValidator));
761
780
  }
762
781
  requestHandler;
763
782
  routers = [];
@@ -1383,25 +1402,6 @@ var ForklaunchExpressLikeApplication = class extends ForklaunchExpressLikeRouter
1383
1402
  this.postEnrichMiddleware = postEnrichMiddleware;
1384
1403
  this.openTelemetryCollector = openTelemetryCollector;
1385
1404
  this.appOptions = appOptions;
1386
- process.on("uncaughtException", (err) => {
1387
- this.openTelemetryCollector.log("error", `Uncaught exception: ${err}`);
1388
- process.exit(1);
1389
- });
1390
- process.on("unhandledRejection", (reason) => {
1391
- this.openTelemetryCollector.log(
1392
- "error",
1393
- `Unhandled rejection: ${reason}`
1394
- );
1395
- process.exit(1);
1396
- });
1397
- process.on("exit", () => {
1398
- this.openTelemetryCollector.log("info", "Shutting down application");
1399
- });
1400
- process.on("SIGINT", () => {
1401
- this.openTelemetryCollector.log("info", "Shutting down application");
1402
- process.exit(0);
1403
- });
1404
- this.internal.use(createContext(this.schemaValidator));
1405
1405
  this.internal.use(cors(this.appOptions?.cors ?? {}));
1406
1406
  }
1407
1407
  };