trickle-observe 0.2.28 → 0.2.29
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/trace-var.js +5 -4
- package/package.json +1 -1
- package/src/trace-var.ts +5 -3
package/dist/trace-var.js
CHANGED
|
@@ -158,15 +158,14 @@ function flushVarBuffer() {
|
|
|
158
158
|
* Sanitize a variable value for safe serialization.
|
|
159
159
|
* More aggressive truncation than function samples since there are many more variables.
|
|
160
160
|
*/
|
|
161
|
-
function sanitizeVarSample(value, depth =
|
|
162
|
-
if (depth <= 0)
|
|
163
|
-
return '[truncated]';
|
|
161
|
+
function sanitizeVarSample(value, depth = 3) {
|
|
164
162
|
if (value === null || value === undefined)
|
|
165
163
|
return value;
|
|
166
164
|
const t = typeof value;
|
|
165
|
+
// Primitives are always safe to return at any depth
|
|
167
166
|
if (t === 'string') {
|
|
168
167
|
const s = value;
|
|
169
|
-
return s.length >
|
|
168
|
+
return s.length > 60 ? s.substring(0, 60) + '...' : s;
|
|
170
169
|
}
|
|
171
170
|
if (t === 'number' || t === 'boolean')
|
|
172
171
|
return value;
|
|
@@ -176,6 +175,8 @@ function sanitizeVarSample(value, depth = 2) {
|
|
|
176
175
|
return String(value);
|
|
177
176
|
if (t === 'function')
|
|
178
177
|
return `[Function: ${value.name || 'anonymous'}]`;
|
|
178
|
+
if (depth <= 0)
|
|
179
|
+
return '[...]';
|
|
179
180
|
if (Array.isArray(value)) {
|
|
180
181
|
return value.slice(0, 3).map(item => sanitizeVarSample(item, depth - 1));
|
|
181
182
|
}
|
package/package.json
CHANGED
package/src/trace-var.ts
CHANGED
|
@@ -148,20 +148,22 @@ function flushVarBuffer(): void {
|
|
|
148
148
|
* Sanitize a variable value for safe serialization.
|
|
149
149
|
* More aggressive truncation than function samples since there are many more variables.
|
|
150
150
|
*/
|
|
151
|
-
function sanitizeVarSample(value: unknown, depth: number =
|
|
152
|
-
if (depth <= 0) return '[truncated]';
|
|
151
|
+
function sanitizeVarSample(value: unknown, depth: number = 3): unknown {
|
|
153
152
|
if (value === null || value === undefined) return value;
|
|
154
153
|
|
|
155
154
|
const t = typeof value;
|
|
155
|
+
// Primitives are always safe to return at any depth
|
|
156
156
|
if (t === 'string') {
|
|
157
157
|
const s = value as string;
|
|
158
|
-
return s.length >
|
|
158
|
+
return s.length > 60 ? s.substring(0, 60) + '...' : s;
|
|
159
159
|
}
|
|
160
160
|
if (t === 'number' || t === 'boolean') return value;
|
|
161
161
|
if (t === 'bigint') return String(value);
|
|
162
162
|
if (t === 'symbol') return String(value);
|
|
163
163
|
if (t === 'function') return `[Function: ${(value as Function).name || 'anonymous'}]`;
|
|
164
164
|
|
|
165
|
+
if (depth <= 0) return '[...]';
|
|
166
|
+
|
|
165
167
|
if (Array.isArray(value)) {
|
|
166
168
|
return value.slice(0, 3).map(item => sanitizeVarSample(item, depth - 1));
|
|
167
169
|
}
|