Skip to content

fix(telemetry): add common gen_ai attributes to event loop cycle spans#1877

Closed
giulio-leone wants to merge 1 commit intostrands-agents:mainfrom
giulio-leone:fix/otel-event-loop-common-attrs
Closed

fix(telemetry): add common gen_ai attributes to event loop cycle spans#1877
giulio-leone wants to merge 1 commit intostrands-agents:mainfrom
giulio-leone:fix/otel-event-loop-common-attrs

Conversation

@giulio-leone
Copy link
Copy Markdown
Contributor

Summary

start_event_loop_cycle_span() was the only span start method that did not call _get_common_attributes(), causing event loop cycle spans to lack gen_ai.system / gen_ai.provider.name and gen_ai.operation.name attributes.

This is inconsistent with start_model_invoke_span, start_tool_call_span, start_agent_span, and start_multiagent_span, all of which include these common attributes. Downstream OTEL tooling (collectors, exporters, redaction processors) may rely on these attributes for filtering or policy decisions.

Changes

  • Added _get_common_attributes(operation_name="execute_event_loop_cycle") call in start_event_loop_cycle_span()
  • Updated existing tests to expect the new common attributes in both legacy and latest convention modes

Testing

All 74 tracer tests pass (including 5 event_loop_cycle-specific tests).

Closes #1876

@giulio-leone
Copy link
Copy Markdown
Contributor Author

Friendly ping — adds standard gen_ai.* OpenTelemetry semantic convention attributes to event loop cycle spans for better observability integration.

start_event_loop_cycle_span() was missing the _get_common_attributes()
call that all other span start methods (start_model_invoke_span,
start_tool_call_span, start_agent_span, start_multiagent_span) include.

This caused event_loop_cycle spans to carry gen_ai.input.messages
(via _add_event_messages) but lack gen_ai.system/gen_ai.provider.name
and gen_ai.operation.name, which downstream OTEL tooling (collectors,
exporters, redaction processors) may rely on for filtering/policy.

Closes #1876
@giulio-leone giulio-leone force-pushed the fix/otel-event-loop-common-attrs branch from 77a8f42 to 7eeab90 Compare March 23, 2026 06:01
@github-actions github-actions bot added size/xs and removed size/xs labels Mar 23, 2026
@giulio-leone
Copy link
Copy Markdown
Contributor Author

Refreshed onto main @ fd8168a (v1.32.0+2) — 2026-03-23

Root cause confirmed still live: start_event_loop_cycle_span still builds its attribute dict as a bare {"event_loop.cycle_id": …} literal, bypassing _get_common_attributes, so event loop cycle spans are missing the gen_ai.operation.name / gen_ai.system / gen_ai.provider.name attributes that every other span in the telemetry layer carries.

Fix: Call _get_common_attributes(operation_name="execute_event_loop_cycle") first, then set event_loop.cycle_id on the returned dict — identical pattern to start_agent_span, start_model_invoke_span, and execute_tool spans.

Runtime proof on rebased branch 7eeab90:

  • start_event_loop_cycle_span uses _get_common_attributes: True
  • event_loop.cycle_id still set: True
  • All 5 event-loop-cycle span tests: 5/5 PASSED
  • Full telemetry suite: 74/74 PASSED

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 9, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] execute_event_loop_cycle spans missing gen_ai.system/gen_ai.provider.name common attributes

1 participant