Skip to content

Commit 14ab89a

Browse files
feat(events): add span events and real-time streaming infrastructure (#21)
* feat(events): add span events and real-time streaming infrastructure Add new events.py module with: - EventType constants following OpenTelemetry GenAI conventions - StreamEvent dataclass for real-time event streaming - add_event() dual emission (span.add_event + streaming queue) - Convenience functions for agent, model, tool, and flow events - EventStream context manager for astream() consumers - Comprehensive test suite (34 tests) This enables real-time event streaming while persisting events to OTel backends (Jaeger, Zipkin, etc.) via span.add_event(). Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * fix(lint): format test_events.py with ruff --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 247ed56 commit 14ab89a

File tree

3 files changed

+816
-0
lines changed

3 files changed

+816
-0
lines changed

src/msgtrace/sdk/__init__.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,50 @@
55
"""
66

77
from msgtrace.sdk.attributes import MsgTraceAttributes
8+
from msgtrace.sdk.events import (
9+
EventStream,
10+
EventType,
11+
StreamEvent,
12+
add_agent_complete_event,
13+
add_agent_start_event,
14+
add_agent_step_event,
15+
add_event,
16+
add_flow_complete_event,
17+
add_flow_reasoning_event,
18+
add_flow_step_event,
19+
add_model_reasoning_event,
20+
add_model_request_event,
21+
add_model_response_chunk_event,
22+
add_model_response_event,
23+
add_tool_call_event,
24+
add_tool_error_event,
25+
add_tool_result_event,
26+
)
827
from msgtrace.sdk.spans import Spans
928
from msgtrace.sdk.tracer import tracer
1029

1130
__all__ = [
31+
# Core
1232
"tracer",
1333
"Spans",
1434
"MsgTraceAttributes",
35+
# Events
36+
"EventType",
37+
"StreamEvent",
38+
"EventStream",
39+
"add_event",
40+
# Convenience event functions
41+
"add_agent_start_event",
42+
"add_agent_complete_event",
43+
"add_agent_step_event",
44+
"add_model_request_event",
45+
"add_model_response_event",
46+
"add_model_response_chunk_event",
47+
"add_model_reasoning_event",
48+
"add_tool_call_event",
49+
"add_tool_result_event",
50+
"add_tool_error_event",
51+
"add_flow_step_event",
52+
"add_flow_reasoning_event",
53+
"add_flow_complete_event",
1554
]

0 commit comments

Comments
 (0)