@malloy-publisher/server 0.0.152 → 0.0.153
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/instrumentation.js +22 -3
- package/dist/server.js +22 -3
- package/package.json +1 -1
- package/src/logger.ts +44 -2
package/dist/instrumentation.js
CHANGED
|
@@ -116694,9 +116694,22 @@ var import_sdk_logs = __toESM(require_src7());
|
|
|
116694
116694
|
var import_winston = __toESM(require_winston());
|
|
116695
116695
|
var isTelemetryEnabled = Boolean(process.env.OTEL_EXPORTER_OTLP_ENDPOINT);
|
|
116696
116696
|
var logger = import_winston.default.createLogger({
|
|
116697
|
-
format: isTelemetryEnabled ? import_winston.default.format.combine(import_winston.default.format.uncolorize(), import_winston.default.format.timestamp(), import_winston.default.format.
|
|
116697
|
+
format: isTelemetryEnabled ? import_winston.default.format.combine(import_winston.default.format.uncolorize(), import_winston.default.format.timestamp(), import_winston.default.format.metadata({
|
|
116698
|
+
fillExcept: ["message", "level", "timestamp"]
|
|
116699
|
+
}), import_winston.default.format.json()) : import_winston.default.format.combine(import_winston.default.format.colorize(), import_winston.default.format.simple()),
|
|
116698
116700
|
transports: [new import_winston.default.transports.Console]
|
|
116699
116701
|
});
|
|
116702
|
+
function extractTraceIdFromTraceparent(traceparent) {
|
|
116703
|
+
if (!traceparent) {
|
|
116704
|
+
return;
|
|
116705
|
+
}
|
|
116706
|
+
const parts = traceparent.split("-");
|
|
116707
|
+
const traceId = parts.length >= 2 ? parts[1] : parts.length == 1 ? parts[0] : undefined;
|
|
116708
|
+
if (traceId && traceId.length === 32 && /^[0-9a-fA-F]{32}$/.test(traceId)) {
|
|
116709
|
+
return traceId;
|
|
116710
|
+
}
|
|
116711
|
+
return;
|
|
116712
|
+
}
|
|
116700
116713
|
var loggerMiddleware = (req, res, next) => {
|
|
116701
116714
|
const startTime = performance.now();
|
|
116702
116715
|
const resJson = res.json;
|
|
@@ -116706,14 +116719,20 @@ var loggerMiddleware = (req, res, next) => {
|
|
|
116706
116719
|
};
|
|
116707
116720
|
res.on("finish", () => {
|
|
116708
116721
|
const endTime = performance.now();
|
|
116709
|
-
|
|
116722
|
+
const traceparent = req.headers["traceparent"];
|
|
116723
|
+
const traceId = extractTraceIdFromTraceparent(traceparent);
|
|
116724
|
+
const logMetadata = {
|
|
116710
116725
|
statusCode: res.statusCode,
|
|
116711
116726
|
duration: endTime - startTime,
|
|
116712
116727
|
payload: req.body,
|
|
116713
116728
|
response: res.locals.body,
|
|
116714
116729
|
params: req.params,
|
|
116715
116730
|
query: req.query
|
|
116716
|
-
}
|
|
116731
|
+
};
|
|
116732
|
+
if (traceId) {
|
|
116733
|
+
logMetadata.traceId = traceId;
|
|
116734
|
+
}
|
|
116735
|
+
logger.info(`${req.method} ${req.url}`, logMetadata);
|
|
116717
116736
|
});
|
|
116718
116737
|
next();
|
|
116719
116738
|
};
|
package/dist/server.js
CHANGED
|
@@ -125121,9 +125121,22 @@ class FrozenConfigError extends Error {
|
|
|
125121
125121
|
var import_winston = __toESM(require_winston());
|
|
125122
125122
|
var isTelemetryEnabled = Boolean(process.env.OTEL_EXPORTER_OTLP_ENDPOINT);
|
|
125123
125123
|
var logger = import_winston.default.createLogger({
|
|
125124
|
-
format: isTelemetryEnabled ? import_winston.default.format.combine(import_winston.default.format.uncolorize(), import_winston.default.format.timestamp(), import_winston.default.format.
|
|
125124
|
+
format: isTelemetryEnabled ? import_winston.default.format.combine(import_winston.default.format.uncolorize(), import_winston.default.format.timestamp(), import_winston.default.format.metadata({
|
|
125125
|
+
fillExcept: ["message", "level", "timestamp"]
|
|
125126
|
+
}), import_winston.default.format.json()) : import_winston.default.format.combine(import_winston.default.format.colorize(), import_winston.default.format.simple()),
|
|
125125
125127
|
transports: [new import_winston.default.transports.Console]
|
|
125126
125128
|
});
|
|
125129
|
+
function extractTraceIdFromTraceparent(traceparent) {
|
|
125130
|
+
if (!traceparent) {
|
|
125131
|
+
return;
|
|
125132
|
+
}
|
|
125133
|
+
const parts = traceparent.split("-");
|
|
125134
|
+
const traceId = parts.length >= 2 ? parts[1] : parts.length == 1 ? parts[0] : undefined;
|
|
125135
|
+
if (traceId && traceId.length === 32 && /^[0-9a-fA-F]{32}$/.test(traceId)) {
|
|
125136
|
+
return traceId;
|
|
125137
|
+
}
|
|
125138
|
+
return;
|
|
125139
|
+
}
|
|
125127
125140
|
var loggerMiddleware = (req, res, next) => {
|
|
125128
125141
|
const startTime = performance.now();
|
|
125129
125142
|
const resJson = res.json;
|
|
@@ -125133,14 +125146,20 @@ var loggerMiddleware = (req, res, next) => {
|
|
|
125133
125146
|
};
|
|
125134
125147
|
res.on("finish", () => {
|
|
125135
125148
|
const endTime = performance.now();
|
|
125136
|
-
|
|
125149
|
+
const traceparent = req.headers["traceparent"];
|
|
125150
|
+
const traceId = extractTraceIdFromTraceparent(traceparent);
|
|
125151
|
+
const logMetadata = {
|
|
125137
125152
|
statusCode: res.statusCode,
|
|
125138
125153
|
duration: endTime - startTime,
|
|
125139
125154
|
payload: req.body,
|
|
125140
125155
|
response: res.locals.body,
|
|
125141
125156
|
params: req.params,
|
|
125142
125157
|
query: req.query
|
|
125143
|
-
}
|
|
125158
|
+
};
|
|
125159
|
+
if (traceId) {
|
|
125160
|
+
logMetadata.traceId = traceId;
|
|
125161
|
+
}
|
|
125162
|
+
logger.info(`${req.method} ${req.url}`, logMetadata);
|
|
125144
125163
|
});
|
|
125145
125164
|
next();
|
|
125146
125165
|
};
|
package/package.json
CHANGED
package/src/logger.ts
CHANGED
|
@@ -9,6 +9,9 @@ export const logger = winston.createLogger({
|
|
|
9
9
|
? winston.format.combine(
|
|
10
10
|
winston.format.uncolorize(),
|
|
11
11
|
winston.format.timestamp(),
|
|
12
|
+
winston.format.metadata({
|
|
13
|
+
fillExcept: ["message", "level", "timestamp"],
|
|
14
|
+
}),
|
|
12
15
|
winston.format.json(),
|
|
13
16
|
)
|
|
14
17
|
: winston.format.combine(
|
|
@@ -18,6 +21,33 @@ export const logger = winston.createLogger({
|
|
|
18
21
|
transports: [new winston.transports.Console()],
|
|
19
22
|
});
|
|
20
23
|
|
|
24
|
+
/**
|
|
25
|
+
* Extracts the trace ID from a W3C traceparent header.
|
|
26
|
+
* Format: version-trace-id-parent-id-trace-flags
|
|
27
|
+
* Example: 00-81f2264f363f1b5596c84ab29e6be171-83ef39df12ab6bab-01
|
|
28
|
+
*
|
|
29
|
+
* @param traceparent The traceparent header value
|
|
30
|
+
* @returns The trace ID (32 hex characters) or undefined if invalid
|
|
31
|
+
*/
|
|
32
|
+
function extractTraceIdFromTraceparent(
|
|
33
|
+
traceparent: string | undefined,
|
|
34
|
+
): string | undefined {
|
|
35
|
+
if (!traceparent) {
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// format of traceparent can either be: version-traceId-parentId-traceFlags or traceId
|
|
40
|
+
const parts = traceparent.split("-");
|
|
41
|
+
const traceId =
|
|
42
|
+
parts.length >= 2 ? parts[1] : parts.length == 1 ? parts[0] : undefined;
|
|
43
|
+
// Validate that the traceId is 32 hex characters
|
|
44
|
+
if (traceId && traceId.length === 32 && /^[0-9a-fA-F]{32}$/.test(traceId)) {
|
|
45
|
+
return traceId;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
|
|
21
51
|
export const loggerMiddleware: RequestHandler = (req, res, next) => {
|
|
22
52
|
const startTime = performance.now();
|
|
23
53
|
const resJson = res.json;
|
|
@@ -27,14 +57,26 @@ export const loggerMiddleware: RequestHandler = (req, res, next) => {
|
|
|
27
57
|
};
|
|
28
58
|
res.on("finish", () => {
|
|
29
59
|
const endTime = performance.now();
|
|
30
|
-
|
|
60
|
+
|
|
61
|
+
// Extract trace ID from traceparent header if present
|
|
62
|
+
const traceparent = req.headers["traceparent"] as string | undefined;
|
|
63
|
+
const traceId = extractTraceIdFromTraceparent(traceparent);
|
|
64
|
+
|
|
65
|
+
const logMetadata: Record<string, unknown> = {
|
|
31
66
|
statusCode: res.statusCode,
|
|
32
67
|
duration: endTime - startTime,
|
|
33
68
|
payload: req.body,
|
|
34
69
|
response: res.locals.body,
|
|
35
70
|
params: req.params,
|
|
36
71
|
query: req.query,
|
|
37
|
-
}
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
// Add traceId to log metadata if present
|
|
75
|
+
if (traceId) {
|
|
76
|
+
logMetadata.traceId = traceId;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
logger.info(`${req.method} ${req.url}`, logMetadata);
|
|
38
80
|
});
|
|
39
81
|
next();
|
|
40
82
|
};
|