nat.observability.processor.redaction.span_header_redaction_processor#

Attributes#

Classes#

SpanHeaderRedactionProcessor

Processor that redacts the Span based on multiple headers and callback logic.

Module Contents#

logger#
class SpanHeaderRedactionProcessor(
headers: list[str],
attributes: list[str],
callback: collections.abc.Callable[Ellipsis, Any],
enabled: bool = True,
force_redact: bool = False,
redaction_value: str = '[REDACTED]',
redaction_tag: str | None = None,
)#

Bases: nat.observability.processor.redaction.contextual_span_redaction_processor.ContextualSpanRedactionProcessor[dict[str, Any]]

Processor that redacts the Span based on multiple headers and callback logic.

Uses context-scoped atomic updates to avoid redundant callback executions within a single context. Since headers are static per request, the callback result is cached for the entire context using an asynccontextmanager to ensure atomic operations.

Args:

headers: List of header keys to extract and pass to the callback attributes: List of Span attribute keys to redact callback: Callable that determines if redaction should occur enabled: Whether the processor is enabled (default: True) force_redact: If True, always redact regardless of header checks (default: False) redaction_value: The value to replace redacted attributes with (default: “[REDACTED]”)

headers#
extract_data_from_context() dict[str, Any] | None#

Extract header data from the context.

Returns:

dict[str, Any] | None: Dictionary of header names to values, or None if no headers.

validate_data(data: dict[str, Any]) bool#

Validate that the extracted headers are suitable for callback execution.

Args:

data (dict[str, Any]): The extracted header dictionary.

Returns:

bool: True if headers exist and are not all None, False otherwise.