use crate::dial9::{io_error_kind_code, io_error_raw_os_code};
use dial9_tokio_telemetry::telemetry::{TelemetryHandle, clock_monotonic_ns, record_event};
use dial9_trace_format::TraceEvent;
#[derive(TraceEvent)]
pub struct IoForwardBridgeOpened {
#[traceevent(timestamp)]
pub timestamp_ns: u64,
pub idle_timeout_ms: u64,
pub graceful: bool,
}
#[derive(TraceEvent)]
pub struct IoForwardBridgeClosed {
#[traceevent(timestamp)]
pub timestamp_ns: u64,
pub reason: super::BridgeCloseReason,
pub age_ms: u64,
pub bytes_l_to_r: u64,
pub bytes_r_to_l: u64,
pub error_kind: Option<u32>,
pub error_raw_os: Option<i64>,
}
#[inline]
pub(super) fn record_bridge_opened(idle_timeout_ms: u64, graceful: bool) {
let handle = TelemetryHandle::current();
if handle.is_enabled() {
record_event(
IoForwardBridgeOpened {
timestamp_ns: clock_monotonic_ns(),
idle_timeout_ms,
graceful,
},
&handle,
);
}
}
#[inline]
pub(super) fn record_bridge_closed(
reason: super::BridgeCloseReason,
age_ms: u64,
bytes_l_to_r: u64,
bytes_r_to_l: u64,
error: Option<&std::io::Error>,
) {
let handle = TelemetryHandle::current();
if handle.is_enabled() {
record_event(
IoForwardBridgeClosed {
timestamp_ns: clock_monotonic_ns(),
reason,
age_ms,
bytes_l_to_r,
bytes_r_to_l,
error_kind: error.map(|e| io_error_kind_code(e.kind())),
error_raw_os: error.and_then(io_error_raw_os_code),
},
&handle,
);
}
}