@jaypie/express 1.2.19 → 1.2.20

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,20 @@ 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({ path, status: String(res.statusCode) });
1985
1993
  // Submit metric if Datadog is configured
1986
1994
  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
1995
  let metricPrefix = "project";
2002
1996
  if (process.env.PROJECT_SPONSOR) {
2003
1997
  metricPrefix = process.env.PROJECT_SPONSOR;
@@ -2015,7 +2009,8 @@ function expressHandler(handlerOrOptions, optionsOrHandler) {
2015
2009
  },
2016
2010
  });
2017
2011
  }
2018
- // Clean up the public logger
2012
+ // End log session and clean up
2013
+ logger$1.teardown();
2019
2014
  logger$1.untag("handler");
2020
2015
  //
2021
2016
  //
@@ -2134,14 +2129,6 @@ function expressStreamHandler(handlerOrOptions, optionsOrHandler) {
2134
2129
  });
2135
2130
  // Update the public logger with the request ID
2136
2131
  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
2132
  if (!name) {
2146
2133
  if (handler.name) {
2147
2134
  name = handler.name;
@@ -2150,9 +2137,15 @@ function expressStreamHandler(handlerOrOptions, optionsOrHandler) {
2150
2137
  name = kit.JAYPIE.UNKNOWN;
2151
2138
  }
2152
2139
  }
2153
- logger.tag({ handler: name });
2154
- libLogger.tag({ handler: name });
2155
- log.tag({ handler: name });
2140
+ const setupTags = { handler: name };
2141
+ if (invokeUuid) {
2142
+ setupTags.invoke = invokeUuid;
2143
+ setupTags.shortInvoke = invokeUuid.slice(0, 8);
2144
+ }
2145
+ logger.setup(setupTags);
2146
+ // TODO: in theory this is redundant
2147
+ libLogger.tag(setupTags);
2148
+ log.tag(setupTags);
2156
2149
  libLogger.trace("[jaypie] Express stream init");
2157
2150
  // Set req.locals if it doesn't exist
2158
2151
  if (!extReq.locals)
@@ -2267,16 +2260,19 @@ function expressStreamHandler(handlerOrOptions, optionsOrHandler) {
2267
2260
  log.info.var({
2268
2261
  res: { statusCode: res.statusCode, streaming: true },
2269
2262
  });
2263
+ // Construct normalized path for reporting and metrics
2264
+ let path = (req.baseUrl || "") + (req.url || "");
2265
+ if (!path.startsWith("/")) {
2266
+ path = "/" + path;
2267
+ }
2268
+ if (path.length > 1 && path.endsWith("/")) {
2269
+ path = path.slice(0, -1);
2270
+ }
2271
+ 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");
2272
+ // Add request data to session report
2273
+ logger.report({ path, status: String(res.statusCode) });
2270
2274
  // Submit metric if Datadog is configured
2271
2275
  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
2276
  let metricPrefix = "project";
2281
2277
  if (process.env.PROJECT_SPONSOR) {
2282
2278
  metricPrefix = process.env.PROJECT_SPONSOR;
@@ -2294,7 +2290,8 @@ function expressStreamHandler(handlerOrOptions, optionsOrHandler) {
2294
2290
  },
2295
2291
  });
2296
2292
  }
2297
- // Clean up the public logger
2293
+ // End log session and clean up
2294
+ logger.teardown();
2298
2295
  logger.untag("handler");
2299
2296
  }
2300
2297
  };