@jaypie/express 1.1.12 → 1.1.13

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/dist/module.cjs CHANGED
@@ -3,6 +3,7 @@
3
3
  var errors = require('@jaypie/errors');
4
4
  var core = require('@jaypie/core');
5
5
  var expressCors = require('cors');
6
+ var datadog = require('@jaypie/datadog');
6
7
  var serverlessExpress = require('@codegenie/serverless-express');
7
8
 
8
9
  //
@@ -290,6 +291,7 @@ const expressHandler = (handler, options = {}) => {
290
291
  // Validate
291
292
  //
292
293
  let {
294
+ chaos,
293
295
  locals,
294
296
  name,
295
297
  setup = [],
@@ -312,6 +314,13 @@ const expressHandler = (handler, options = {}) => {
312
314
  return async (req, res, ...params) => {
313
315
  // * This is the first line of code that runs when a request is received
314
316
 
317
+ // Set default chaos value
318
+ if (chaos === undefined) {
319
+ chaos =
320
+ process.env.PROJECT_CHAOS ||
321
+ core.getHeaderFrom(core.HTTP.HEADER.PROJECT.CHAOS, req);
322
+ }
323
+
315
324
  // Re-init the logger
316
325
  core.log.init();
317
326
  // Very low-level, internal sub-trace details
@@ -430,6 +439,7 @@ const expressHandler = (handler, options = {}) => {
430
439
 
431
440
  // Initialize after logging is set up
432
441
  jaypieFunction = core.jaypieHandler(handler, {
442
+ chaos,
433
443
  name,
434
444
  setup,
435
445
  teardown,
@@ -535,6 +545,45 @@ const expressHandler = (handler, options = {}) => {
535
545
  res: summarizeResponse(res, extras),
536
546
  });
537
547
 
548
+ // Submit metric if Datadog is configured
549
+ if (datadog.hasDatadogEnv()) {
550
+ // Construct path from baseUrl and url
551
+ let path = (req.baseUrl || "") + (req.url || "");
552
+ // Ensure path starts with /
553
+ if (!path.startsWith("/")) {
554
+ path = "/" + path;
555
+ }
556
+ // Remove trailing slash unless it's the root path
557
+ if (path.length > 1 && path.endsWith("/")) {
558
+ path = path.slice(0, -1);
559
+ }
560
+
561
+ // Replace UUIDs with :id for better aggregation
562
+ // Matches standard UUID v4 format (8-4-4-4-12 hex characters)
563
+ path = path.replace(
564
+ /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/gi,
565
+ ":id",
566
+ );
567
+
568
+ // Determine metric name based on environment variables
569
+ let metricPrefix = "project";
570
+ if (process.env.PROJECT_SPONSOR) {
571
+ metricPrefix = process.env.PROJECT_SPONSOR;
572
+ } else if (process.env.PROJECT_KEY) {
573
+ metricPrefix = `project.${process.env.PROJECT_KEY}`;
574
+ }
575
+
576
+ await datadog.submitMetric({
577
+ name: `${metricPrefix}.api.response`,
578
+ type: datadog.DATADOG.METRIC.TYPE.COUNT,
579
+ value: 1,
580
+ tags: {
581
+ code: res.statusCode,
582
+ path,
583
+ },
584
+ });
585
+ }
586
+
538
587
  // Clean up the public logger
539
588
  core.log.untag("handler");
540
589
 
@@ -1,6 +1,7 @@
1
1
  import { CorsError } from '@jaypie/errors';
2
- import { force, envBoolean, log, JAYPIE, HTTP, validate, jaypieHandler, UnhandledError, GatewayTimeoutError, UnavailableError, BadGatewayError, InternalError, TeapotError, GoneError, MethodNotAllowedError, NotFoundError, ForbiddenError, UnauthorizedError, BadRequestError, NotImplementedError } from '@jaypie/core';
2
+ import { force, envBoolean, log, JAYPIE, HTTP, validate, getHeaderFrom, jaypieHandler, UnhandledError, GatewayTimeoutError, UnavailableError, BadGatewayError, InternalError, TeapotError, GoneError, MethodNotAllowedError, NotFoundError, ForbiddenError, UnauthorizedError, BadRequestError, NotImplementedError } from '@jaypie/core';
3
3
  import expressCors from 'cors';
4
+ import { hasDatadogEnv, submitMetric, DATADOG } from '@jaypie/datadog';
4
5
  import { getCurrentInvoke } from '@codegenie/serverless-express';
5
6
 
6
7
  //
@@ -288,6 +289,7 @@ const expressHandler = (handler, options = {}) => {
288
289
  // Validate
289
290
  //
290
291
  let {
292
+ chaos,
291
293
  locals,
292
294
  name,
293
295
  setup = [],
@@ -310,6 +312,13 @@ const expressHandler = (handler, options = {}) => {
310
312
  return async (req, res, ...params) => {
311
313
  // * This is the first line of code that runs when a request is received
312
314
 
315
+ // Set default chaos value
316
+ if (chaos === undefined) {
317
+ chaos =
318
+ process.env.PROJECT_CHAOS ||
319
+ getHeaderFrom(HTTP.HEADER.PROJECT.CHAOS, req);
320
+ }
321
+
313
322
  // Re-init the logger
314
323
  log.init();
315
324
  // Very low-level, internal sub-trace details
@@ -428,6 +437,7 @@ const expressHandler = (handler, options = {}) => {
428
437
 
429
438
  // Initialize after logging is set up
430
439
  jaypieFunction = jaypieHandler(handler, {
440
+ chaos,
431
441
  name,
432
442
  setup,
433
443
  teardown,
@@ -533,6 +543,45 @@ const expressHandler = (handler, options = {}) => {
533
543
  res: summarizeResponse(res, extras),
534
544
  });
535
545
 
546
+ // Submit metric if Datadog is configured
547
+ if (hasDatadogEnv()) {
548
+ // Construct path from baseUrl and url
549
+ let path = (req.baseUrl || "") + (req.url || "");
550
+ // Ensure path starts with /
551
+ if (!path.startsWith("/")) {
552
+ path = "/" + path;
553
+ }
554
+ // Remove trailing slash unless it's the root path
555
+ if (path.length > 1 && path.endsWith("/")) {
556
+ path = path.slice(0, -1);
557
+ }
558
+
559
+ // Replace UUIDs with :id for better aggregation
560
+ // Matches standard UUID v4 format (8-4-4-4-12 hex characters)
561
+ path = path.replace(
562
+ /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/gi,
563
+ ":id",
564
+ );
565
+
566
+ // Determine metric name based on environment variables
567
+ let metricPrefix = "project";
568
+ if (process.env.PROJECT_SPONSOR) {
569
+ metricPrefix = process.env.PROJECT_SPONSOR;
570
+ } else if (process.env.PROJECT_KEY) {
571
+ metricPrefix = `project.${process.env.PROJECT_KEY}`;
572
+ }
573
+
574
+ await submitMetric({
575
+ name: `${metricPrefix}.api.response`,
576
+ type: DATADOG.METRIC.TYPE.COUNT,
577
+ value: 1,
578
+ tags: {
579
+ code: res.statusCode,
580
+ path,
581
+ },
582
+ });
583
+ }
584
+
536
585
  // Clean up the public logger
537
586
  log.untag("handler");
538
587
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jaypie/express",
3
- "version": "1.1.12",
3
+ "version": "1.1.13",
4
4
  "license": "MIT",
5
5
  "author": "Finlayson Studio",
6
6
  "type": "module",
@@ -39,6 +39,7 @@
39
39
  "dependencies": {
40
40
  "@codegenie/serverless-express": "^4.15.0",
41
41
  "@jaypie/core": "^1.1.0",
42
+ "@jaypie/datadog": "^1.1.8",
42
43
  "@jaypie/errors": "^1.1.2",
43
44
  "cors": "^2.8.5"
44
45
  },
@@ -48,5 +49,5 @@
48
49
  "publishConfig": {
49
50
  "access": "public"
50
51
  },
51
- "gitHead": "37596b497a334443338f86baa9d370529c055c12"
52
+ "gitHead": "8d2d1b78cc7181d8bc1ec097bb8e425959e9cd79"
52
53
  }
@@ -1,5 +1,6 @@
1
1
  import {
2
2
  force,
3
+ getHeaderFrom,
3
4
  HTTP,
4
5
  JAYPIE,
5
6
  jaypieHandler,
@@ -7,6 +8,7 @@ import {
7
8
  UnhandledError,
8
9
  validate as validateIs,
9
10
  } from "@jaypie/core";
11
+ import { DATADOG, hasDatadogEnv, submitMetric } from "@jaypie/datadog";
10
12
 
11
13
  import getCurrentInvokeUuid from "./getCurrentInvokeUuid.adapter.js";
12
14
  import decorateResponse from "./decorateResponse.helper.js";
@@ -31,6 +33,7 @@ const expressHandler = (handler, options = {}) => {
31
33
  // Validate
32
34
  //
33
35
  let {
36
+ chaos,
34
37
  locals,
35
38
  name,
36
39
  setup = [],
@@ -53,6 +56,13 @@ const expressHandler = (handler, options = {}) => {
53
56
  return async (req, res, ...params) => {
54
57
  // * This is the first line of code that runs when a request is received
55
58
 
59
+ // Set default chaos value
60
+ if (chaos === undefined) {
61
+ chaos =
62
+ process.env.PROJECT_CHAOS ||
63
+ getHeaderFrom(HTTP.HEADER.PROJECT.CHAOS, req);
64
+ }
65
+
56
66
  // Re-init the logger
57
67
  publicLogger.init();
58
68
  // Very low-level, internal sub-trace details
@@ -171,6 +181,7 @@ const expressHandler = (handler, options = {}) => {
171
181
 
172
182
  // Initialize after logging is set up
173
183
  jaypieFunction = jaypieHandler(handler, {
184
+ chaos,
174
185
  name,
175
186
  setup,
176
187
  teardown,
@@ -276,6 +287,45 @@ const expressHandler = (handler, options = {}) => {
276
287
  res: summarizeResponse(res, extras),
277
288
  });
278
289
 
290
+ // Submit metric if Datadog is configured
291
+ if (hasDatadogEnv()) {
292
+ // Construct path from baseUrl and url
293
+ let path = (req.baseUrl || "") + (req.url || "");
294
+ // Ensure path starts with /
295
+ if (!path.startsWith("/")) {
296
+ path = "/" + path;
297
+ }
298
+ // Remove trailing slash unless it's the root path
299
+ if (path.length > 1 && path.endsWith("/")) {
300
+ path = path.slice(0, -1);
301
+ }
302
+
303
+ // Replace UUIDs with :id for better aggregation
304
+ // Matches standard UUID v4 format (8-4-4-4-12 hex characters)
305
+ path = path.replace(
306
+ /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/gi,
307
+ ":id",
308
+ );
309
+
310
+ // Determine metric name based on environment variables
311
+ let metricPrefix = "project";
312
+ if (process.env.PROJECT_SPONSOR) {
313
+ metricPrefix = process.env.PROJECT_SPONSOR;
314
+ } else if (process.env.PROJECT_KEY) {
315
+ metricPrefix = `project.${process.env.PROJECT_KEY}`;
316
+ }
317
+
318
+ await submitMetric({
319
+ name: `${metricPrefix}.api.response`,
320
+ type: DATADOG.METRIC.TYPE.COUNT,
321
+ value: 1,
322
+ tags: {
323
+ code: res.statusCode,
324
+ path,
325
+ },
326
+ });
327
+ }
328
+
279
329
  // Clean up the public logger
280
330
  publicLogger.untag("handler");
281
331