@jaypie/express 1.2.18 → 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/cjs/expressHandler.d.ts +1 -1
- package/dist/cjs/expressStreamHandler.d.ts +1 -1
- package/dist/cjs/index.cjs +44 -47
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/expressHandler.d.ts +1 -1
- package/dist/esm/expressStreamHandler.d.ts +1 -1
- package/dist/esm/index.js +44 -47
- package/dist/esm/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Request, Response } from "express";
|
|
2
2
|
export type JaypieHandlerSetup = (req: Request, res: Response) => Promise<void> | void;
|
|
3
3
|
export type JaypieHandlerTeardown = (req: Request, res: Response) => Promise<void> | void;
|
|
4
|
-
export type JaypieHandlerValidate = (req: Request, res: Response) => Promise<boolean> | boolean;
|
|
4
|
+
export type JaypieHandlerValidate = (req: Request, res: Response) => Promise<boolean | void> | boolean | void;
|
|
5
5
|
export type ExpressHandlerLocals = (req: Request, res: Response) => Promise<unknown> | unknown;
|
|
6
6
|
export interface ExpressHandlerOptions {
|
|
7
7
|
chaos?: string;
|
|
@@ -2,7 +2,7 @@ import type { Request, Response } from "express";
|
|
|
2
2
|
import type { StreamFormat } from "@jaypie/aws";
|
|
3
3
|
export type JaypieStreamHandlerSetup = (req: Request, res: Response) => Promise<void> | void;
|
|
4
4
|
export type JaypieStreamHandlerTeardown = (req: Request, res: Response) => Promise<void> | void;
|
|
5
|
-
export type JaypieStreamHandlerValidate = (req: Request, res: Response) => Promise<boolean> | boolean;
|
|
5
|
+
export type JaypieStreamHandlerValidate = (req: Request, res: Response) => Promise<boolean | void> | boolean | void;
|
|
6
6
|
export type ExpressStreamHandlerLocals = (req: Request, res: Response) => Promise<unknown> | unknown;
|
|
7
7
|
export interface ExpressStreamHandlerOptions {
|
|
8
8
|
chaos?: string;
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -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
|
-
|
|
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(
|
|
1781
|
-
log.tag(
|
|
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
|
-
//
|
|
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
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
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
|
-
//
|
|
2293
|
+
// End log session and clean up
|
|
2294
|
+
logger.teardown();
|
|
2298
2295
|
logger.untag("handler");
|
|
2299
2296
|
}
|
|
2300
2297
|
};
|