@@ -834,21 +834,33 @@ def wrap_base_client_process_response(wrapped, instance, args, kwargs):
834
834
835
835
836
836
def instrument_openai_util (module ):
837
- wrap_function_wrapper (module , "convert_to_openai_object" , wrap_convert_to_openai_object )
837
+ if hasattr (module , "convert_to_openai_object" ):
838
+ wrap_function_wrapper (module , "convert_to_openai_object" , wrap_convert_to_openai_object )
839
+ # This is to mark where we instrument so the SDK knows not to instrument them
840
+ # again.
841
+ setattr (module .convert_to_openai_object , "_nr_wrapped" , True )
838
842
839
843
840
844
def instrument_openai_api_resources_embedding (module ):
841
- if hasattr (module .Embedding , "create" ):
842
- wrap_function_wrapper (module , "Embedding.create" , wrap_embedding_sync )
843
- if hasattr (module .Embedding , "acreate" ):
844
- wrap_function_wrapper (module , "Embedding.acreate" , wrap_embedding_async )
845
+ if hasattr (module , "Embedding" ):
846
+ if hasattr (module .Embedding , "create" ):
847
+ wrap_function_wrapper (module , "Embedding.create" , wrap_embedding_sync )
848
+ if hasattr (module .Embedding , "acreate" ):
849
+ wrap_function_wrapper (module , "Embedding.acreate" , wrap_embedding_async )
850
+ # This is to mark where we instrument so the SDK knows not to instrument them
851
+ # again.
852
+ setattr (module .Embedding , "_nr_wrapped" , True )
845
853
846
854
847
855
def instrument_openai_api_resources_chat_completion (module ):
848
- if hasattr (module .ChatCompletion , "create" ):
849
- wrap_function_wrapper (module , "ChatCompletion.create" , wrap_chat_completion_sync )
850
- if hasattr (module .ChatCompletion , "acreate" ):
851
- wrap_function_wrapper (module , "ChatCompletion.acreate" , wrap_chat_completion_async )
856
+ if hasattr (module , "ChatCompletion" ):
857
+ if hasattr (module .ChatCompletion , "create" ):
858
+ wrap_function_wrapper (module , "ChatCompletion.create" , wrap_chat_completion_sync )
859
+ if hasattr (module .ChatCompletion , "acreate" ):
860
+ wrap_function_wrapper (module , "ChatCompletion.acreate" , wrap_chat_completion_async )
861
+ # This is to mark where we instrument so the SDK knows not to instrument them
862
+ # again.
863
+ setattr (module .ChatCompletion , "_nr_wrapped" , True )
852
864
853
865
854
866
def instrument_openai_resources_chat_completions (module ):
@@ -858,7 +870,6 @@ def instrument_openai_resources_chat_completions(module):
858
870
wrap_function_wrapper (module , "AsyncCompletions.create" , wrap_chat_completion_async )
859
871
860
872
861
- # OpenAI v1 instrumentation points
862
873
def instrument_openai_resources_embeddings (module ):
863
874
if hasattr (module , "Embeddings" ):
864
875
if hasattr (module .Embeddings , "create" ):
0 commit comments