Skip to content

ref(litellm): migrate litellm wrapper to integrations API#160

Merged
Abhijeet Prasad (AbhiPrasad) merged 3 commits intomainfrom
abhi-feat-litellm-integrations-api-migration
Mar 31, 2026
Merged

ref(litellm): migrate litellm wrapper to integrations API#160
Abhijeet Prasad (AbhiPrasad) merged 3 commits intomainfrom
abhi-feat-litellm-integrations-api-migration

Conversation

@AbhiPrasad
Copy link
Copy Markdown
Member

@AbhiPrasad Abhijeet Prasad (AbhiPrasad) commented Mar 26, 2026

ref #116

Convert the LiteLLM instrumentation from the legacy wrappers pattern to the new integrations API introduced in #118.

Move the LiteLLM tracing implementation from wrappers/litellm.py into the integrations API under integrations/litellm/. This replaces the manual LiteLLMWrapper class approach with FunctionWrapperPatcher subclasses that use wrapt's wrap_function_wrapper for idempotent monkey-patching.

Key changes:

  • Add integrations/litellm/ with tracing.py, patchers.py, and integration.py following the standard integrations API pattern
  • Add wrap_litellm() helper that instruments a specific litellm module object using the patchers, complementing the existing patch_litellm() which patches the globally-imported module
  • Consolidate patcher list into _ALL_PATCHERS, shared by both LiteLLMIntegration.patchers and wrap_litellm()
  • Reduce wrappers/litellm.py to compatibility re-exports
  • Move tests and cassettes to integrations/litellm/
  • Add cassettes_dir parameter to autoinstrument_test_context

@AbhiPrasad Abhijeet Prasad (AbhiPrasad) changed the title feat(litellm): migrate litellm wrapper to integrations API ref(litellm): migrate litellm wrapper to integrations API Mar 26, 2026
@AbhiPrasad Abhijeet Prasad (AbhiPrasad) force-pushed the abhi-feat-litellm-integrations-api-migration branch from b9d4c22 to 749365f Compare March 31, 2026 15:05
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stamp

Example:
```python
import braintrust
braintrust.patch_litellm()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-patch_litellm()
+braintrust.integrations.litellm.patch_litellm()

Move the LiteLLM tracing implementation from wrappers/litellm.py into
the integrations API under integrations/litellm/. This replaces the
manual LiteLLMWrapper class approach with FunctionWrapperPatcher
subclasses that use wrapt's wrap_function_wrapper for idempotent
monkey-patching.

Key changes:
- Add integrations/litellm/ with tracing.py, patchers.py, and
  integration.py following the standard integrations API pattern
- Add wrap_litellm() helper that instruments a specific litellm module
  object using the patchers, complementing the existing patch_litellm()
  which patches the globally-imported module
- Consolidate patcher list into _ALL_PATCHERS, shared by both
  LiteLLMIntegration.patchers and wrap_litellm()
- Reduce wrappers/litellm.py to compatibility re-exports
- Move tests and cassettes to integrations/litellm/
- Add cassettes_dir parameter to autoinstrument_test_context
@AbhiPrasad Abhijeet Prasad (AbhiPrasad) force-pushed the abhi-feat-litellm-integrations-api-migration branch from 1ac9119 to 2b59e3a Compare March 31, 2026 20:15
@AbhiPrasad Abhijeet Prasad (AbhiPrasad) merged commit ba0bc10 into main Mar 31, 2026
35 checks passed
@AbhiPrasad Abhijeet Prasad (AbhiPrasad) deleted the abhi-feat-litellm-integrations-api-migration branch March 31, 2026 20:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants