メインコンテンツへ移動

SensitiveDataFilter

span のフィールドから機密情報をマスキングする SpanOutputProcessor です。

デフォルトで自動適用
デフォルトで自動適用への直接リンク

Observability は、設定された各インスタンスの spanOutputProcessorsSensitiveDataFilter を自動的に追加します。これにより、機密情報は Mastra cloud exporter などの exporter に届く前にマスキングされます。この filter は最後(ユーザー指定の processor の後)に実行されるため、先行する processor が追加または露出させた機密データもマスキングされます。オプションをカスタマイズする場合を除き、手動で追加する必要はありません。

自動適用される filter を無効化またはカスタマイズするには、Observability registry 設定sensitiveDataFilter オプションを使用します。

import { Observability } from '@mastra/observability'

new Observability({
configs: {/* ... */},
// disable the auto-applied filter
sensitiveDataFilter: false,
// or customize it
// sensitiveDataFilter: { sensitiveFields: ['mySecret'], redactionStyle: 'partial' },
})

設定の spanOutputProcessorsSensitiveDataFilter がすでに含まれている場合、二重のマスキングを避けるため、自動適用される filter はスキップされます。事前にインスタンス化された ObservabilityInstance の値は変更されません。必要に応じて、その processor に SensitiveDataFilter を追加してください。

コンストラクター
コンストラクターへの直接リンク

new SensitiveDataFilter(options?: SensitiveDataFilterOptions)

SensitiveDataFilterOptions
sensitivedatafilteroptionsへの直接リンク

interface SensitiveDataFilterOptions {
/**
* List of sensitive field names to redact.
* Matching is case-insensitive and normalizes separators
* (api-key, api_key, Api Key → apikey).
* Defaults include: password, token, secret, key, apikey, auth,
* authorization, bearer, bearertoken, jwt, credential,
* clientsecret, privatekey, refresh, ssn.
*/
sensitiveFields?: string[]

/**
* The token used for full redaction.
* Default: "[REDACTED]"
*/
redactionToken?: string

/**
* Style of redaction to use:
* - "full": always replace with redactionToken
* - "partial": show 3 characters from the start and end, redact the middle
* Default: "full"
*/
redactionStyle?: RedactionStyle
}

RedactionStyle
redactionstyleへの直接リンク

type RedactionStyle = 'full' | 'partial'

メソッド
メソッドへの直接リンク

process
processへの直接リンク

process(span: AnySpan): AnySpan

attributes、metadata、input、output、errorInfo の主要フィールド全体で機密データを filter し、span を処理します。

戻り値: 機密値がマスキングされた新しい span。

shutdown
shutdownへの直接リンク

async shutdown(): Promise<void>

この processor ではクリーンアップは不要です。

プロパティ
プロパティへの直接リンク

readonly name = 'sensitive-data-filter';

デフォルトの機密フィールド
デフォルトの機密フィールドへの直接リンク

カスタムフィールドが指定されていない場合:

[
'password',
'token',
'secret',
'key',
'apikey',
'auth',
'authorization',
'bearer',
'bearertoken',
'jwt',
'credential',
'clientsecret',
'privatekey',
'refresh',
'ssn',
]

処理動作
処理動作への直接リンク

フィールドの照合
フィールドの照合への直接リンク

  • 大文字と小文字を区別しないAPIKeyapikeyApiKey はすべて一致します
  • 区切り文字を区別しないapi-keyapi_keyapiKey は同一として扱われます
  • 完全一致:正規化後、フィールドは完全に一致する必要があります
    • tokentokenTokenTOKEN に一致します
    • tokenpromptTokenstokenCount には一致しません

マスキング形式
マスキング形式への直接リンク

完全マスキング(デフォルト)
完全マスキング(デフォルト)への直接リンク

一致したすべての値を redactionToken に置き換えます。

部分マスキング
部分マスキングへの直接リンク

  • 先頭 3 文字と末尾 3 文字を表示します
  • 6 文字以下の値は完全にマスキングされます
  • 文字列以外の値は、部分マスキングの前に文字列へ変換されます

エラー処理
エラー処理への直接リンク

フィールドの filtering に失敗した場合、そのフィールドは次の値に置き換えられます。

{
error: {
processor: 'sensitive-data-filter'
}
}

処理対象フィールド
処理対象フィールドへの直接リンク

filter は次のフィールドを再帰的に処理します。

  • span.attributes - span のメタデータとプロパティ
  • span.metadata - カスタムメタデータ
  • span.input - 入力データ
  • span.output - 出力データ
  • span.errorInfo - エラー情報

ネストされた object、配列、循環参照を安全に処理します。