SensitiveDataFilter
span のフィールドから機密情報をマスキングする SpanOutputProcessor です。
デフォルトで自動適用デフォルトで自動適用への直接リンク
Observability は、設定された各インスタンスの spanOutputProcessors に SensitiveDataFilter を自動的に追加します。これにより、機密情報は 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' },
})
設定の spanOutputProcessors に SensitiveDataFilter がすでに含まれている場合、二重のマスキングを避けるため、自動適用される filter はスキップされます。事前にインスタンス化された ObservabilityInstance の値は変更されません。必要に応じて、その processor に SensitiveDataFilter を追加してください。
コンストラクターコンストラクターへの直接リンク
new SensitiveDataFilter(options?: SensitiveDataFilterOptions)
SensitiveDataFilterOptionssensitivedatafilteroptionsへの直接リンク
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
}
RedactionStyleredactionstyleへの直接リンク
type RedactionStyle = 'full' | 'partial'
メソッドメソッドへの直接リンク
processprocessへの直接リンク
process(span: AnySpan): AnySpan
attributes、metadata、input、output、errorInfo の主要フィールド全体で機密データを filter し、span を処理します。
戻り値: 機密値がマスキングされた新しい span。
shutdownshutdownへの直接リンク
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',
]
処理動作処理動作への直接リンク
フィールドの照合フィールドの照合への直接リンク
- 大文字と小文字を区別しない:
APIKey、apikey、ApiKeyはすべて一致します - 区切り文字を区別しない:
api-key、api_key、apiKeyは同一として扱われます - 完全一致:正規化後、フィールドは完全に一致する必要があります
tokenはtoken、Token、TOKENに一致しますtokenはpromptTokensやtokenCountには一致しません
マスキング形式マスキング形式への直接リンク
完全マスキング(デフォルト)完全マスキング(デフォルト)への直接リンク
一致したすべての値を redactionToken に置き換えます。
部分マスキング部分マスキングへの直接リンク
- 先頭 3 文字と末尾 3 文字を表示します
- 6 文字以下の値は完全にマスキングされます
- 文字列以外の値は、部分マスキングの前に文字列へ変換されます
エラー処理エラー処理への直接リンク
フィールドの filtering に失敗した場合、そのフィールドは次の値に置き換えられます。
{
error: {
processor: 'sensitive-data-filter'
}
}
処理対象フィールド処理対象フィールドへの直接リンク
filter は次のフィールドを再帰的に処理します。
span.attributes- span のメタデータとプロパティspan.metadata- カスタムメタデータspan.input- 入力データspan.output- 出力データspan.errorInfo- エラー情報
ネストされた object、配列、循環参照を安全に処理します。