Skip to main content

EventSink

Trait EventSink 

Source
pub trait EventSink:
    Send
    + Sync
    + 'static {
    // Required methods
    fn record_invocation(
        &self,
        flow_id: FlowId,
        component_id: ComponentId,
        start_ns: u64,
        end_ns: u64,
        status: InvocationStatus,
    );
    fn record_element_transfer(
        &self,
        flow_id: FlowId,
        stream_id: StreamId,
        element_sequence: u64,
        queue_depth_after: u32,
    );
    fn record_backpressure(
        &self,
        flow_id: FlowId,
        stream_id: StreamId,
        activated: bool,
        queue_depth: u32,
        timestamp_ns: u64,
    );
    fn record_copy(
        &self,
        flow_id: FlowId,
        resource_id: ResourceId,
        from_component: ComponentId,
        to_component: ComponentId,
        copy_bytes: u64,
        reason: CopyReason,
    );
    fn level(&self) -> ObservabilityLevel;

    // Provided methods
    fn record_flow_latency(&self, flow_id: FlowId, latency_ns: u64) { ... }
    fn record_element_span(
        &self,
        flow_id: FlowId,
        component_id: ComponentId,
        element_sequence: u64,
        start_ns: u64,
        end_ns: u64,
        status: InvocationStatus,
    ) { ... }
    fn flow_trace_context(&self, flow_id: FlowId) -> Option<TraceContext> { ... }
    fn on_flow_start(
        &self,
        flow_id: FlowId,
        component_ids: &[ComponentId],
        stream_ids: &[StreamId],
    ) { ... }
}
Expand description

The hot-path trait for recording observability events.

Implemented by the observability collector (torvyn-observability) and provided to the reactor, resource manager, and host lifecycle manager.

Per Doc 05, Section 9.1: all methods must be non-blocking and allocation-free on the hot path.

Use NoopEventSink for testing or when observability is disabled.

§Examples

use torvyn_types::{NoopEventSink, EventSink, ObservabilityLevel};

let sink = NoopEventSink;
assert_eq!(sink.level(), ObservabilityLevel::Off);

Required Methods§

Source

fn record_invocation( &self, flow_id: FlowId, component_id: ComponentId, start_ns: u64, end_ns: u64, status: InvocationStatus, )

Record a component invocation completion.

Called by the reactor after every component invocation.

§HOT PATH — must be non-blocking, allocation-free.
Source

fn record_element_transfer( &self, flow_id: FlowId, stream_id: StreamId, element_sequence: u64, queue_depth_after: u32, )

Record a stream element transfer between components.

Called by the reactor when an element moves through a stream queue.

§HOT PATH — must be non-blocking, allocation-free.
Source

fn record_backpressure( &self, flow_id: FlowId, stream_id: StreamId, activated: bool, queue_depth: u32, timestamp_ns: u64, )

Record a backpressure state change.

Called by the reactor when backpressure activates or deactivates.

§WARM PATH — called per backpressure event.
Source

fn record_copy( &self, flow_id: FlowId, resource_id: ResourceId, from_component: ComponentId, to_component: ComponentId, copy_bytes: u64, reason: CopyReason, )

Record a resource copy operation.

Called by the resource manager when data is copied across a boundary.

§HOT PATH — must be non-blocking, allocation-free.
Source

fn level(&self) -> ObservabilityLevel

Returns the current observability level.

Hot-path callers can skip expensive recording at lower levels.

§HOT PATH — checked per element to skip recording.

Provided Methods§

Source

fn record_flow_latency(&self, flow_id: FlowId, latency_ns: u64)

Record an element’s end-to-end latency through the flow.

Called by the reactor when a sink consumes an element, measured from the element’s pipeline-entry timestamp (set at the source) to its consumption at the sink. Unlike per-component processing time, this is the full journey — queueing plus every stage. The default is a no-op.

§HOT PATH — called once per element delivered to a sink.
Source

fn record_element_span( &self, flow_id: FlowId, component_id: ComponentId, element_sequence: u64, start_ns: u64, end_ns: u64, status: InvocationStatus, )

Record one component invocation as a per-element span.

Called by the reactor immediately after record_invocation, with the sequence number of the element the invocation handled.

This is the per-element counterpart to record_invocation: where that call folds the invocation into aggregate counters and histograms, this one retains the individual event so a trace can reconstruct one element’s path through the pipeline. Sinks are expected to drop these below ObservabilityLevel::Diagnostic — the level check is the sink’s responsibility, and at Production level this must cost no more than the atomic load it takes to decide to do nothing.

start_ns and end_ns are nanoseconds since the Unix epoch, so a span is directly exportable without a second clock reading.

The default is a no-op: sinks that do not retain per-element detail (such as NoopEventSink) need not implement it.

§HOT PATH — called once per invocation; must be non-blocking.
Source

fn flow_trace_context(&self, flow_id: FlowId) -> Option<TraceContext>

The trace context assigned to a flow, if this sink is tracing it.

Called once per flow, after on_flow_start, so the host can propagate the flow’s W3C trace and span identifiers into each component’s store — which is what lets a guest calling flow-context.trace-id() correlate its own work with the host’s trace.

Returns None when the sink is not tracing (the default), when the flow is unknown, or when the flow was not selected by head sampling.

§COLD PATH — called once per flow.
Source

fn on_flow_start( &self, flow_id: FlowId, component_ids: &[ComponentId], stream_ids: &[StreamId], )

Pre-register a flow’s per-flow metric state before its driver starts.

Called by the reactor exactly once per flow — after the flow id is assigned and before the flow driver is spawned — so that no later record_* call can observe a flow whose metrics have not yet been allocated. component_ids and stream_ids enumerate the flow’s stages and stream connections in the same order the reactor records them, letting the sink allocate matching metric slots up front.

The default is a no-op: sinks that hold no per-flow state (such as NoopEventSink) need not implement it.

§COLD PATH — called once per flow, off the element hot path.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<E: EventSink> EventSink for Arc<E>

Forwarding implementation so any Arc-shared sink satisfies the reactor’s E: EventSink + Clone + 'static bound without the sink itself being Clone: the Arc provides the cheap clone (one shared sink, reference counted), and every call forwards to the single instance behind it.

This lets the host install a shared ObservabilityCollector (which owns Arc-backed registries and a background event recorder, and so is not Clone) by wrapping it in an Arc.

Source§

fn record_invocation( &self, flow_id: FlowId, component_id: ComponentId, start_ns: u64, end_ns: u64, status: InvocationStatus, )

Source§

fn record_element_transfer( &self, flow_id: FlowId, stream_id: StreamId, element_sequence: u64, queue_depth_after: u32, )

Source§

fn record_backpressure( &self, flow_id: FlowId, stream_id: StreamId, activated: bool, queue_depth: u32, timestamp_ns: u64, )

Source§

fn record_copy( &self, flow_id: FlowId, resource_id: ResourceId, from_component: ComponentId, to_component: ComponentId, copy_bytes: u64, reason: CopyReason, )

Source§

fn record_flow_latency(&self, flow_id: FlowId, latency_ns: u64)

Source§

fn record_element_span( &self, flow_id: FlowId, component_id: ComponentId, element_sequence: u64, start_ns: u64, end_ns: u64, status: InvocationStatus, )

Source§

fn flow_trace_context(&self, flow_id: FlowId) -> Option<TraceContext>

Source§

fn level(&self) -> ObservabilityLevel

Source§

fn on_flow_start( &self, flow_id: FlowId, component_ids: &[ComponentId], stream_ids: &[StreamId], )

Implementors§