55import os
66import time
77
8- from cozeloop import new_client , flush
8+ from cozeloop import new_client , flush , get_span_from_context
99from cozeloop .decorator import observe
1010from cozeloop .logger import set_log_level
1111
@@ -45,13 +45,13 @@ def llm_call(self, input_data):
4545 # the default client will be used automatically.
4646 name = "root_span" , # The name of the Span. Defaults to the function name.
4747 span_type = "main_span" , # The span_type of the Span. Defaults to 'custom'.
48- tags = {"mode" : 'simple' , "node_id" : 6076665 }, # Set custom tag. The Priority is higher than the default tags.
49- baggage = {"product_id" : "123456654321" }, # Set custom baggage. baggage can cover tag of sample key, and will pass to child span automatically.
48+ tags = {"mode" : 'simple' , "node_id" : 6076665 }, # Set static custom tag. The Priority is higher than the default tags.
49+ baggage = {"product_id" : "123456654321" }, # Set static custom baggage. baggage can cover tag of sample key, and will pass to child span automatically.
5050)
5151def do_simple_demo ():
52- # Set the following environment variables first (Assuming you are using a PAT token.).
53- # os.environ["COZELOOP_WORKSPACE_ID"] = "your workspace id"
54- # os.environ["COZELOOP_API_TOKEN"] = "your token"
52+ # Dynamic set tag or baggage in runtime
53+ get_span_from_context (). set_baggage ({ "thread_id" : "my-thread- id"})
54+ get_span_from_context (). set_tags ({ "sale_id" : "my-sale-id" })
5555
5656 # 0. new client
5757 set_log_level (logging .INFO )
@@ -66,6 +66,10 @@ def do_simple_demo():
6666
6767
6868if __name__ == "__main__" :
69+ # Set the following environment variables first (Assuming you are using a PAT token.).
70+ # os.environ["COZELOOP_WORKSPACE_ID"] = "your workspace id"
71+ # os.environ["COZELOOP_API_TOKEN"] = "your token"
72+
6973 do_simple_demo ()
7074
7175 # flush all trace data before server exit.
0 commit comments