dvIsSensitiveTelemetryKey function

bool dvIsSensitiveTelemetryKey(
  1. String key
)

Whether a telemetry attribute named key is redacted whatever its value.

Matched on the key's dotted segments: a segment that is a registered @DVModel.sensitiveField() name, or that ends in a credential word (password, token, authorization, cookie...). Ends in rather than contains, so http.request.header.authorization and access_token are redacted while gen_ai.usage.input_tokens -- a count -- is not.

Implementation

bool dvIsSensitiveTelemetryKey(String key) {
  // Attribute keys are few and repeat on every span, so each is decided once.
  // The answers are forgotten when the sensitive field names change.
  if (_sensitiveKeyGeneration != DVLogger._sensitiveRevision) {
    _sensitiveKeys.clear();
    _sensitiveKeyGeneration = DVLogger._sensitiveRevision;
  }

  final bool? known = _sensitiveKeys[key];
  if (known != null) return known;
  if (_sensitiveKeys.length > 4096) _sensitiveKeys.clear();
  return _sensitiveKeys[key] = _decideSensitiveKey(key);
}