Commit Graph

13 Commits

Author SHA1 Message Date
YutaSaito 13df50830d chore: prefer standard trace id for Langfuse logging (#17791) 2025-12-11 08:18:45 -08:00
YutaSaito 80a18f989a feat: propagate Langfuse trace_id (#17669) 2025-12-09 12:25:52 -08:00
Alexsander Hamir 1254a92e66 fix: make test_log_langfuse_v2_handles_null_usage_values more robust (#17599)
- Reset mock call counts at start of test to ensure clean state
- Add span method to mock trace to handle log_provider_specific_information_as_span calls
- Re-establish mock chain before test call to ensure fresh state
- Add exception handling to catch and report errors during test execution
- Add verification that trace was called before checking generation

This should fix the flaky test that was failing intermittently with
'Expected generation to have been called once. Called 0 times.'
2025-12-06 09:21:00 -08:00
Alexsander Hamir 1e89aa3068 Fix: Resolve flakiness in three integration tests (#17594)
Fixed three flaky tests that were intermittently failing in CI:

1. test_no_duplicate_spend_logs (test_litellm/responses/test_no_duplicate_spend_logs.py)
   Problem: Used await asyncio.sleep(1) to wait for async logging completion,
            which created race conditions. The async logging worker queues tasks
            in the background, and sleep() doesn't guarantee completion.

   Fix: Replaced sleep() with GLOBAL_LOGGING_WORKER.flush() which properly waits
        for the logging queue to empty, ensuring all async logging tasks complete
        before assertions run.

2. test_log_langfuse_v2_handles_null_usage_values (test_litellm/integrations/test_langfuse.py)
   Problem: Used datetime.datetime.now() twice for start_time and end_time, which
            could cause timing inconsistencies between test runs, especially in
            CI environments with variable execution speeds.

   Fix: Use fixed timestamps instead of datetime.now() to ensure consistent timing
        across all test runs, eliminating timing-related flakiness.

3. test_watsonx_gpt_oss_prompt_transformation (test_litellm/llms/watsonx/test_watsonx.py)
   Problem: Directly accessed mock_post.call_args without checking if it exists,
            which could be None if the mock wasn't called or if an exception
            occurred before the POST request. The test catches exceptions and
            continues, making this a potential failure point.

   Fix: Added proper assertions and use call_args_list[0] for safer access:
        - Assert that call_args_list has at least one call
        - Assert that call_args is not None
        - Assert that 'data' key exists in kwargs
        This ensures the test fails with clear error messages rather than
        intermittent AttributeError exceptions.

All fixes maintain the original test intent while making them deterministic
and reliable in CI environments.
2025-12-06 07:57:03 -08:00
Alexsander Hamir 3db6d2a1ed Reapply Langfuse logger test mock setup fix (#17591)
Reapplies the fix from commit a885e21543 that was
reverted in 6c9556be67.

The original revert was done because the test was flaky and giving false
negatives. This fix properly mocks the Langfuse client to ensure the test
can correctly verify that _log_langfuse_v2 converts None usage values to 0.

Changes:
- Add mock_langfuse_client.client attribute to prevent errors during init
- Add trace_id to mock_langfuse_generation for proper return value handling
- Remove redundant mock setup code
- Explicitly set logger.Langfuse to mock client after initialization
- Set logger.langfuse_sdk_version to ensure _supports_* methods work correctly
2025-12-06 07:26:34 -08:00
Alexsander Hamir 6c9556be67 Revert "Fix Langfuse logger test mock setup (#17588)" (#17590)
This reverts commit a885e21543.
2025-12-06 06:25:47 -08:00
Alexsander Hamir a885e21543 Fix Langfuse logger test mock setup (#17588)
* Fix test_log_langfuse_v2_handles_null_usage_values test failure

The test was failing because the logger's Langfuse client wasn't properly
mocked. Even though sys.modules was mocked, the logger's __init__ method
creates its own Langfuse client instance that wasn't using the test's mock.

Changes:
- Explicitly set logger.Langfuse to the mock client after initialization
- Set logger.langfuse_sdk_version to ensure _supports_* methods work correctly
- Added mock_langfuse_client.client attribute to prevent errors during init
- Added trace_id to mock_langfuse_generation for proper return value handling
- Removed redundant mock setup code

This ensures the test can properly verify that _log_langfuse_v2 correctly
converts None usage values to 0 by allowing the mock's generation method
to be called and asserted.

Fixes: AssertionError: Expected 'generation' to have been called once. Called 0 times.
2025-12-06 05:56:24 -08:00
Ishaan Jaffer 39c1a970a1 fix 2025-11-14 18:56:30 -08:00
Alan Ponnachan 5f12e4be1e fix(langfuse): Handle null usage values to prevent validation errors (#16396)
* langfuse null validation fix

* formatting
2025-11-10 19:34:56 -08:00
anthony-liner 9ca73d5504 fix: set usage_details.total in langfuse integration 2025-09-29 16:30:44 +09:00
Fabricio Ceschin faaae888f1 Merge conflicts 2025-09-08 11:34:45 -04:00
Cole McIntosh 0666ede8e3 fix: correct patch path in langfuse test for MAX_LANGFUSE_INITIALIZED_CLIENTS (#13192)
The test was failing because it was trying to patch MAX_LANGFUSE_INITIALIZED_CLIENTS
at the wrong path. The constant is imported from litellm.constants into the langfuse
module namespace, so we need to use patch.object on the imported module reference.

Changes:
- Import langfuse module explicitly for patching
- Use patch.object instead of patch string path
- This fixes the AttributeError that was causing CI failures
2025-07-31 17:11:28 -07:00
Krish Dholakia ef42461c1e Litellm fix GitHub action testing (#11163)
* test: add __init__.py files

* refactor: rename test folder to avoid naming conflict

* test: update workflows

* test: update tests

* test: update imports

* test: update tests

* test: remove unused import

* ci(test-litellm.yml): add pytest retry to github workflow

* test: fix test
2025-05-26 14:41:42 -07:00