Skip to content

Commit 8a447a2

Browse files
authored
update annotation example (#10)
1. update annotation example
1 parent 70a3cb9 commit 8a447a2

2 files changed

Lines changed: 11 additions & 7 deletions

File tree

examples/trace/annotation/func_simple.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import os
66
import time
77

8-
from cozeloop import new_client, flush
8+
from cozeloop import new_client, flush, get_span_from_context
99
from cozeloop.decorator import observe
1010
from 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
)
5151
def 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

6868
if __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.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "cozeloop"
3-
version = "0.1.6"
3+
version = "0.1.7"
44
description = "coze loop sdk"
55
authors = ["JiangQi715 <jiangqi.rrt@bytedance.com>"]
66
license = "MIT"

0 commit comments

Comments
 (0)