@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.js CHANGED
@@ -9185,7 +9185,7 @@ var SensitiveDataFilter = class {
9185
9185
  }
9186
9186
  /**
9187
9187
  * Process a span by filtering sensitive data across its key fields.
9188
- * Fields processed: attributes, metadata, input, output, errorInfo.
9188
+ * Fields processed: attributes, metadata, input, output, errorInfo, requestContext.
9189
9189
  *
9190
9190
  * @param span - The input span to filter
9191
9191
  * @returns A new span with sensitive values redacted
@@ -9197,6 +9197,7 @@ var SensitiveDataFilter = class {
9197
9197
  span.input = this.tryFilter(span.input, indexedState);
9198
9198
  span.output = this.tryFilter(span.output, indexedState);
9199
9199
  span.errorInfo = this.tryFilter(span.errorInfo, indexedState);
9200
+ span.requestContext = this.tryFilter(span.requestContext, indexedState);
9200
9201
  return span;
9201
9202
  }
9202
9203
  /**
@@ -9209,7 +9210,8 @@ var SensitiveDataFilter = class {
9209
9210
  if (state) this.traceStates.delete(traceId);
9210
9211
  else state = {
9211
9212
  tokensByValue: /* @__PURE__ */ new Map(),
9212
- counters: /* @__PURE__ */ new Map()
9213
+ counters: /* @__PURE__ */ new Map(),
9214
+ issuedTokens: /* @__PURE__ */ new Set()
9213
9215
  };
9214
9216
  this.traceStates.set(traceId, state);
9215
9217
  while (this.traceStates.size > MAX_TRACKED_TRACES) {
@@ -9228,7 +9230,7 @@ var SensitiveDataFilter = class {
9228
9230
  if (obj === null || typeof obj !== "object") {
9229
9231
  if (typeof obj === "string") {
9230
9232
  const trimmed = obj.trim();
9231
- if (trimmed.startsWith("{") || trimmed.startsWith("[")) return this.redactJsonString(obj, indexedState);
9233
+ if (this.isJsonCandidate(trimmed)) return this.redactJsonString(obj, indexedState);
9232
9234
  }
9233
9235
  return obj;
9234
9236
  }
@@ -9245,6 +9247,16 @@ var SensitiveDataFilter = class {
9245
9247
  }
9246
9248
  return filtered;
9247
9249
  }
9250
+ isJsonCandidate(value) {
9251
+ const opening = value[0];
9252
+ if (opening !== "{" && opening !== "[") return false;
9253
+ let index = 1;
9254
+ while (value[index] === " " || value[index] === " " || value[index] === "\r" || value[index] === "\n") index++;
9255
+ const first = value[index];
9256
+ if (first === void 0) return false;
9257
+ if (opening === "{") return first === "\"" || first === "}";
9258
+ return first === "]" || first === "{" || first === "[" || first === "\"" || first === "-" || first >= "0" && first <= "9" || first === "t" || first === "f" || first === "n";
9259
+ }
9248
9260
  tryFilter(value, indexedState) {
9249
9261
  try {
9250
9262
  return this.deepFilter(value, /* @__PURE__ */ new WeakSet(), indexedState);
@@ -9307,6 +9319,7 @@ var SensitiveDataFilter = class {
9307
9319
  return str.slice(0, 3) + "…" + str.slice(len - 3);
9308
9320
  }
9309
9321
  if (this.redactionStyle === "indexed" && indexedState) {
9322
+ if (typeof value === "string" && indexedState.issuedTokens.has(value)) return value;
9310
9323
  const valueKey = createHash("sha256").update(String(value)).digest("hex");
9311
9324
  const existing = indexedState.tokensByValue.get(valueKey);
9312
9325
  if (existing) return existing;
@@ -9316,6 +9329,7 @@ var SensitiveDataFilter = class {
9316
9329
  indexedState.counters.set(label, count);
9317
9330
  const token = `[${label}_${count}]`;
9318
9331
  indexedState.tokensByValue.set(valueKey, token);
9332
+ indexedState.issuedTokens.add(token);
9319
9333
  return token;
9320
9334
  }
9321
9335
  return this.redactionToken;