3232
3333
3434DATA_FIELDS = {
35- "temperature" : SPANDATA .AI_TEMPERATURE ,
36- "top_p" : SPANDATA .AI_TOP_P ,
37- "top_k" : SPANDATA .AI_TOP_K ,
38- "function_call" : SPANDATA .AI_FUNCTION_CALL ,
39- "tool_calls" : SPANDATA .AI_TOOL_CALLS ,
40- "tools" : SPANDATA .AI_TOOLS ,
41- "response_format" : SPANDATA .AI_RESPONSE_FORMAT ,
42- "logit_bias" : SPANDATA .AI_LOGIT_BIAS ,
43- "tags" : SPANDATA .AI_TAGS ,
35+ "temperature" : SPANDATA .GEN_AI_REQUEST_TEMPERATURE ,
36+ "top_p" : SPANDATA .GEN_AI_REQUEST_TOP_P ,
37+ "top_k" : SPANDATA .GEN_AI_REQUEST_TOP_K ,
38+ "function_call" : SPANDATA .GEN_AI_RESPONSE_TOOL_CALLS ,
39+ "tool_calls" : SPANDATA .GEN_AI_RESPONSE_TOOL_CALLS ,
40+ "tools" : SPANDATA .GEN_AI_REQUEST_AVAILABLE_TOOLS ,
41+ "response_format" : SPANDATA .GEN_AI_RESPONSE_FORMAT ,
42+ "logit_bias" : SPANDATA .GEN_AI_REQUEST_LOGIT_BIAS ,
43+ "tags" : SPANDATA .GEN_AI_REQUEST_TAGS ,
4444}
4545
46+ # TODO(shellmayr): is this still the case?
4647# To avoid double collecting tokens, we do *not* measure
4748# token counts for models for which we have an explicit integration
4849NO_COLLECT_TOKEN_MODELS = [
@@ -191,7 +192,7 @@ def on_llm_start(
191192 )
192193 span = watched_span .span
193194 if should_send_default_pii () and self .include_prompts :
194- set_data_normalized (span , SPANDATA .AI_INPUT_MESSAGES , prompts )
195+ set_data_normalized (span , SPANDATA .GEN_AI_REQUEST_MESSAGES , prompts )
195196 for k , v in DATA_FIELDS .items ():
196197 if k in all_params :
197198 set_data_normalized (span , v , all_params [k ])
@@ -222,11 +223,11 @@ def on_chat_model_start(self, serialized, messages, *, run_id, **kwargs):
222223 if not model and "anthropic" in all_params .get ("_type" ):
223224 model = "claude-2"
224225 if model :
225- span .set_data (SPANDATA .AI_MODEL_ID , model )
226+ span .set_data (SPANDATA .GEN_AI_REQUEST_MODEL , model )
226227 if should_send_default_pii () and self .include_prompts :
227228 set_data_normalized (
228229 span ,
229- SPANDATA .AI_INPUT_MESSAGES ,
230+ SPANDATA .GEN_AI_REQUEST_MESSAGES ,
230231 [
231232 [self ._normalize_langchain_message (x ) for x in list_ ]
232233 for list_ in messages
@@ -271,7 +272,7 @@ def on_llm_end(self, response, *, run_id, **kwargs):
271272 if should_send_default_pii () and self .include_prompts :
272273 set_data_normalized (
273274 span_data .span ,
274- SPANDATA .AI_RESPONSES ,
275+ SPANDATA .GEN_AI_RESPONSE_TEXT ,
275276 [[x .text for x in list_ ] for list_ in response .generations ],
276277 )
277278
@@ -317,7 +318,9 @@ def on_chain_start(self, serialized, inputs, *, run_id, **kwargs):
317318 )
318319 metadata = kwargs .get ("metadata" )
319320 if metadata :
320- set_data_normalized (watched_span .span , SPANDATA .AI_METADATA , metadata )
321+ set_data_normalized (
322+ watched_span .span , SPANDATA .GEN_AI_REQUEST_METADATA , metadata
323+ )
321324
322325 def on_chain_end (self , outputs , * , run_id , ** kwargs ):
323326 # type: (SentryLangchainCallback, Dict[str, Any], UUID, Any) -> Any
@@ -350,7 +353,9 @@ def on_agent_action(self, action, *, run_id, **kwargs):
350353 )
351354 if action .tool_input and should_send_default_pii () and self .include_prompts :
352355 set_data_normalized (
353- watched_span .span , SPANDATA .AI_INPUT_MESSAGES , action .tool_input
356+ watched_span .span ,
357+ SPANDATA .GEN_AI_REQUEST_MESSAGES ,
358+ action .tool_input ,
354359 )
355360
356361 def on_agent_finish (self , finish , * , run_id , ** kwargs ):
@@ -364,7 +369,9 @@ def on_agent_finish(self, finish, *, run_id, **kwargs):
364369 return
365370 if should_send_default_pii () and self .include_prompts :
366371 set_data_normalized (
367- span_data .span , SPANDATA .AI_RESPONSES , finish .return_values .items ()
372+ span_data .span ,
373+ SPANDATA .GEN_AI_RESPONSE_TEXT ,
374+ finish .return_values .items (),
368375 )
369376 self ._exit_span (span_data , run_id )
370377
@@ -384,12 +391,14 @@ def on_tool_start(self, serialized, input_str, *, run_id, **kwargs):
384391 if should_send_default_pii () and self .include_prompts :
385392 set_data_normalized (
386393 watched_span .span ,
387- SPANDATA .AI_INPUT_MESSAGES ,
394+ SPANDATA .GEN_AI_REQUEST_MESSAGES ,
388395 kwargs .get ("inputs" , [input_str ]),
389396 )
390397 if kwargs .get ("metadata" ):
391398 set_data_normalized (
392- watched_span .span , SPANDATA .AI_METADATA , kwargs .get ("metadata" )
399+ watched_span .span ,
400+ SPANDATA .GEN_AI_REQUEST_METADATA ,
401+ kwargs .get ("metadata" ),
393402 )
394403
395404 def on_tool_end (self , output , * , run_id , ** kwargs ):
@@ -403,7 +412,9 @@ def on_tool_end(self, output, *, run_id, **kwargs):
403412 if not span_data :
404413 return
405414 if should_send_default_pii () and self .include_prompts :
406- set_data_normalized (span_data .span , SPANDATA .AI_RESPONSES , output )
415+ set_data_normalized (
416+ span_data .span , SPANDATA .GEN_AI_RESPONSE_TEXT , output
417+ )
407418 self ._exit_span (span_data , run_id )
408419
409420 def on_tool_error (self , error , * args , run_id , ** kwargs ):
0 commit comments