@@ -36,13 +36,15 @@ def setup_once():
3636
3737 # Other tasks that can be called: https://huggingface.co/docs/huggingface_hub/guides/inference#supported-providers-and-tasks
3838 huggingface_hub .inference ._client .InferenceClient .text_generation = (
39- _wrap_text_generation (
40- huggingface_hub .inference ._client .InferenceClient .text_generation
39+ _wrap_huggingface_task (
40+ huggingface_hub .inference ._client .InferenceClient .text_generation ,
41+ OP .GEN_AI_GENERATE_TEXT ,
4142 )
4243 )
4344 huggingface_hub .inference ._client .InferenceClient .chat_completion = (
44- _wrap_text_generation (
45- huggingface_hub .inference ._client .InferenceClient .chat_completion
45+ _wrap_huggingface_task (
46+ huggingface_hub .inference ._client .InferenceClient .chat_completion ,
47+ OP .GEN_AI_CHAT ,
4648 )
4749 )
4850
@@ -57,8 +59,8 @@ def _capture_exception(exc):
5759 sentry_sdk .capture_event (event , hint = hint )
5860
5961
60- def _wrap_text_generation ( f ):
61- # type: (Callable[..., Any]) -> Callable[..., Any]
62+ def _wrap_huggingface_task ( f , op ):
63+ # type: (Callable[..., Any], str ) -> Callable[..., Any]
6264 @wraps (f )
6365 def new_text_generation (* args , ** kwargs ):
6466 # type: (*Any, **Any) -> Any
@@ -81,21 +83,23 @@ def new_text_generation(*args, **kwargs):
8183 client = args [0 ]
8284 model = client .model or kwargs .get ("model" ) or ""
8385 streaming = kwargs .get ("stream" )
86+ operation_name = op .split ("." )[- 1 ]
8487
8588 span = sentry_sdk .start_span (
86- op = OP . GEN_AI_GENERATE_TEXT ,
87- name = f"generate_text { model } " ,
89+ op = op ,
90+ name = f"{ operation_name } { model } " ,
8891 origin = HuggingfaceHubIntegration .origin ,
8992 )
9093 span .__enter__ ()
9194
92- span .set_data (SPANDATA .GEN_AI_OPERATION_NAME , "generate_text" )
95+ span .set_data (SPANDATA .GEN_AI_OPERATION_NAME , operation_name )
9396 if model :
9497 span .set_data (SPANDATA .GEN_AI_REQUEST_MODEL , model )
9598
9699 try :
97100 res = f (* args , ** kwargs )
98101 except Exception as e :
102+ span .set_status ("error" )
99103 _capture_exception (e )
100104 span .__exit__ (None , None , None )
101105 raise e from None
@@ -120,9 +124,6 @@ def new_text_generation(*args, **kwargs):
120124
121125 if isinstance (res , TextGenerationOutput ):
122126 if should_send_default_pii () and integration .include_prompts :
123- import ipdb
124-
125- ipdb .set_trace ()
126127 set_data_normalized (
127128 span ,
128129 SPANDATA .GEN_AI_RESPONSE_TEXT ,
0 commit comments