nat.observability.processor.redaction#

Submodules#

Classes#

RedactionContext

Generic context provider for redaction operations.

RedactionContextState

Generic context state for redaction results.

SpanHeaderRedactionProcessor

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

Package Contents#

class RedactionContext(context: RedactionContextState)#

Bases: Generic[RedactionDataT]

Generic context provider for redaction operations.

Provides read-only access to redaction state and manages the RedactionManager lifecycle through async context managers.

Args:

RedactionDataT: The type of data being processed for redaction decisions.

_context_state: RedactionContextState#
property redaction_result: bool | None#

Get the current redaction result from context.

Returns:

bool | None: The cached redaction result, or None if not set.

async redaction_manager() collections.abc.AsyncGenerator[RedactionManager[RedactionDataT], None]#

Provide a redaction manager within an async context.

Creates and yields a RedactionManager instance for atomic redaction operations within the current context.

Yields:

RedactionManager[RedactionDataT]: Manager instance for redaction operations.

class RedactionContextState#

Generic context state for redaction results.

Stores the redaction result in a context variable to avoid redundant callback executions within the same request context.

redaction_result: contextvars.ContextVar[bool | None]#
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.