Skip to content

Commit 776fd93

Browse files
authored
fix(telemetry): removed double serialization for events (#977)
1 parent bab1270 commit 776fd93

File tree

2 files changed

+14
-18
lines changed

2 files changed

+14
-18
lines changed

src/strands/telemetry/tracer.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ def end_model_invoke_span(
307307
[
308308
{
309309
"role": message["role"],
310-
"parts": [{"type": "text", "content": serialize(message["content"])}],
310+
"parts": [{"type": "text", "content": message["content"]}],
311311
"finish_reason": str(stop_reason),
312312
}
313313
]
@@ -362,7 +362,7 @@ def start_tool_call_span(self, tool: ToolUse, parent_span: Optional[Span] = None
362362
"type": "tool_call",
363363
"name": tool["name"],
364364
"id": tool["toolUseId"],
365-
"arguments": [{"content": serialize(tool["input"])}],
365+
"arguments": [{"content": tool["input"]}],
366366
}
367367
],
368368
}
@@ -417,7 +417,7 @@ def end_tool_call_span(
417417
{
418418
"type": "tool_call_response",
419419
"id": tool_result.get("toolUseId", ""),
420-
"result": serialize(tool_result.get("content")),
420+
"result": tool_result.get("content"),
421421
}
422422
],
423423
}
@@ -504,7 +504,7 @@ def end_event_loop_cycle_span(
504504
[
505505
{
506506
"role": tool_result_message["role"],
507-
"parts": [{"type": "text", "content": serialize(tool_result_message["content"])}],
507+
"parts": [{"type": "text", "content": tool_result_message["content"]}],
508508
}
509509
]
510510
)
@@ -640,11 +640,7 @@ def start_multiagent_span(
640640
self._add_event(
641641
span,
642642
"gen_ai.client.inference.operation.details",
643-
{
644-
"gen_ai.input.messages": serialize(
645-
[{"role": "user", "parts": [{"type": "text", "content": content}]}]
646-
)
647-
},
643+
{"gen_ai.input.messages": serialize([{"role": "user", "parts": [{"type": "text", "content": task}]}])},
648644
)
649645
else:
650646
self._add_event(
@@ -722,7 +718,7 @@ def _add_event_messages(self, span: Span, messages: Messages) -> None:
722718
input_messages: list = []
723719
for message in messages:
724720
input_messages.append(
725-
{"role": message["role"], "parts": [{"type": "text", "content": serialize(message["content"])}]}
721+
{"role": message["role"], "parts": [{"type": "text", "content": message["content"]}]}
726722
)
727723
self._add_event(
728724
span, "gen_ai.client.inference.operation.details", {"gen_ai.input.messages": serialize(input_messages)}

tests/strands/telemetry/test_tracer.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ def test_start_model_invoke_span_latest_conventions(mock_tracer):
191191
[
192192
{
193193
"role": messages[0]["role"],
194-
"parts": [{"type": "text", "content": serialize(messages[0]["content"])}],
194+
"parts": [{"type": "text", "content": messages[0]["content"]}],
195195
}
196196
]
197197
)
@@ -249,7 +249,7 @@ def test_end_model_invoke_span_latest_conventions(mock_span):
249249
[
250250
{
251251
"role": "assistant",
252-
"parts": [{"type": "text", "content": serialize(message["content"])}],
252+
"parts": [{"type": "text", "content": message["content"]}],
253253
"finish_reason": "end_turn",
254254
}
255255
]
@@ -318,7 +318,7 @@ def test_start_tool_call_span_latest_conventions(mock_tracer):
318318
"type": "tool_call",
319319
"name": tool["name"],
320320
"id": tool["toolUseId"],
321-
"arguments": [{"content": serialize(tool["input"])}],
321+
"arguments": [{"content": tool["input"]}],
322322
}
323323
],
324324
}
@@ -398,7 +398,7 @@ def test_start_swarm_span_with_contentblock_task_latest_conventions(mock_tracer)
398398
"gen_ai.client.inference.operation.details",
399399
attributes={
400400
"gen_ai.input.messages": serialize(
401-
[{"role": "user", "parts": [{"type": "text", "content": '[{"text": "Original Task: foo bar"}]'}]}]
401+
[{"role": "user", "parts": [{"type": "text", "content": [{"text": "Original Task: foo bar"}]}]}]
402402
)
403403
},
404404
)
@@ -502,7 +502,7 @@ def test_end_tool_call_span_latest_conventions(mock_span):
502502
{
503503
"type": "tool_call_response",
504504
"id": tool_result.get("toolUseId", ""),
505-
"result": serialize(tool_result.get("content")),
505+
"result": tool_result.get("content"),
506506
}
507507
],
508508
}
@@ -559,7 +559,7 @@ def test_start_event_loop_cycle_span_latest_conventions(mock_tracer):
559559
"gen_ai.client.inference.operation.details",
560560
attributes={
561561
"gen_ai.input.messages": serialize(
562-
[{"role": "user", "parts": [{"type": "text", "content": serialize(messages[0]["content"])}]}]
562+
[{"role": "user", "parts": [{"type": "text", "content": messages[0]["content"]}]}]
563563
)
564564
},
565565
)
@@ -601,7 +601,7 @@ def test_end_event_loop_cycle_span_latest_conventions(mock_span):
601601
[
602602
{
603603
"role": "assistant",
604-
"parts": [{"type": "text", "content": serialize(tool_result_message["content"])}],
604+
"parts": [{"type": "text", "content": tool_result_message["content"]}],
605605
}
606606
]
607607
)
@@ -676,7 +676,7 @@ def test_start_agent_span_latest_conventions(mock_tracer):
676676
"gen_ai.client.inference.operation.details",
677677
attributes={
678678
"gen_ai.input.messages": serialize(
679-
[{"role": "user", "parts": [{"type": "text", "content": '[{"text": "test prompt"}]'}]}]
679+
[{"role": "user", "parts": [{"type": "text", "content": [{"text": "test prompt"}]}]}]
680680
)
681681
},
682682
)

0 commit comments

Comments
 (0)