Skip to content

Commit c89206e

Browse files
committed
fix(telemetry): removed double serialization for events
1 parent fad30fd commit c89206e

File tree

2 files changed

+15
-18
lines changed

2 files changed

+15
-18
lines changed

src/strands/telemetry/tracer.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from datetime import date, datetime, timezone
1111
from typing import Any, Dict, Mapping, Optional
1212

13+
1314
import opentelemetry.trace as trace_api
1415
from opentelemetry.instrumentation.threading import ThreadingInstrumentor
1516
from opentelemetry.trace import Span, StatusCode
@@ -307,7 +308,7 @@ def end_model_invoke_span(
307308
[
308309
{
309310
"role": message["role"],
310-
"parts": [{"type": "text", "content": serialize(message["content"])}],
311+
"parts": [{"type": "text", "content": message["content"]}],
311312
"finish_reason": str(stop_reason),
312313
}
313314
]
@@ -362,7 +363,7 @@ def start_tool_call_span(self, tool: ToolUse, parent_span: Optional[Span] = None
362363
"type": "tool_call",
363364
"name": tool["name"],
364365
"id": tool["toolUseId"],
365-
"arguments": [{"content": serialize(tool["input"])}],
366+
"arguments": [{"content": tool["input"]}],
366367
}
367368
],
368369
}
@@ -417,7 +418,7 @@ def end_tool_call_span(
417418
{
418419
"type": "tool_call_response",
419420
"id": tool_result.get("toolUseId", ""),
420-
"result": serialize(tool_result.get("content")),
421+
"result": tool_result.get("content"),
421422
}
422423
],
423424
}
@@ -504,7 +505,7 @@ def end_event_loop_cycle_span(
504505
[
505506
{
506507
"role": tool_result_message["role"],
507-
"parts": [{"type": "text", "content": serialize(tool_result_message["content"])}],
508+
"parts": [{"type": "text", "content": tool_result_message["content"]}],
508509
}
509510
]
510511
)
@@ -640,11 +641,7 @@ def start_multiagent_span(
640641
self._add_event(
641642
span,
642643
"gen_ai.client.inference.operation.details",
643-
{
644-
"gen_ai.input.messages": serialize(
645-
[{"role": "user", "parts": [{"type": "text", "content": content}]}]
646-
)
647-
},
644+
{"gen_ai.input.messages": serialize([{"role": "user", "parts": [{"type": "text", "content": task}]}])},
648645
)
649646
else:
650647
self._add_event(
@@ -722,7 +719,7 @@ def _add_event_messages(self, span: Span, messages: Messages) -> None:
722719
input_messages: list = []
723720
for message in messages:
724721
input_messages.append(
725-
{"role": message["role"], "parts": [{"type": "text", "content": serialize(message["content"])}]}
722+
{"role": message["role"], "parts": [{"type": "text", "content": message["content"]}]}
726723
)
727724
self._add_event(
728725
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)