@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.
@@ -15,41 +15,6 @@ function cors(corsOptions) {
15
15
  };
16
16
  }
17
17
 
18
- // src/http/middleware/request/createContext.middleware.ts
19
- import { trace } from "@opentelemetry/api";
20
- import { v4 } from "uuid";
21
-
22
- // src/http/telemetry/constants.ts
23
- import {
24
- ATTR_HTTP_REQUEST_METHOD,
25
- ATTR_HTTP_RESPONSE_STATUS_CODE,
26
- ATTR_HTTP_ROUTE,
27
- ATTR_SERVICE_NAME
28
- } from "@opentelemetry/semantic-conventions";
29
- var ATTR_API_NAME = "api.name";
30
- var ATTR_CORRELATION_ID = "correlation.id";
31
-
32
- // src/http/middleware/request/createContext.middleware.ts
33
- function createContext(schemaValidator) {
34
- return function setContext(req, res, next) {
35
- req.schemaValidator = schemaValidator;
36
- let correlationId = v4();
37
- if (req.headers["x-correlation-id"]) {
38
- correlationId = req.headers["x-correlation-id"];
39
- }
40
- res.setHeader("x-correlation-id", correlationId);
41
- req.context = {
42
- correlationId
43
- };
44
- const span = trace.getActiveSpan();
45
- if (span != null) {
46
- req.context.span = span;
47
- req.context.span?.setAttribute(ATTR_CORRELATION_ID, correlationId);
48
- }
49
- next?.();
50
- };
51
- }
52
-
53
18
  // src/http/guards/isForklaunchRouter.ts
54
19
  function isForklaunchRouter(maybeForklaunchRouter) {
55
20
  return maybeForklaunchRouter != null && typeof maybeForklaunchRouter === "object" && "basePath" in maybeForklaunchRouter && "routes" in maybeForklaunchRouter && Array.isArray(maybeForklaunchRouter.routes);
@@ -225,6 +190,41 @@ async function parseRequestAuth(req, res, next) {
225
190
  next?.();
226
191
  }
227
192
 
193
+ // src/http/middleware/request/createContext.middleware.ts
194
+ import { trace } from "@opentelemetry/api";
195
+ import { v4 } from "uuid";
196
+
197
+ // src/http/telemetry/constants.ts
198
+ import {
199
+ ATTR_HTTP_REQUEST_METHOD,
200
+ ATTR_HTTP_RESPONSE_STATUS_CODE,
201
+ ATTR_HTTP_ROUTE,
202
+ ATTR_SERVICE_NAME
203
+ } from "@opentelemetry/semantic-conventions";
204
+ var ATTR_API_NAME = "api.name";
205
+ var ATTR_CORRELATION_ID = "correlation.id";
206
+
207
+ // src/http/middleware/request/createContext.middleware.ts
208
+ function createContext(schemaValidator) {
209
+ return function setContext(req, res, next) {
210
+ req.schemaValidator = schemaValidator;
211
+ let correlationId = v4();
212
+ if (req.headers["x-correlation-id"]) {
213
+ correlationId = req.headers["x-correlation-id"];
214
+ }
215
+ res.setHeader("x-correlation-id", correlationId);
216
+ req.context = {
217
+ correlationId
218
+ };
219
+ const span = trace.getActiveSpan();
220
+ if (span != null) {
221
+ req.context.span = span;
222
+ req.context.span?.setAttribute(ATTR_CORRELATION_ID, correlationId);
223
+ }
224
+ next?.();
225
+ };
226
+ }
227
+
228
228
  // src/http/middleware/request/enrichDetails.middleware.ts
229
229
  import { getEnvVar as getEnvVar2 } from "@forklaunch/common";
230
230
 
@@ -480,7 +480,7 @@ function enrichDetails(path, contractDetails, requestSchema, responseSchemas, op
480
480
  req.requestSchema = requestSchema;
481
481
  res.responseSchemas = responseSchemas;
482
482
  req.openTelemetryCollector = openTelemetryCollector;
483
- req.context.span?.setAttribute(ATTR_API_NAME, req.contractDetails?.name);
483
+ req.context?.span?.setAttribute(ATTR_API_NAME, req.contractDetails?.name);
484
484
  const startTime = process.hrtime();
485
485
  res.on("finish", () => {
486
486
  const [seconds, nanoseconds] = process.hrtime(startTime);
@@ -694,6 +694,25 @@ var ForklaunchExpressLikeRouter = class {
694
694
  this.postEnrichMiddleware = postEnrichMiddleware;
695
695
  this.openTelemetryCollector = openTelemetryCollector;
696
696
  this.basePath = basePath;
697
+ process.on("uncaughtException", (err) => {
698
+ this.openTelemetryCollector.log("error", `Uncaught exception: ${err}`);
699
+ process.exit(1);
700
+ });
701
+ process.on("unhandledRejection", (reason) => {
702
+ this.openTelemetryCollector.log(
703
+ "error",
704
+ `Unhandled rejection: ${reason}`
705
+ );
706
+ process.exit(1);
707
+ });
708
+ process.on("exit", () => {
709
+ this.openTelemetryCollector.log("info", "Shutting down application");
710
+ });
711
+ process.on("SIGINT", () => {
712
+ this.openTelemetryCollector.log("info", "Shutting down application");
713
+ process.exit(0);
714
+ });
715
+ this.internal.use(createContext(this.schemaValidator));
697
716
  }
698
717
  requestHandler;
699
718
  routers = [];
@@ -1319,25 +1338,6 @@ var ForklaunchExpressLikeApplication = class extends ForklaunchExpressLikeRouter
1319
1338
  this.postEnrichMiddleware = postEnrichMiddleware;
1320
1339
  this.openTelemetryCollector = openTelemetryCollector;
1321
1340
  this.appOptions = appOptions;
1322
- process.on("uncaughtException", (err) => {
1323
- this.openTelemetryCollector.log("error", `Uncaught exception: ${err}`);
1324
- process.exit(1);
1325
- });
1326
- process.on("unhandledRejection", (reason) => {
1327
- this.openTelemetryCollector.log(
1328
- "error",
1329
- `Unhandled rejection: ${reason}`
1330
- );
1331
- process.exit(1);
1332
- });
1333
- process.on("exit", () => {
1334
- this.openTelemetryCollector.log("info", "Shutting down application");
1335
- });
1336
- process.on("SIGINT", () => {
1337
- this.openTelemetryCollector.log("info", "Shutting down application");
1338
- process.exit(0);
1339
- });
1340
- this.internal.use(createContext(this.schemaValidator));
1341
1341
  this.internal.use(cors(this.appOptions?.cors ?? {}));
1342
1342
  }
1343
1343
  };