File tree Expand file tree Collapse file tree 1 file changed +12
-0
lines changed
src/openlayer/lib/integrations Expand file tree Collapse file tree 1 file changed +12
-0
lines changed Original file line number Diff line number Diff line change 1919
2020logger = logging .getLogger (__name__ )
2121
22+ # Flag to prevent multiple patching
23+ _litellm_traced = False
24+
2225
2326def trace_litellm () -> None :
2427 """Patch the litellm.completion function to trace completions.
@@ -57,11 +60,18 @@ def trace_litellm() -> None:
5760 ... inference_id="custom-id-123" # Optional Openlayer parameter
5861 ... )
5962 """
63+ global _litellm_traced
64+
6065 if not HAVE_LITELLM :
6166 raise ImportError (
6267 "LiteLLM library is not installed. Please install it with: pip install litellm"
6368 )
6469
70+ # Prevent multiple patching - this avoids duplicate traces
71+ if _litellm_traced :
72+ logger .debug ("trace_litellm() already called - skipping to prevent duplicate traces" )
73+ return
74+
6575 original_completion = litellm .completion
6676
6777 @wraps (original_completion )
@@ -84,6 +94,8 @@ def traced_completion(*args, **kwargs):
8494 )
8595
8696 litellm .completion = traced_completion
97+ _litellm_traced = True
98+ logger .debug ("litellm.completion has been patched for Openlayer tracing" )
8799
88100
89101def handle_streaming_completion (
You can’t perform that action at this time.
0 commit comments