Skip to content

Commit a4ee397

Browse files
authored
add tags_bool
2 parents 4854fc1 + d380b64 commit a4ee397

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

cozeloop/internal/trace/exporter.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ class UploadSpan(BaseModel):
109109
tags_string: Dict[str, str]
110110
tags_long: Dict[str, int]
111111
tags_double: Dict[str, float]
112+
tags_bool: Dict[str, bool]
112113

113114

114115
class UploadFile(BaseModel):
@@ -131,8 +132,8 @@ def transfer_to_upload_span_and_file(spans: List['Span']) -> (List[UploadSpan],
131132
span_upload_files, put_content_map = parse_input_output(span)
132133
object_storage_byte = transfer_object_storage(span_upload_files)
133134

134-
tag_str_m, tag_long_m, tag_double_m = parse_tag(span.tag_map)
135-
system_tag_str_m, system_tag_long_m, system_tag_double_m = parse_tag(span.system_tag_map)
135+
tag_str_m, tag_long_m, tag_double_m, tag_bool_m = parse_tag(span.tag_map, False)
136+
system_tag_str_m, system_tag_long_m, system_tag_double_m, _ = parse_tag(span.system_tag_map, True)
136137

137138
res_span.append(UploadSpan(
138139
started_at_micros=int(span.start_time.timestamp() * 1_000_000),
@@ -152,35 +153,42 @@ def transfer_to_upload_span_and_file(spans: List['Span']) -> (List[UploadSpan],
152153
system_tags_double=system_tag_double_m,
153154
tags_string=tag_str_m,
154155
tags_long=tag_long_m,
155-
tags_double=tag_double_m
156+
tags_double=tag_double_m,
157+
tags_bool=tag_bool_m,
156158
))
157159
res_file.extend(span_upload_files)
158160

159161
return res_span, res_file
160162

161163

162-
def parse_tag(span_tag: Dict[str, Any]) -> (Dict[str, str], Dict[str, int], Dict[str, float]):
164+
def parse_tag(span_tag: Dict[str, Any], is_system_tag: bool) -> (Dict[str, str], Dict[str, int], Dict[str, float], Dict[str, bool]):
163165
if not span_tag:
164166
return {}, {}, {}
165167

166168
v_str_map = {}
167169
v_long_map = {}
168170
v_double_map = {}
171+
v_bool_map = {}
169172

170173
for key, value in span_tag.items():
171174
if key in (INPUT, OUTPUT):
172175
continue
173176

174177
if isinstance(value, str):
175178
v_str_map[key] = value
176-
elif isinstance(value, (int, bool)):
179+
elif isinstance(value, bool):
180+
if is_system_tag:
181+
v_str_map[key] = str(value)
182+
else:
183+
v_bool_map[key] = bool(value)
184+
elif isinstance(value, int):
177185
v_long_map[key] = int(value)
178186
elif isinstance(value, float):
179187
v_double_map[key] = float(value)
180188
else:
181189
v_str_map[key] = str(value)
182190

183-
return v_str_map, v_long_map, v_double_map
191+
return v_str_map, v_long_map, v_double_map, v_bool_map
184192

185193

186194

examples/trace/simple.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ def do_simple_demo():
7777
"mode": "simple",
7878
"node_id": 6076665,
7979
"node_process_duration": 228.6,
80+
"is_first_node": True,
8081
})
8182

8283
# set custom baggage, baggage can cover tag of sample key, and baggage will pass to child span automatically.

0 commit comments

Comments
 (0)