Emitters¶
PeriodicEmitter¶
PeriodicEmitter ¶
PeriodicEmitter(collector: TelemetryCollector, interval_ms: int = 100, event_type: EventType = TELEMETRY_PERIODIC, on_event: Callable[[UDMEvent], None] | None = None)
Captures and emits telemetry events at regular intervals.
Uses a TelemetryCollector to gather data and emits UDM events at the configured interval.
Example
collector = MyRobotCollector(source_id="robot-001") emitter = PeriodicEmitter( collector=collector, interval_ms=100, # 10 Hz on_event=lambda e: agent.emit(e) ) await emitter.start()
Initialize the periodic emitter.
| PARAMETER | DESCRIPTION |
|---|---|
collector | Telemetry collector to use TYPE: |
interval_ms | Emission interval in milliseconds TYPE: |
event_type | Event type for emitted events TYPE: |
on_event | Callback for each emitted event TYPE: |
Source code in phytrace/emitters/periodic.py
Attributes¶
Functions¶
start async ¶
stop async ¶
Stop periodic emission.
set_interval ¶
get_event async ¶
get_event(timeout: float | None = None) -> UDMEvent | None
Get the next emitted event from the queue.
| PARAMETER | DESCRIPTION |
|---|---|
timeout | Maximum time to wait in seconds TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
UDMEvent | None | UDMEvent or None if timeout |
Source code in phytrace/emitters/periodic.py
EventEmitter¶
EventEmitter ¶
EventEmitter(source_id: str, source_type: SourceType, session_id: str | None = None, on_event: Callable[[UDMEvent], None] | None = None)
Emits specific event types when triggered.
Used for emitting events in response to specific occurrences like state transitions, safety violations, task events, etc.
Example
emitter = EventEmitter(source_id="robot-001", source_type=SourceType.AMR)
Emit state transition¶
event = emitter.emit_state_transition( from_state="idle", to_state="executing_task", reason="New task received" ) await agent.emit(event)
Initialize the event emitter.
| PARAMETER | DESCRIPTION |
|---|---|
source_id | Unique source identifier TYPE: |
source_type | Type of source TYPE: |
session_id | Optional session ID for grouping events TYPE: |
on_event | Optional callback for each emitted event TYPE: |
Source code in phytrace/emitters/event.py
Attributes¶
Functions¶
emit_state_transition ¶
emit_state_transition(from_state: str, to_state: str, reason: str | None = None) -> UDMEvent
Emit a state transition event.
| PARAMETER | DESCRIPTION |
|---|---|
from_state | Previous state TYPE: |
to_state | New state TYPE: |
reason | Optional reason for transition TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
UDMEvent | The emitted UDMEvent |
Source code in phytrace/emitters/event.py
emit_safety_violation ¶
emit_safety_violation(violation_id: str, rule_id: str, violation_type: str, severity: ViolationSeverity, details: dict[str, Any] | None = None) -> UDMEvent
Emit a safety violation event.
| PARAMETER | DESCRIPTION |
|---|---|
violation_id | Unique violation identifier TYPE: |
rule_id | Rule that was violated TYPE: |
violation_type | Type of violation TYPE: |
severity | Violation severity TYPE: |
details | Additional violation details TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
UDMEvent | The emitted UDMEvent |
Source code in phytrace/emitters/event.py
emit_task_event ¶
emit_task_event(task_id: str, event_type: TaskEventType, task_type: str | None = None, details: dict[str, Any] | None = None) -> UDMEvent
Emit a task lifecycle event.
| PARAMETER | DESCRIPTION |
|---|---|
task_id | Task identifier TYPE: |
event_type | Task event type (started, completed, failed, cancelled) TYPE: |
task_type | Optional task type TYPE: |
details | Additional task details TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
UDMEvent | The emitted UDMEvent |
Source code in phytrace/emitters/event.py
emit_navigation_event ¶
emit_navigation_event(event_type: NavigationEventType, goal_id: str | None = None, goal_x_m: float | None = None, goal_y_m: float | None = None, details: dict[str, Any] | None = None) -> UDMEvent
Emit a navigation event.
| PARAMETER | DESCRIPTION |
|---|---|
event_type | Navigation event type TYPE: |
goal_id | Goal identifier TYPE: |
goal_x_m | Goal X position TYPE: |
goal_y_m | Goal Y position TYPE: |
details | Additional details TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
UDMEvent | The emitted UDMEvent |
Source code in phytrace/emitters/event.py
emit_power_event ¶
emit_power_event(event_type: EventType, battery_soc_pct: float | None = None, is_charging: bool | None = None, charger_id: str | None = None) -> UDMEvent
Emit a power-related event.
| PARAMETER | DESCRIPTION |
|---|---|
event_type | Power event type TYPE: |
battery_soc_pct | Battery state of charge TYPE: |
is_charging | Whether currently charging TYPE: |
charger_id | Charger identifier TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
UDMEvent | The emitted UDMEvent |
Source code in phytrace/emitters/event.py
emit_custom_event ¶
emit_custom_event(event_type_name: str, data: dict[str, Any]) -> UDMEvent
Emit a custom event (custom.* namespace).
| PARAMETER | DESCRIPTION |
|---|---|
event_type_name | Custom event type name (without 'custom.' prefix) TYPE: |
data | Event data TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
UDMEvent | The emitted UDMEvent |