@mastra/observability 1.17.6-alpha.0 → 1.17.6-alpha.2

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/index.cjs CHANGED
@@ -9210,7 +9210,7 @@ var SensitiveDataFilter = class {
9210
9210
  }
9211
9211
  /**
9212
9212
  * Process a span by filtering sensitive data across its key fields.
9213
- * Fields processed: attributes, metadata, input, output, errorInfo.
9213
+ * Fields processed: attributes, metadata, input, output, errorInfo, requestContext.
9214
9214
  *
9215
9215
  * @param span - The input span to filter
9216
9216
  * @returns A new span with sensitive values redacted
@@ -9222,6 +9222,7 @@ var SensitiveDataFilter = class {
9222
9222
  span.input = this.tryFilter(span.input, indexedState);
9223
9223
  span.output = this.tryFilter(span.output, indexedState);
9224
9224
  span.errorInfo = this.tryFilter(span.errorInfo, indexedState);
9225
+ span.requestContext = this.tryFilter(span.requestContext, indexedState);
9225
9226
  return span;
9226
9227
  }
9227
9228
  /**
@@ -9234,7 +9235,8 @@ var SensitiveDataFilter = class {
9234
9235
  if (state) this.traceStates.delete(traceId);
9235
9236
  else state = {
9236
9237
  tokensByValue: /* @__PURE__ */ new Map(),
9237
- counters: /* @__PURE__ */ new Map()
9238
+ counters: /* @__PURE__ */ new Map(),
9239
+ issuedTokens: /* @__PURE__ */ new Set()
9238
9240
  };
9239
9241
  this.traceStates.set(traceId, state);
9240
9242
  while (this.traceStates.size > MAX_TRACKED_TRACES) {
@@ -9253,7 +9255,7 @@ var SensitiveDataFilter = class {
9253
9255
  if (obj === null || typeof obj !== "object") {
9254
9256
  if (typeof obj === "string") {
9255
9257
  const trimmed = obj.trim();
9256
- if (trimmed.startsWith("{") || trimmed.startsWith("[")) return this.redactJsonString(obj, indexedState);
9258
+ if (this.isJsonCandidate(trimmed)) return this.redactJsonString(obj, indexedState);
9257
9259
  }
9258
9260
  return obj;
9259
9261
  }
@@ -9270,6 +9272,16 @@ var SensitiveDataFilter = class {
9270
9272
  }
9271
9273
  return filtered;
9272
9274
  }
9275
+ isJsonCandidate(value) {
9276
+ const opening = value[0];
9277
+ if (opening !== "{" && opening !== "[") return false;
9278
+ let index = 1;
9279
+ while (value[index] === " " || value[index] === " " || value[index] === "\r" || value[index] === "\n") index++;
9280
+ const first = value[index];
9281
+ if (first === void 0) return false;
9282
+ if (opening === "{") return first === "\"" || first === "}";
9283
+ return first === "]" || first === "{" || first === "[" || first === "\"" || first === "-" || first >= "0" && first <= "9" || first === "t" || first === "f" || first === "n";
9284
+ }
9273
9285
  tryFilter(value, indexedState) {
9274
9286
  try {
9275
9287
  return this.deepFilter(value, /* @__PURE__ */ new WeakSet(), indexedState);
@@ -9332,6 +9344,7 @@ var SensitiveDataFilter = class {
9332
9344
  return str.slice(0, 3) + "…" + str.slice(len - 3);
9333
9345
  }
9334
9346
  if (this.redactionStyle === "indexed" && indexedState) {
9347
+ if (typeof value === "string" && indexedState.issuedTokens.has(value)) return value;
9335
9348
  const valueKey = (0, crypto$1.createHash)("sha256").update(String(value)).digest("hex");
9336
9349
  const existing = indexedState.tokensByValue.get(valueKey);
9337
9350
  if (existing) return existing;
@@ -9341,6 +9354,7 @@ var SensitiveDataFilter = class {
9341
9354
  indexedState.counters.set(label, count);
9342
9355
  const token = `[${label}_${count}]`;
9343
9356
  indexedState.tokensByValue.set(valueKey, token);
9357
+ indexedState.issuedTokens.add(token);
9344
9358
  return token;
9345
9359
  }
9346
9360
  return this.redactionToken;