Skip to content

Commit ca6f599

Browse files
giulio-leonegiulio-leone
andauthored
fix(telemetry): add common gen_ai attributes to event loop cycle spans (#1973)
Co-authored-by: giulio-leone <giulio.leone@users.noreply.github.com>
1 parent 762fba2 commit ca6f599

2 files changed

Lines changed: 13 additions & 4 deletions

File tree

src/strands/telemetry/tracer.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -526,9 +526,10 @@ def start_event_loop_cycle_span(
526526
event_loop_cycle_id = str(invocation_state.get("event_loop_cycle_id"))
527527
parent_span = parent_span if parent_span else invocation_state.get("event_loop_parent_span")
528528

529-
attributes: dict[str, AttributeValue] = {
530-
"event_loop.cycle_id": event_loop_cycle_id,
531-
}
529+
attributes: dict[str, AttributeValue] = self._get_common_attributes(
530+
operation_name="execute_event_loop_cycle"
531+
)
532+
attributes["event_loop.cycle_id"] = event_loop_cycle_id
532533

533534
if custom_trace_attributes:
534535
attributes.update(custom_trace_attributes)

tests/strands/telemetry/test_tracer.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,8 @@ def test_start_event_loop_cycle_span(mock_tracer):
743743

744744
mock_span.set_attributes.assert_called_once_with(
745745
{
746+
"gen_ai.operation.name": "execute_event_loop_cycle",
747+
"gen_ai.system": "strands-agents",
746748
"event_loop.cycle_id": "cycle-123",
747749
"request_id": "req-456",
748750
"trace_level": "debug",
@@ -772,7 +774,13 @@ def test_start_event_loop_cycle_span_latest_conventions(mock_tracer, monkeypatch
772774
mock_tracer.start_span.assert_called_once()
773775
assert mock_tracer.start_span.call_args[1]["name"] == "execute_event_loop_cycle"
774776

775-
mock_span.set_attributes.assert_called_once_with({"event_loop.cycle_id": "cycle-123"})
777+
mock_span.set_attributes.assert_called_once_with(
778+
{
779+
"gen_ai.operation.name": "execute_event_loop_cycle",
780+
"gen_ai.provider.name": "strands-agents",
781+
"event_loop.cycle_id": "cycle-123",
782+
}
783+
)
776784
mock_span.add_event.assert_any_call(
777785
"gen_ai.client.inference.operation.details",
778786
attributes={

0 commit comments

Comments
 (0)