nat.observability.processor.redaction.contextual_redaction_processor#

Attributes#

Classes#

ContextualRedactionProcessor

Generic processor with context-aware caching for any data type.

Module Contents#

logger#
RedactionDataT#
class ContextualRedactionProcessor(
callback: collections.abc.Callable[Ellipsis, Any],
enabled: bool,
force_redact: bool,
redaction_value: str,
)#

Bases: nat.observability.processor.redaction.redaction_processor.RedactionProcessor[nat.observability.processor.redaction.redaction_processor.RedactionInputT, RedactionDataT]

Generic processor with context-aware caching for any data type.

Provides a framework for redaction processors that need to: - Extract data from the request context (headers, cookies, query params, etc.) - Execute callbacks to determine redaction decisions - Cache results within the request context to avoid redundant callback executions - Handle race conditions with atomic operations

This class handles all the generic caching, context management, and callback execution logic. Subclasses only need to implement data extraction and validation.

Args:

callback: Callable that determines if redaction should occur based on extracted data enabled: Whether the processor is enabled force_redact: If True, always redact regardless of data checks redaction_value: The value to replace redacted attributes with

callback#
enabled#
force_redact#
redaction_value#
_redaction_context#
abstractmethod extract_data_from_context() RedactionDataT | None#

Extract the relevant data from the context for redaction decision.

This method must be implemented by subclasses to extract their specific data type (headers, cookies, query params, etc.) from the request context

Returns:

RedactionDataT | None: The extracted data, or None if no relevant data found

abstractmethod validate_data(data: RedactionDataT) bool#

Validate that the extracted data is suitable for callback execution.

This method allows subclasses to implement their own validation logic (e.g., checking if headers exist, if cookies are not empty, etc.).

Args:

data (RedactionDataT): The extracted data to validate

Returns:

bool: True if the data is valid for callback execution, False otherwise

async should_redact(
item: nat.observability.processor.redaction.redaction_processor.RedactionInputT,
) bool#

Determine if this span should be redacted based on extracted data.

Extracts the relevant data from the context, validates it, and passes it to the callback function to determine if redaction should occur. Results are cached within the request context to avoid redundant callback executions.

Args:

item (RedactionInputT): The item to check

Returns:

bool: True if the span should be redacted, False otherwise