@nestjs/observe 0.3.9 → 0.3.11
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 +5 -1
- package/dist/agent/degraded-ingest.protocol.d.ts +35 -2
- package/dist/agent/degraded-ingest.protocol.js +35 -2
- package/dist/agent/detached-observe-worker.assembly.js +2 -1
- package/dist/agent/detached-observe-worker.d.ts +2 -0
- package/dist/agent/detached-observe-worker.js +35 -9
- package/dist/agent/observe-agent.shared-buffer.d.ts +27 -1
- package/dist/agent/observe-agent.shared-buffer.js +41 -6
- package/dist/agent/observe-agent.worker.d.ts +87 -7
- package/dist/agent/observe-agent.worker.js +273 -28
- package/dist/agent/telemetry-wire-contract.d.ts +43 -2
- package/dist/agent/telemetry-wire-contract.js +164 -34
- package/dist/encoders/job-snapshot.encoder.d.ts +1 -1
- package/dist/encoders/job-snapshot.encoder.js +1 -3
- package/dist/encoders/request-snapshot.encoder.d.ts +1 -1
- package/dist/encoders/request-snapshot.encoder.js +1 -3
- package/dist/instrument/create-instance-decorator.instrument.js +29 -0
- package/dist/interfaces/observe-options.interface.d.ts +18 -0
- package/dist/services/operation-trace.registry.d.ts +7 -0
- package/dist/services/operation-trace.registry.js +16 -1
- package/dist/services/stdout-forwarder.service.d.ts +16 -0
- package/dist/services/stdout-forwarder.service.js +43 -3
- package/dist/utils/log-line.parser.d.ts +2 -1
- package/dist/utils/log-line.parser.js +74 -11
- package/dist/utils/log-redactor.js +6 -1
- package/package.json +1 -1
|
@@ -23,14 +23,46 @@ const ANSI_PATTERN = /\x1B\[[0-9;]*[A-Za-z]/g;
|
|
|
23
23
|
* Nest's default ConsoleLogger line:
|
|
24
24
|
* [Nest] 1234 - 07/29/2026, 10:42:18 AM LOG [AppController] message
|
|
25
25
|
* The context bracket is optional - `logger.log()` without a context omits it.
|
|
26
|
+
* The level is right-aligned in seven columns, so `VERBOSE` follows the
|
|
27
|
+
* timestamp after a single space and every other level after several.
|
|
28
|
+
*
|
|
29
|
+
* Must stay linear in the length of the line: it runs on every line the
|
|
30
|
+
* process writes, synchronously inside `process.stdout.write`, on text a caller
|
|
31
|
+
* can shape. The pattern this replaced read `.+?\s{2,}` here - two quantifiers
|
|
32
|
+
* that could both take the same run of whitespace - and backtracked cubically
|
|
33
|
+
* on a `[Nest]` line that never reached a level: seconds for a few thousand
|
|
34
|
+
* spaces. Here no two neighbouring quantifiers can take the same character.
|
|
35
|
+
* The timestamp opens with a non-space, exactly one whitespace character
|
|
36
|
+
* precedes the level, and nothing after the level can fail.
|
|
26
37
|
*/
|
|
27
|
-
const NEST_TEXT_PATTERN = /^\[Nest\]\s+\d+\s+-\s
|
|
38
|
+
const NEST_TEXT_PATTERN = /^\[Nest\]\s+\d+\s+-\s+\S.*?\s(FATAL|ERROR|WARN|LOG|DEBUG|VERBOSE)\s+(?:\[([^\]]+)\]\s*)?([\s\S]*)$/;
|
|
28
39
|
/**
|
|
29
|
-
*
|
|
30
|
-
* back off recovers
|
|
31
|
-
* the time the forwarder sees them.
|
|
40
|
+
* Marker LoggerPatcherService puts before the trace id it appends when a trace
|
|
41
|
+
* is in scope. Parsing the id back off recovers it even for lines whose async
|
|
42
|
+
* context is gone by the time the forwarder sees them.
|
|
32
43
|
*/
|
|
33
|
-
const
|
|
44
|
+
const TRACE_ID_MARKER = "Trace ID:";
|
|
45
|
+
/** What may follow the marker: one token, and nothing after it. */
|
|
46
|
+
const TRACE_ID_VALUE_PATTERN = /^\s*(\S+)\s*$/;
|
|
47
|
+
/**
|
|
48
|
+
* The levels the collector accepts, which are Nest's own. It refuses a batch
|
|
49
|
+
* carrying any other value whole - every trace and metric in it lost over one
|
|
50
|
+
* log line - so nothing else is ever put in `level`.
|
|
51
|
+
*/
|
|
52
|
+
const LOG_LEVELS = new Set([
|
|
53
|
+
"fatal",
|
|
54
|
+
"error",
|
|
55
|
+
"warn",
|
|
56
|
+
"log",
|
|
57
|
+
"debug",
|
|
58
|
+
"verbose",
|
|
59
|
+
]);
|
|
60
|
+
/** Other loggers' names for a level the collector models. */
|
|
61
|
+
const LEVEL_ALIASES = new Map([
|
|
62
|
+
["info", "log"],
|
|
63
|
+
["warning", "warn"],
|
|
64
|
+
["trace", "verbose"],
|
|
65
|
+
]);
|
|
34
66
|
/**
|
|
35
67
|
* Keys the JSON logger sets that map onto modelled columns; anything else a
|
|
36
68
|
* service attaches is preserved under `attributes`.
|
|
@@ -71,9 +103,13 @@ function parseStructured(line) {
|
|
|
71
103
|
if (typeof record.message !== "string") {
|
|
72
104
|
return null;
|
|
73
105
|
}
|
|
74
|
-
const
|
|
106
|
+
const level = toLogLevel(record.level);
|
|
107
|
+
const attributes = Object.fromEntries(Object.entries(record).filter(
|
|
108
|
+
// A level the collector does not model - pino's numeric ones, a logger's
|
|
109
|
+
// own `notice` - stays an attribute rather than being dropped.
|
|
110
|
+
([key]) => !STRUCTURED_KEYS.has(key) || (key === "level" && level === undefined)));
|
|
75
111
|
return {
|
|
76
|
-
level
|
|
112
|
+
level,
|
|
77
113
|
context: typeof record.context === "string" ? record.context : undefined,
|
|
78
114
|
traceId: typeof record.traceId === "string" ? record.traceId : undefined,
|
|
79
115
|
message: record.message,
|
|
@@ -86,11 +122,38 @@ function parseNestText(line) {
|
|
|
86
122
|
return null;
|
|
87
123
|
}
|
|
88
124
|
const [, level, context, rest] = match;
|
|
89
|
-
const
|
|
125
|
+
const { message, traceId } = splitTraceIdSuffix(rest);
|
|
90
126
|
return {
|
|
91
|
-
level: level
|
|
127
|
+
level: toLogLevel(level),
|
|
92
128
|
context: context || undefined,
|
|
93
|
-
traceId
|
|
94
|
-
message
|
|
129
|
+
traceId,
|
|
130
|
+
message,
|
|
95
131
|
};
|
|
96
132
|
}
|
|
133
|
+
/**
|
|
134
|
+
* Splits the trace id suffix off the end of a message, when there is one.
|
|
135
|
+
*
|
|
136
|
+
* Found with `lastIndexOf` rather than an unanchored `\s*Trace ID:...$`
|
|
137
|
+
* pattern, which retried its leading `\s*` from every offset - quadratic in a
|
|
138
|
+
* long run of whitespace, and that whitespace can come from a caller. Only the
|
|
139
|
+
* last marker can be the suffix anyway: the marker itself contains a space, so
|
|
140
|
+
* an earlier one is always followed by more than one token.
|
|
141
|
+
*/
|
|
142
|
+
function splitTraceIdSuffix(rest) {
|
|
143
|
+
const markerIndex = rest.lastIndexOf(TRACE_ID_MARKER);
|
|
144
|
+
if (markerIndex === -1) {
|
|
145
|
+
return { message: rest };
|
|
146
|
+
}
|
|
147
|
+
const value = TRACE_ID_VALUE_PATTERN.exec(rest.slice(markerIndex + TRACE_ID_MARKER.length));
|
|
148
|
+
if (!value) {
|
|
149
|
+
return { message: rest };
|
|
150
|
+
}
|
|
151
|
+
return { message: rest.slice(0, markerIndex).trimEnd(), traceId: value[1] };
|
|
152
|
+
}
|
|
153
|
+
function toLogLevel(value) {
|
|
154
|
+
if (typeof value !== "string") {
|
|
155
|
+
return undefined;
|
|
156
|
+
}
|
|
157
|
+
const lower = value.toLowerCase();
|
|
158
|
+
return LOG_LEVELS.has(lower) ? lower : LEVEL_ALIASES.get(lower);
|
|
159
|
+
}
|
|
@@ -84,8 +84,13 @@ function buildDefaultRules(literalValuesOnly = false) {
|
|
|
84
84
|
replace: (replacement, prefix) => `${prefix}${replacement}`,
|
|
85
85
|
},
|
|
86
86
|
// Bare JWTs - they show up outside any header often enough to matter.
|
|
87
|
+
//
|
|
88
|
+
// Must not follow a token character, rather than `\b`: a hyphen is a word
|
|
89
|
+
// boundary but also a token character, so under `\b` every `eyJ` in a run
|
|
90
|
+
// like `eyJ-eyJ-eyJ-...` started a match that rescanned the rest of the
|
|
91
|
+
// run - quadratic, on a line a caller can fill.
|
|
87
92
|
{
|
|
88
|
-
pattern:
|
|
93
|
+
pattern: /(?<![A-Za-z0-9_-])eyJ[A-Za-z0-9_-]{4,}\.[A-Za-z0-9_-]{4,}\.[A-Za-z0-9_-]*/g,
|
|
89
94
|
replace: (replacement) => replacement,
|
|
90
95
|
},
|
|
91
96
|
// AWS access key ids. Distinctive enough to match on sight; the matching
|
package/package.json
CHANGED