-
[OPIK-3049] [P SDK] Add support for PII information filtering (#4055)
发布于
2025-11-13 18:56:30 +00:00 - [OPIK-3049] [P SDK] Introduce a text anonymization framework with rules-based abstraction
- Added a framework for text anonymization, providing generic
Rule,RegexRule, andFunctionRuleimplementations for customizable anonymization logic. - Introduced
RulesAnonymizerto sequentially apply defined rules to anonymize text data. - Implemented a core
Anonymizerclass with support for recursive handling of nested structures (e.g., dicts, lists). - Added unit tests for various scenarios, including regex-based, function-based, and complex anonymization workflows.
- Ensured safe and efficient recursion with a customizable depth limit and robust handling of edge cases like circular references.
- [OPIK-3049] [P SDK] Add
create_anonymizerfactory function for flexible anonymization rule creation
- Introduced
create_anonymizerto handle multiple rule formats including dictionaries, tuples, functions, and lists. - Added robust validation for rule inputs with custom exceptions for invalid formats.
- Included a comprehensive test suite covering various rule types, edge cases, and error handling scenarios.
- [OPIK-3049] [P SDK] Refactor imports and extend anonymizer functionality
- Consolidated imports in anonymizer modules to improve readability and maintain modularity.
- Introduced
anonymizer_hookfor registering, clearing, and applying global anonymizers. - Refactored
RulesAnonymizerand related factory code to align with the new import structure and naming conventions.
- [OPIK-3049] [P SDK] Add
has_anonymizersutility function
- Introduced
has_anonymizersto check if any anonymizers are registered.
- [OPIK-3049] [P SDK] Refactor anonymizer imports and extend functionality with message anonymization
- Updated import structure in anonymizer modules for consistency (
factory,rules_anonymizer,rules). - Added
message_anonymizerfor anonymizingCreateSpanMessageandCreateTraceMessageinputs, outputs, and metadata fields. - Introduced unit tests for
message_anonymizercovering diverse scenarios such as nested data, unsupported message types, and custom anonymization rules. - Refactored test cases in
test_factory.pyandtest_rules_anonymizer.pyto align with updated import paths and naming conventions.
- [OPIK-3049] [P SDK] Refactor anonymizer structure
- Extracted recursive anonymization logic to a new
RecursiveAnonymizerbase class for reusability. - Updated
RulesAnonymizerto inherit fromRecursiveAnonymizer, simplifying the inheritance structure. - Refactored anonymizer module to consolidate recursive handling and improve maintainability.
- [OPIK-3049] [P SDK] Add
encode_and_anonymizefunction with comprehensive tests
- Introduced
encode_and_anonymizefunction injsonable_encoderto support field-level anonymization during encoding. - Added extensive unit tests to validate functionality, including scenarios with nested objects, various data types, and integration with custom anonymizers.
- Ensured compatibility with existing encoding logic while enhancing flexibility for sensitive data handling.
- [OPIK-3049] [P SDK] Extend anonymizer functionality to support field-specific metadata
- Updated
Anonymizerinterface to accept additionalkwargs, enabling more context-aware anonymization. - Enhanced
jsonable_encoderto pass field names to anonymizers for improved control over field-specific anonymization. - Added
has_anonymizers,apply_anonymizers, andadd_anonymizerexports to hooks for streamlined integration of anonymizers. - Introduced new unit test scenarios to validate field-specific anonymization behavior within
encode_and_anonymize.
- [OPIK-3049] [P SDK] Enhance anonymization with
fields_to_anonymizeintegration and refactorencode_and_anonymize
- Introduced
fields_to_anonymizestatic methods in message classes for centralized anonymization field definitions. - Refactored
encode_and_anonymizeto support multiple anonymizers and add context during anonymization. - Replaced
jsonable_encodercalls with the newencode_and_anonymizefunction across message processing modules. - Added support for
get_anonymizersin anonymizer hooks for streamlined anonymizer retrieval. - Extended unit tests in
test_jsonable_encoderto cover multiple anonymizers and new context scenarios.
- [OPIK-3049] [P SDK] Enhance anonymization with
fields_to_anonymizeintegration and refactorencode_and_anonymize
- Introduced
fields_to_anonymizestatic methods in message classes for centralized anonymization field definitions. - Refactored
encode_and_anonymizeto support multiple anonymizers and add context during anonymization. - Replaced
jsonable_encodercalls with the newencode_and_anonymizefunction across message processing modules. - Added support for
get_anonymizersin anonymizer hooks for streamlined anonymizer retrieval. - Extended unit tests in
test_jsonable_encoderto cover multiple anonymizers and new context scenarios.
- [OPIK-3049] [P SDK] Added documentation describing anonymizers use in OPIK.
下载附件