@jaypie/express 1.2.22 → 1.2.24
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/README.md +4 -13
- package/dist/cjs/index.cjs +25 -3
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/index.js +26 -4
- package/dist/esm/index.js.map +1 -1
- package/package.json +1 -1
package/dist/esm/index.js
CHANGED
|
@@ -5,7 +5,7 @@ import { force, envBoolean, JAYPIE, HTTP, getHeaderFrom, jaypieHandler } from '@
|
|
|
5
5
|
import expressCors from 'cors';
|
|
6
6
|
import { loadEnvSecrets, getContentTypeForFormat, formatStreamError } from '@jaypie/aws';
|
|
7
7
|
import { log, redactAuth } from '@jaypie/logger';
|
|
8
|
-
import { hasDatadogEnv, submitMetric, DATADOG } from '@jaypie/datadog';
|
|
8
|
+
import { hasDatadogEnv, submitMetric, DATADOG, loadDatadogApiKey } from '@jaypie/datadog';
|
|
9
9
|
|
|
10
10
|
//
|
|
11
11
|
//
|
|
@@ -1863,6 +1863,10 @@ function expressHandler(handlerOrOptions, optionsOrHandler) {
|
|
|
1863
1863
|
//
|
|
1864
1864
|
// Build a request-local setup list to avoid mutating the shared array
|
|
1865
1865
|
const requestSetup = [];
|
|
1866
|
+
// Load the Datadog LLM Observability API key into the environment when enabled
|
|
1867
|
+
requestSetup.push(async () => {
|
|
1868
|
+
await loadDatadogApiKey();
|
|
1869
|
+
});
|
|
1866
1870
|
// Load secrets into process.env if configured
|
|
1867
1871
|
if (secrets && secrets.length > 0) {
|
|
1868
1872
|
const secretsToLoad = secrets;
|
|
@@ -2022,19 +2026,37 @@ function expressHandler(handlerOrOptions, optionsOrHandler) {
|
|
|
2022
2026
|
res: summarizeResponse(res, extras),
|
|
2023
2027
|
});
|
|
2024
2028
|
// Construct normalized path for reporting and metrics
|
|
2025
|
-
let
|
|
2026
|
-
if (!
|
|
2027
|
-
|
|
2029
|
+
let pathWithQuery = (req.baseUrl || "") + (req.url || "");
|
|
2030
|
+
if (!pathWithQuery.startsWith("/")) {
|
|
2031
|
+
pathWithQuery = "/" + pathWithQuery;
|
|
2028
2032
|
}
|
|
2033
|
+
const queryIndex = pathWithQuery.indexOf("?");
|
|
2034
|
+
let path = queryIndex >= 0 ? pathWithQuery.slice(0, queryIndex) : pathWithQuery;
|
|
2035
|
+
const rawQuery = queryIndex >= 0 ? pathWithQuery.slice(queryIndex + 1) : "";
|
|
2029
2036
|
if (path.length > 1 && path.endsWith("/")) {
|
|
2030
2037
|
path = path.slice(0, -1);
|
|
2031
2038
|
}
|
|
2032
2039
|
// Replace UUIDs with :id for better aggregation
|
|
2033
2040
|
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");
|
|
2041
|
+
// Normalize query params (sort alphabetically for stable aggregation)
|
|
2042
|
+
let query = "";
|
|
2043
|
+
if (rawQuery) {
|
|
2044
|
+
const params = new URLSearchParams(rawQuery);
|
|
2045
|
+
params.sort();
|
|
2046
|
+
query = params.toString();
|
|
2047
|
+
}
|
|
2048
|
+
// Capture request content metadata
|
|
2049
|
+
const headers = req.headers || {};
|
|
2050
|
+
const contentType = String(headers["content-type"] || "");
|
|
2051
|
+
const contentLengthHeader = headers["content-length"];
|
|
2052
|
+
const contentLength = contentLengthHeader ? Number(contentLengthHeader) : 0;
|
|
2034
2053
|
// Add request data to session report
|
|
2035
2054
|
logger$1.report({
|
|
2036
2055
|
method: req.method,
|
|
2037
2056
|
path,
|
|
2057
|
+
query,
|
|
2058
|
+
contentType,
|
|
2059
|
+
contentLength,
|
|
2038
2060
|
status: String(res.statusCode),
|
|
2039
2061
|
});
|
|
2040
2062
|
// Submit metric if Datadog is configured
|