@@ -526,42 +526,24 @@ def log_context(context: List[str]) -> None:
526526 logger .warning ("No current step found to log context." )
527527
528528
529- def update_current_trace (
530- name : Optional [str ] = None ,
531- tags : Optional [List [str ]] = None ,
532- metadata : Optional [Dict [str , Any ]] = None ,
533- thread_id : Optional [str ] = None ,
534- user_id : Optional [str ] = None ,
535- input : Optional [Any ] = None ,
536- output : Optional [Any ] = None ,
537- feedback : Optional ['traces.Feedback' ] = None ,
538- test_case : Optional ['traces.LLMTestCase' ] = None ,
539- ) -> None :
529+ def update_current_trace (** kwargs ) -> None :
540530 """Updates the current trace metadata with the provided values.
541531
542532 This function allows users to set trace-level metadata dynamically
543533 during execution without having to pass it through function arguments.
544534
545- Args:
546- name: Optional trace name
547- tags: Optional list of tags for the trace
548- metadata: Optional dictionary of metadata to merge with existing metadata
549- thread_id: Optional thread identifier
550- user_id: Optional user identifier
551- input: Optional trace input data
552- output: Optional trace output data
553- feedback: Optional feedback data
554- test_case: Optional LLM test case data
535+ All provided key-value pairs will be stored in the trace metadata.
555536
556537 Example:
557- >>> import openlayer
538+ >>> from openlayer.lib import trace, update_current_trace
558539 >>>
559- >>> @openlayer. trace()
540+ >>> @trace()
560541 >>> def my_function():
561542 >>> # Update trace with user context
562- >>> openlayer. update_current_trace(
543+ >>> update_current_trace(
563544 >>> user_id="user123",
564- >>> metadata={"session_id": "sess456"}
545+ >>> session_id="sess456",
546+ >>> custom_field="any_value"
565547 >>> )
566548 >>> return "result"
567549 """
@@ -574,17 +556,7 @@ def update_current_trace(
574556 )
575557 return
576558
577- current_trace .update_metadata (
578- name = name ,
579- tags = tags ,
580- metadata = metadata ,
581- thread_id = thread_id ,
582- user_id = user_id ,
583- input = input ,
584- output = output ,
585- feedback = feedback ,
586- test_case = test_case ,
587- )
559+ current_trace .update_metadata (** kwargs )
588560 logger .debug ("Updated current trace metadata" )
589561
590562
@@ -934,25 +906,9 @@ def post_process_trace(
934906 }
935907
936908 # Include trace-level metadata if set
937- if trace_obj .name is not None :
938- trace_data ["trace_name" ] = trace_obj .name
939- if trace_obj .tags is not None :
940- trace_data ["tags" ] = trace_obj .tags
941909 if trace_obj .metadata is not None :
942910 # Merge trace-level metadata (higher precedence than root step metadata)
943911 trace_data .update (trace_obj .metadata )
944- if trace_obj .thread_id is not None :
945- trace_data ["thread_id" ] = trace_obj .thread_id
946- if trace_obj .user_id is not None :
947- trace_data ["user_id" ] = trace_obj .user_id
948- if trace_obj .input is not None :
949- trace_data ["trace_input" ] = trace_obj .input
950- if trace_obj .output is not None :
951- trace_data ["trace_output" ] = trace_obj .output
952- if trace_obj .feedback is not None :
953- trace_data ["feedback" ] = trace_obj .feedback
954- if trace_obj .test_case is not None :
955- trace_data ["test_case" ] = trace_obj .test_case
956912
957913 if root_step .ground_truth :
958914 trace_data ["groundTruth" ] = root_step .ground_truth
0 commit comments