@jaypie/express 1.2.19 → 1.2.21

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.
@@ -1757,15 +1757,6 @@ function expressHandler(handlerOrOptions, optionsOrHandler) {
1757
1757
  });
1758
1758
  // Update the public logger with the request ID
1759
1759
  const invokeUuid = getCurrentInvokeUuid(req);
1760
- if (invokeUuid) {
1761
- logger$1.tag({ invoke: invokeUuid });
1762
- logger$1.tag({ shortInvoke: invokeUuid.slice(0, 8) });
1763
- // TODO: in theory this is redundant
1764
- libLogger.tag({ invoke: invokeUuid });
1765
- libLogger.tag({ shortInvoke: invokeUuid.slice(0, 8) });
1766
- log.tag({ invoke: invokeUuid });
1767
- log.tag({ shortInvoke: invokeUuid.slice(0, 8) });
1768
- }
1769
1760
  if (!name) {
1770
1761
  // If handler has a name, use it
1771
1762
  if (handler.name) {
@@ -1775,10 +1766,15 @@ function expressHandler(handlerOrOptions, optionsOrHandler) {
1775
1766
  name = kit.JAYPIE.UNKNOWN;
1776
1767
  }
1777
1768
  }
1778
- logger$1.tag({ handler: name });
1769
+ const setupTags = { handler: name };
1770
+ if (invokeUuid) {
1771
+ setupTags.invoke = invokeUuid;
1772
+ setupTags.shortInvoke = invokeUuid.slice(0, 8);
1773
+ }
1774
+ logger$1.setup(setupTags);
1779
1775
  // TODO: in theory this is redundant
1780
- libLogger.tag({ handler: name });
1781
- log.tag({ handler: name });
1776
+ libLogger.tag(setupTags);
1777
+ log.tag(setupTags);
1782
1778
  libLogger.trace("[jaypie] Express init");
1783
1779
  // Set req.locals if it doesn't exist
1784
1780
  if (!extReq.locals)
@@ -1982,22 +1978,24 @@ function expressHandler(handlerOrOptions, optionsOrHandler) {
1982
1978
  log.info.var({
1983
1979
  res: summarizeResponse(res, extras),
1984
1980
  });
1981
+ // Construct normalized path for reporting and metrics
1982
+ let path = (req.baseUrl || "") + (req.url || "");
1983
+ if (!path.startsWith("/")) {
1984
+ path = "/" + path;
1985
+ }
1986
+ if (path.length > 1 && path.endsWith("/")) {
1987
+ path = path.slice(0, -1);
1988
+ }
1989
+ // Replace UUIDs with :id for better aggregation
1990
+ path = path.replace(/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/gi, ":id");
1991
+ // Add request data to session report
1992
+ logger$1.report({
1993
+ method: req.method,
1994
+ path,
1995
+ status: String(res.statusCode),
1996
+ });
1985
1997
  // Submit metric if Datadog is configured
1986
1998
  if (datadog.hasDatadogEnv()) {
1987
- // Construct path from baseUrl and url
1988
- let path = (req.baseUrl || "") + (req.url || "");
1989
- // Ensure path starts with /
1990
- if (!path.startsWith("/")) {
1991
- path = "/" + path;
1992
- }
1993
- // Remove trailing slash unless it's the root path
1994
- if (path.length > 1 && path.endsWith("/")) {
1995
- path = path.slice(0, -1);
1996
- }
1997
- // Replace UUIDs with :id for better aggregation
1998
- // Matches standard UUID v4 format (8-4-4-4-12 hex characters)
1999
- path = path.replace(/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/gi, ":id");
2000
- // Determine metric name based on environment variables
2001
1999
  let metricPrefix = "project";
2002
2000
  if (process.env.PROJECT_SPONSOR) {
2003
2001
  metricPrefix = process.env.PROJECT_SPONSOR;
@@ -2015,7 +2013,8 @@ function expressHandler(handlerOrOptions, optionsOrHandler) {
2015
2013
  },
2016
2014
  });
2017
2015
  }
2018
- // Clean up the public logger
2016
+ // End log session and clean up
2017
+ logger$1.teardown();
2019
2018
  logger$1.untag("handler");
2020
2019
  //
2021
2020
  //
@@ -2134,14 +2133,6 @@ function expressStreamHandler(handlerOrOptions, optionsOrHandler) {
2134
2133
  });
2135
2134
  // Update the public logger with the request ID
2136
2135
  const invokeUuid = getCurrentInvokeUuid(req);
2137
- if (invokeUuid) {
2138
- logger.tag({ invoke: invokeUuid });
2139
- logger.tag({ shortInvoke: invokeUuid.slice(0, 8) });
2140
- libLogger.tag({ invoke: invokeUuid });
2141
- libLogger.tag({ shortInvoke: invokeUuid.slice(0, 8) });
2142
- log.tag({ invoke: invokeUuid });
2143
- log.tag({ shortInvoke: invokeUuid.slice(0, 8) });
2144
- }
2145
2136
  if (!name) {
2146
2137
  if (handler.name) {
2147
2138
  name = handler.name;
@@ -2150,9 +2141,15 @@ function expressStreamHandler(handlerOrOptions, optionsOrHandler) {
2150
2141
  name = kit.JAYPIE.UNKNOWN;
2151
2142
  }
2152
2143
  }
2153
- logger.tag({ handler: name });
2154
- libLogger.tag({ handler: name });
2155
- log.tag({ handler: name });
2144
+ const setupTags = { handler: name };
2145
+ if (invokeUuid) {
2146
+ setupTags.invoke = invokeUuid;
2147
+ setupTags.shortInvoke = invokeUuid.slice(0, 8);
2148
+ }
2149
+ logger.setup(setupTags);
2150
+ // TODO: in theory this is redundant
2151
+ libLogger.tag(setupTags);
2152
+ log.tag(setupTags);
2156
2153
  libLogger.trace("[jaypie] Express stream init");
2157
2154
  // Set req.locals if it doesn't exist
2158
2155
  if (!extReq.locals)
@@ -2267,16 +2264,23 @@ function expressStreamHandler(handlerOrOptions, optionsOrHandler) {
2267
2264
  log.info.var({
2268
2265
  res: { statusCode: res.statusCode, streaming: true },
2269
2266
  });
2267
+ // Construct normalized path for reporting and metrics
2268
+ let path = (req.baseUrl || "") + (req.url || "");
2269
+ if (!path.startsWith("/")) {
2270
+ path = "/" + path;
2271
+ }
2272
+ if (path.length > 1 && path.endsWith("/")) {
2273
+ path = path.slice(0, -1);
2274
+ }
2275
+ path = path.replace(/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/gi, ":id");
2276
+ // Add request data to session report
2277
+ logger.report({
2278
+ method: req.method,
2279
+ path,
2280
+ status: String(res.statusCode),
2281
+ });
2270
2282
  // Submit metric if Datadog is configured
2271
2283
  if (datadog.hasDatadogEnv()) {
2272
- let path = (req.baseUrl || "") + (req.url || "");
2273
- if (!path.startsWith("/")) {
2274
- path = "/" + path;
2275
- }
2276
- if (path.length > 1 && path.endsWith("/")) {
2277
- path = path.slice(0, -1);
2278
- }
2279
- path = path.replace(/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/gi, ":id");
2280
2284
  let metricPrefix = "project";
2281
2285
  if (process.env.PROJECT_SPONSOR) {
2282
2286
  metricPrefix = process.env.PROJECT_SPONSOR;
@@ -2294,7 +2298,8 @@ function expressStreamHandler(handlerOrOptions, optionsOrHandler) {
2294
2298
  },
2295
2299
  });
2296
2300
  }
2297
- // Clean up the public logger
2301
+ // End log session and clean up
2302
+ logger.teardown();
2298
2303
  logger.untag("handler");
2299
2304
  }
2300
2305
  };