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