@@ -526,42 +526,24 @@ def log_context(context: List[str]) -> None:
526
526
logger .warning ("No current step found to log context." )
527
527
528
528
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 :
540
530
"""Updates the current trace metadata with the provided values.
541
531
542
532
This function allows users to set trace-level metadata dynamically
543
533
during execution without having to pass it through function arguments.
544
534
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.
555
536
556
537
Example:
557
- >>> import openlayer
538
+ >>> from openlayer.lib import trace, update_current_trace
558
539
>>>
559
- >>> @openlayer. trace()
540
+ >>> @trace()
560
541
>>> def my_function():
561
542
>>> # Update trace with user context
562
- >>> openlayer. update_current_trace(
543
+ >>> update_current_trace(
563
544
>>> user_id="user123",
564
- >>> metadata={"session_id": "sess456"}
545
+ >>> session_id="sess456",
546
+ >>> custom_field="any_value"
565
547
>>> )
566
548
>>> return "result"
567
549
"""
@@ -574,17 +556,7 @@ def update_current_trace(
574
556
)
575
557
return
576
558
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 )
588
560
logger .debug ("Updated current trace metadata" )
589
561
590
562
@@ -927,25 +899,9 @@ def post_process_trace(
927
899
}
928
900
929
901
# Include trace-level metadata if set
930
- if trace_obj .name is not None :
931
- trace_data ["trace_name" ] = trace_obj .name
932
- if trace_obj .tags is not None :
933
- trace_data ["tags" ] = trace_obj .tags
934
902
if trace_obj .metadata is not None :
935
903
# Merge trace-level metadata (higher precedence than root step metadata)
936
904
trace_data .update (trace_obj .metadata )
937
- if trace_obj .thread_id is not None :
938
- trace_data ["thread_id" ] = trace_obj .thread_id
939
- if trace_obj .user_id is not None :
940
- trace_data ["user_id" ] = trace_obj .user_id
941
- if trace_obj .input is not None :
942
- trace_data ["trace_input" ] = trace_obj .input
943
- if trace_obj .output is not None :
944
- trace_data ["trace_output" ] = trace_obj .output
945
- if trace_obj .feedback is not None :
946
- trace_data ["feedback" ] = trace_obj .feedback
947
- if trace_obj .test_case is not None :
948
- trace_data ["test_case" ] = trace_obj .test_case
949
905
950
906
if root_step .ground_truth :
951
907
trace_data ["groundTruth" ] = root_step .ground_truth
0 commit comments