@mastra/observability 1.11.1 → 1.12.0-alpha.0

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
@@ -13897,12 +13897,18 @@ var observabilityConfigValueSchema = external_exports.object(observabilityInstan
13897
13897
  message: "At least one exporter or a bridge is required"
13898
13898
  }
13899
13899
  );
13900
+ var sensitiveDataFilterOptionsSchema = external_exports.object({
13901
+ sensitiveFields: external_exports.array(external_exports.string()).optional(),
13902
+ redactionToken: external_exports.string().optional(),
13903
+ redactionStyle: external_exports.enum(["full", "partial"]).optional()
13904
+ }).strict();
13900
13905
  var observabilityRegistryConfigSchema = external_exports.object({
13901
13906
  default: external_exports.object({
13902
13907
  enabled: external_exports.boolean().optional()
13903
13908
  }).optional().nullable(),
13904
13909
  configs: external_exports.union([external_exports.record(external_exports.string(), external_exports.any()), external_exports.array(external_exports.any()), external_exports.null()]).optional(),
13905
- configSelector: external_exports.function().optional()
13910
+ configSelector: external_exports.function().optional(),
13911
+ sensitiveDataFilter: external_exports.union([external_exports.boolean(), sensitiveDataFilterOptionsSchema]).optional()
13906
13912
  }).passthrough().refine(
13907
13913
  (data) => {
13908
13914
  const isDefaultEnabled = data.default?.enabled === true;
@@ -20879,23 +20885,56 @@ var Observability = class extends MastraBase {
20879
20885
  }
20880
20886
  }
20881
20887
  }
20888
+ const sensitiveDataFilterSetting = config2.sensitiveDataFilter ?? true;
20889
+ const shouldAutoApplySensitiveFilter = sensitiveDataFilterSetting !== false;
20890
+ const sensitiveDataFilterOptions = typeof sensitiveDataFilterSetting === "object" && sensitiveDataFilterSetting !== null ? sensitiveDataFilterSetting : void 0;
20891
+ const buildAutoSensitiveFilter = () => {
20892
+ if (!shouldAutoApplySensitiveFilter) {
20893
+ return void 0;
20894
+ }
20895
+ return new SensitiveDataFilter(sensitiveDataFilterOptions);
20896
+ };
20882
20897
  if (config2.default?.enabled) {
20883
20898
  console.warn(
20884
- '[Mastra Observability] The "default: { enabled: true }" configuration is deprecated and will be removed in a future version. Please use explicit configs with DefaultExporter, CloudExporter, and SensitiveDataFilter instead. See https://mastra.ai/docs/observability/tracing/overview for the recommended configuration.'
20899
+ '[Mastra Observability] The "default: { enabled: true }" configuration is deprecated and will be removed in a future version. Please use explicit configs with DefaultExporter and CloudExporter instead. Sensitive data filtering is applied by default and can be controlled via the top-level "sensitiveDataFilter" option. See https://mastra.ai/docs/observability/tracing/overview for the recommended configuration.'
20885
20900
  );
20901
+ const autoFilter = buildAutoSensitiveFilter();
20886
20902
  const defaultInstance = new DefaultObservabilityInstance({
20887
20903
  serviceName: "mastra",
20888
20904
  name: "default",
20889
20905
  sampling: { type: "always" /* ALWAYS */ },
20890
20906
  exporters: [new DefaultExporter(), new CloudExporter()],
20891
- spanOutputProcessors: [new SensitiveDataFilter()]
20907
+ spanOutputProcessors: autoFilter ? [autoFilter] : []
20892
20908
  });
20893
20909
  this.#registry.register("default", defaultInstance, true);
20894
20910
  }
20895
20911
  if (config2.configs) {
20896
20912
  const instances = Object.entries(config2.configs);
20897
20913
  instances.forEach(([name, tracingDef], index) => {
20898
- const instance = isInstance(tracingDef) ? tracingDef : new DefaultObservabilityInstance({ ...tracingDef, name });
20914
+ let instance;
20915
+ if (isInstance(tracingDef)) {
20916
+ instance = tracingDef;
20917
+ if (shouldAutoApplySensitiveFilter) {
20918
+ const processors = instance.getSpanOutputProcessors?.() ?? [];
20919
+ const hasFilter = processors.some((p) => p instanceof SensitiveDataFilter);
20920
+ if (!hasFilter) {
20921
+ this.logger?.warn(
20922
+ "[Mastra Observability] Pre-instantiated observability instance does not include a SensitiveDataFilter. Auto-applied filtering is skipped for pre-instantiated instances. Add a SensitiveDataFilter to spanOutputProcessors when constructing the instance to redact sensitive data.",
20923
+ { instanceName: name }
20924
+ );
20925
+ }
20926
+ }
20927
+ } else {
20928
+ const userProcessors = tracingDef.spanOutputProcessors ?? [];
20929
+ const hasFilter = userProcessors.some((p) => p instanceof SensitiveDataFilter);
20930
+ const autoFilter = !hasFilter ? buildAutoSensitiveFilter() : void 0;
20931
+ const spanOutputProcessors = autoFilter ? [...userProcessors, autoFilter] : userProcessors;
20932
+ instance = new DefaultObservabilityInstance({
20933
+ ...tracingDef,
20934
+ name,
20935
+ spanOutputProcessors
20936
+ });
20937
+ }
20899
20938
  const isDefault = !config2.default?.enabled && index === 0;
20900
20939
  this.#registry.register(name, instance, isDefault);
20901
20940
  });