litellm/tests/logging_callback_tests
Cesar Garcia d693596e87
feat(langfuse): Add support for custom masking function (#17826)
* feat(langfuse): Add support for custom masking function

Allow users to pass a custom masking function via metadata to selectively
redact sensitive data (credit cards, emails, PII) before sending to Langfuse.

Usage:
```python
def mask_pii(data):
    if isinstance(data, str):
        data = re.sub(r'\b\d{4}[\s-]?\d{4}[\s-]?\d{4}[\s-]?\d{4}\b', '[CARD]', data)
    return data

litellm.completion(
    model="gpt-4",
    messages=[...],
    metadata={"langfuse_masking_function": mask_pii}
)
```

* fix(langfuse): Isolate masking function from other logging integrations

Extract langfuse_masking_function from metadata early in the flow and store
it in a dedicated key (_langfuse_masking_function) that only the Langfuse
logger knows to look for. This prevents the callable from leaking to other
logging integrations (Datadog, S3, etc.) which would serialize it as
"<function at 0x...>".

Changes:
- scrub_sensitive_keys_in_metadata() now extracts and stores the function
- Langfuse logger looks in the dedicated key first, falls back to metadata
- Added tests to verify isolation works correctly
2025-12-11 15:36:54 -08:00
..
gcs_pub_sub_body Changes for CI/CD Tests 2025-11-22 10:21:52 -08:00
langfuse_expected_request_body test logging tests + mcp server QA checks 2025-11-15 08:58:46 -08:00
base_test.py Litellm dev 11 11 2024 (#6693) 2024-11-12 00:16:35 +05:30
conftest.py [Perf] Improvements for Async Success Handler (Logging Callbacks) - Approx +130 RPS (#13905) 2025-08-23 13:13:23 -07:00
create_mock_standard_logging_payload.py (fixes) datadog logging - handle 1MB max log size on DD (#6996) 2024-12-02 23:01:42 -08:00
gettysburg.wav (Testing) - Add e2e testing for langfuse logging with tags (#7922) 2025-01-22 09:09:25 -08:00
log.txt test: update test 2025-04-10 14:04:57 -07:00
test_alerting.py Fix/organization max budget not enforced (#17334) 2025-12-02 22:46:03 -08:00
test_amazing_s3_logs.py fix tests 2025-10-25 10:19:24 -07:00
test_assemble_streaming_responses.py test(test_assemble_streaming_responses.py): update test to use correct type 2025-03-17 18:17:01 -07:00
test_azure_blob_storage.py (feat) Add Azure Blob Storage Logging Integration (#7265) 2024-12-16 22:18:22 -08:00
test_bedrock_knowledgebase_hook.py [Fix] - Bedrock Knowledge Bases - add support for filtering kb queries (#16543) 2025-11-12 12:38:50 -08:00
test_built_in_tools_cost_tracking.py fix: use fastuuid helper (#14903) 2025-09-25 15:47:01 -07:00
test_custom_callback_router.py fix tests 2025-10-25 10:19:24 -07:00
test_datadog.py Fix: Datadog callback regression when ddtrace is installed (#17393) 2025-12-02 17:27:50 -08:00
test_datadog_llm_obs.py [Feat] Allow redacting message / response content for specific logging integrations - DD LLM Observability (#13158) 2025-07-31 16:44:16 -07:00
test_gcs_pub_sub.py [Feat] Responses API Session Handling - Multi media support (#13347) 2025-08-07 10:59:53 -07:00
test_generic_api_callback.py make generic api OSS + support multiple generic API's (#17152) 2025-11-26 18:38:38 -08:00
test_humanloop_unit_tests.py HumanLoop integration for Prompt Management (#7479) 2024-12-30 22:26:03 -08:00
test_langfuse_e2e_test.py fix LF tests 2025-10-04 10:39:17 -07:00
test_langfuse_unit_tests.py feat(langfuse): Add support for custom masking function (#17826) 2025-12-11 15:36:54 -08:00
test_langsmith_unit_test.py test logging tests + mcp server QA checks 2025-11-15 08:58:46 -08:00
test_log_db_redis_services.py LiteLLM Minor Fixes & Improvements (12/05/2024) (#7037) 2024-12-05 00:02:31 -08:00
test_logging_redaction_e2e_test.py test_redaction_responses_api 2025-11-08 13:43:22 -08:00
test_moderations_api_logging.py fix: use fastuuid helper (#14903) 2025-09-25 15:47:01 -07:00
test_opentelemetry_unit_tests.py test_opentelemetry_integration 2025-11-26 12:28:47 -08:00
test_otel_logging.py [Feat] OTEL - Log Cost Breakdown on OTEL Logger (#16334) 2025-11-06 13:53:53 -08:00
test_pagerduty_alerting.py [Refactor] Make Pagerduty a free feature (#10857) 2025-05-15 10:12:06 -07:00
test_posthog.py fix: Add atexit handlers to flush callbacks for async completions (#16487) 2025-11-11 19:12:53 -08:00
test_spend_logs.py fix tests 2025-10-25 10:19:24 -07:00
test_sqs_logger.py Add Langfuse OTEL and SQS to health check (#16514) 2025-11-12 18:25:30 -08:00
test_standard_logging_payload.py [Feat] - Cost Tracking - show input, output, tool call cost breakdown in StandardLoggingPayload (#14921) 2025-09-25 15:48:22 -07:00
test_token_counting.py test_stream_token_counting_anthropic_with_include_usage 2025-10-31 20:24:58 -07:00
test_unit_test_litellm_logging.py (performance improvement - litellm sdk + proxy) - ensure litellm does not create unnecessary threads when running async functions (#7680) 2025-01-10 17:57:22 -08:00
test_unit_tests_init_callbacks.py test_init_custom_logger_compatible_class_as_callback 2025-12-06 16:21:50 -08:00
test_view_request_resp_logs.py fix: use fastuuid helper (#14903) 2025-09-25 15:47:01 -07:00