Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
Use the `telemetry-enable` feature flag on `veecle-os` to control telemetry behavior.
* **breaking** Removed `Span::root` method and `root_span!` macro; root spans should use `Span::new` and `span!` instead.
* **breaking** Replaced `SpanContext::from_span` with `Span::context` method.
* **breaking** Telemetry execution id is replaced by separate thread and process ids to uniquely identify thread/task combinations.
* Added `ThreadAbstraction` trait to OSAL for querying current thread id.
* Updated MSRV to 1.90.
* Fixed `veecle_os::telemetry::instrument` macro to automatically resolve correct crate paths for the facade.
Expand Down
2 changes: 1 addition & 1 deletion veecle-ipc/src/connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl Connector {
/// let connector = veecle_ipc::Connector::connect().await;
///
/// veecle_os::telemetry::collector::set_exporter(
/// veecle_os::telemetry::protocol::ExecutionId::random(&mut rand::rng()),
/// veecle_os::telemetry::collector::ProcessId::random(&mut rand::rng()),
/// Box::leak(Box::new(connector.exporter())),
/// )?;
/// # Ok::<(), Box<dyn std::error::Error>>(())
Expand Down
12 changes: 8 additions & 4 deletions veecle-ipc/src/telemetry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,26 @@ impl Export for Exporter {
#[cfg(test)]
#[cfg_attr(coverage_nightly, coverage(off))]
mod tests {
use core::num::NonZeroU64;
use tokio::sync::mpsc;
use veecle_telemetry::collector::Export;
use veecle_telemetry::protocol::{
ExecutionId, InstanceMessage, LogMessage, Severity, TelemetryMessage,
InstanceMessage, LogMessage, ProcessId, Severity, TelemetryMessage, ThreadId,
};
use veecle_telemetry::{SpanId, TraceId};

use super::Exporter;

const THREAD_ID: ThreadId =
ThreadId::from_raw(ProcessId::from_raw(123), NonZeroU64::new(456).unwrap());

#[tokio::test]
async fn test_export_telemetry_message() {
let (sender, mut receiver) = mpsc::channel(1);
let exporter = Exporter::new(sender);

let test_message = InstanceMessage {
execution: ExecutionId::from_raw(123),
thread: THREAD_ID,
message: TelemetryMessage::Log(LogMessage {
time_unix_nano: 1000000000,
severity: Severity::Info,
Expand All @@ -62,7 +66,7 @@ mod tests {
let received = receiver.recv().await.expect("should receive message");
match received {
veecle_ipc_protocol::Message::Telemetry(message) => {
assert_eq!(*message.execution, 123);
assert_eq!(message.thread, THREAD_ID);
match message.message {
TelemetryMessage::Log(message) => {
assert_eq!(message.time_unix_nano, 1000000000);
Expand All @@ -86,7 +90,7 @@ mod tests {
drop(receiver);

let test_message = InstanceMessage {
execution: ExecutionId::from_raw(456),
thread: THREAD_ID,
message: TelemetryMessage::Log(LogMessage {
time_unix_nano: 2000000000,
severity: Severity::Error,
Expand Down
2 changes: 1 addition & 1 deletion veecle-os-examples/embassy-std/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ async fn run() {
#[embassy_executor::main]
async fn main(spawner: Spawner) {
veecle_os::telemetry::collector::set_exporter(
veecle_os::telemetry::protocol::ExecutionId::random(&mut rand::rng()),
veecle_os::telemetry::collector::ProcessId::random(&mut rand::rng()),
&veecle_os::telemetry::collector::ConsoleJsonExporter,
)
.unwrap();
Expand Down
2 changes: 1 addition & 1 deletion veecle-os-examples/freertos-linux/src/bin/alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ async fn alloc_stat_actor() -> Infallible {

pub fn main() -> ! {
veecle_os::telemetry::collector::set_exporter(
veecle_os::telemetry::protocol::ExecutionId::random(&mut rand::rng()),
veecle_os::telemetry::collector::ProcessId::random(&mut rand::rng()),
&veecle_os::telemetry::collector::ConsoleJsonExporter,
)
.unwrap();
Expand Down
2 changes: 1 addition & 1 deletion veecle-os-examples/freertos-linux/src/bin/queues.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ async fn queue_actor(

fn main() {
veecle_os::telemetry::collector::set_exporter(
veecle_os::telemetry::protocol::ExecutionId::random(&mut rand::rng()),
veecle_os::telemetry::collector::ProcessId::random(&mut rand::rng()),
&veecle_os::telemetry::collector::ConsoleJsonExporter,
)
.unwrap();
Expand Down
2 changes: 1 addition & 1 deletion veecle-os-examples/freertos-linux/src/bin/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ static GLOBAL: FreeRtosAllocator = unsafe { FreeRtosAllocator::new() };
/// An example of using the time abstraction within a FreeRTOS task.
pub fn main() -> ! {
veecle_os::telemetry::collector::set_exporter(
veecle_os::telemetry::protocol::ExecutionId::random(&mut rand::rng()),
veecle_os::telemetry::collector::ProcessId::random(&mut rand::rng()),
&veecle_os::telemetry::collector::ConsoleJsonExporter,
)
.unwrap();
Expand Down
2 changes: 1 addition & 1 deletion veecle-os-examples/orchestrator-ipc/src/bin/ping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ async fn main() {
let connector = veecle_ipc::Connector::connect().await;

veecle_os::telemetry::collector::set_exporter(
veecle_os::telemetry::protocol::ExecutionId::random(&mut rand::rng()),
veecle_os::telemetry::collector::ProcessId::random(&mut rand::rng()),
Box::leak(Box::new(connector.exporter())),
)
.unwrap();
Expand Down
2 changes: 1 addition & 1 deletion veecle-os-examples/orchestrator-ipc/src/bin/pong.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ async fn main() {
let connector = veecle_ipc::Connector::connect().await;

veecle_os::telemetry::collector::set_exporter(
veecle_os::telemetry::protocol::ExecutionId::random(&mut rand::rng()),
veecle_os::telemetry::collector::ProcessId::random(&mut rand::rng()),
Box::leak(Box::new(connector.exporter())),
)
.unwrap();
Expand Down
2 changes: 1 addition & 1 deletion veecle-os-examples/orchestrator-ipc/src/bin/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ async fn main() {
let connector = veecle_ipc::Connector::connect().await;

veecle_os::telemetry::collector::set_exporter(
veecle_os::telemetry::protocol::ExecutionId::random(&mut rand::rng()),
veecle_os::telemetry::collector::ProcessId::random(&mut rand::rng()),
Box::leak(Box::new(connector.exporter())),
)
.unwrap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ async fn main() {
let connector = veecle_ipc::Connector::connect().await;

veecle_os::telemetry::collector::set_exporter(
veecle_os::telemetry::protocol::ExecutionId::random(&mut rand::rng()),
veecle_os::telemetry::protocol::ProcessId::random(&mut rand::rng()),
Box::leak(Box::new(connector.exporter())),
)
.unwrap();
Expand Down
2 changes: 1 addition & 1 deletion veecle-osal-std-macros/src/main_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ fn impl_main(
quote!(
// Initialize `veecle-telemetry` with a random execution ID and console JSON exporter.
#veecle_telemetry_path::collector::set_exporter(
#veecle_telemetry_path::protocol::ExecutionId::random(
#veecle_telemetry_path::collector::ProcessId::random(
&mut #veecle_osal_std_path::reexports::rand::rng(),
),
&#veecle_telemetry_path::collector::ConsoleJsonExporter
Expand Down
7 changes: 3 additions & 4 deletions veecle-telemetry-ui/examples/continuous.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ use std::convert::Infallible;

use veecle_os_runtime::{Reader, Writer};
use veecle_osal_std::time::{Duration, Time, TimeAbstraction};
use veecle_telemetry::collector::ConsoleJsonExporter;
use veecle_telemetry::protocol::ExecutionId;
use veecle_telemetry::collector::{ConsoleJsonExporter, ProcessId};

use crate::common::{ConcreteTraceActor, Ping, Pong, PongActor, ping_loop};

Expand All @@ -34,8 +33,8 @@ async fn ping_actor(

#[veecle_osal_std::main]
async fn main() {
let execution_id = ExecutionId::random(&mut rand::rng());
veecle_telemetry::collector::set_exporter(execution_id, &ConsoleJsonExporter)
let process_id = ProcessId::random(&mut rand::rng());
veecle_telemetry::collector::set_exporter(process_id, &ConsoleJsonExporter)
.expect("exporter was not set yet");

veecle_os_runtime::execute! {
Expand Down
7 changes: 3 additions & 4 deletions veecle-telemetry-ui/examples/remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
use std::convert::Infallible;

use veecle_os_runtime::{Reader, Writer};
use veecle_telemetry::collector::ConsoleJsonExporter;
use veecle_telemetry::protocol::ExecutionId;
use veecle_telemetry::collector::{ConsoleJsonExporter, ProcessId};

use crate::common::{ConcreteTraceActor, Ping, Pong, PongActor, ping_loop};

Expand All @@ -34,8 +33,8 @@ pub async fn ping_actor(mut ping: Writer<'_, Ping>, mut pong: Reader<'_, Pong>)

#[veecle_osal_std::main]
async fn main() {
let execution_id = ExecutionId::random(&mut rand::rng());
veecle_telemetry::collector::set_exporter(execution_id, &ConsoleJsonExporter)
let process_id = ProcessId::random(&mut rand::rng());
veecle_telemetry::collector::set_exporter(process_id, &ConsoleJsonExporter)
.expect("exporter was not set yet");

veecle_os_runtime::execute! {
Expand Down
4 changes: 2 additions & 2 deletions veecle-telemetry-ui/src/store/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ impl Store {
self.ensure_program_span();

let InstanceMessage {
// TODO(DEV-605): support filtering by execution.
execution: _,
// TODO(DEV-605): support filtering by thread.
thread: _,
message,
} = instance_message;

Expand Down
7 changes: 3 additions & 4 deletions veecle-telemetry/examples/async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@

use std::time::Duration;

use veecle_telemetry::collector::ConsoleJsonExporter;
use veecle_telemetry::protocol::ExecutionId;
use veecle_telemetry::collector::{ConsoleJsonExporter, ProcessId};
use veecle_telemetry::{CurrentSpan, Span};

#[tokio::main]
async fn main() {
let execution_id = ExecutionId::random(&mut rand::rng());
veecle_telemetry::collector::set_exporter(execution_id, &ConsoleJsonExporter)
let process_id = ProcessId::random(&mut rand::rng());
veecle_telemetry::collector::set_exporter(process_id, &ConsoleJsonExporter)
.expect("exporter was not set yet");

let _span = Span::new("main", &[]).entered();
Expand Down
7 changes: 3 additions & 4 deletions veecle-telemetry/examples/basic.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#![expect(missing_docs, reason = "example")]

use veecle_telemetry::Span;
use veecle_telemetry::collector::ConsoleJsonExporter;
use veecle_telemetry::protocol::ExecutionId;
use veecle_telemetry::collector::{ConsoleJsonExporter, ProcessId};

fn main() {
let execution_id = ExecutionId::random(&mut rand::rng());
veecle_telemetry::collector::set_exporter(execution_id, &ConsoleJsonExporter)
let process_id = ProcessId::random(&mut rand::rng());
veecle_telemetry::collector::set_exporter(process_id, &ConsoleJsonExporter)
.expect("exporter was not set yet");

let _span = Span::new("main", &[]).entered();
Expand Down
7 changes: 3 additions & 4 deletions veecle-telemetry/src/collector/json_exporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ use crate::protocol::InstanceMessage;
/// # Examples
///
/// ```rust
/// use veecle_telemetry::collector::{ConsoleJsonExporter, set_exporter};
/// use veecle_telemetry::protocol::ExecutionId;
/// use veecle_telemetry::collector::{ConsoleJsonExporter, set_exporter, ProcessId};
///
/// let execution_id = ExecutionId::random(&mut rand::rng());
/// set_exporter(execution_id, &ConsoleJsonExporter).unwrap();
/// let process_id = ProcessId::random(&mut rand::rng());
/// set_exporter(process_id, &ConsoleJsonExporter).unwrap();
/// ```
#[derive(Debug)]
pub struct ConsoleJsonExporter;
Expand Down
40 changes: 21 additions & 19 deletions veecle-telemetry/src/collector/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,14 @@ pub use json_exporter::ConsoleJsonExporter;
pub use test_exporter::TestExporter;

use crate::TraceId;
#[cfg(feature = "enable")]
use crate::protocol::ExecutionId;
use crate::protocol::InstanceMessage;
#[cfg(feature = "enable")]
pub use crate::protocol::ProcessId;
#[cfg(feature = "enable")]
use crate::protocol::{
LogMessage, SpanAddEventMessage, SpanAddLinkMessage, SpanCloseMessage, SpanCreateMessage,
SpanEnterMessage, SpanExitMessage, SpanSetAttributeMessage, TelemetryMessage, TracingMessage,
SpanEnterMessage, SpanExitMessage, SpanSetAttributeMessage, TelemetryMessage, ThreadId,
TracingMessage,
};

/// Trait for exporting telemetry data to external systems.
Expand Down Expand Up @@ -94,7 +95,7 @@ pub struct Collector {
#[cfg(feature = "enable")]
#[derive(Debug)]
struct CollectorInner {
execution_id: ExecutionId,
process_id: ProcessId,

exporter: &'static (dyn Export + Sync),

Expand All @@ -116,7 +117,7 @@ impl Export for NopExporter {
#[cfg(feature = "enable")]
static mut GLOBAL_COLLECTOR: Collector = Collector {
inner: CollectorInner {
execution_id: ExecutionId::from_raw(0),
process_id: ProcessId::from_raw(0),
exporter: &NO_EXPORTER,

trace_id_prefix: 0,
Expand All @@ -126,7 +127,7 @@ static mut GLOBAL_COLLECTOR: Collector = Collector {
static NO_COLLECTOR: Collector = Collector {
#[cfg(feature = "enable")]
inner: CollectorInner {
execution_id: ExecutionId::from_raw(0),
process_id: ProcessId::from_raw(0),
exporter: &NO_EXPORTER,

trace_id_prefix: 0,
Expand All @@ -150,13 +151,13 @@ const INITIALIZING: usize = 1;
#[cfg(feature = "enable")]
const INITIALIZED: usize = 2;

/// Initializes the collector with the given Exporter and [`ExecutionId`].
/// Initializes the collector with the given Exporter and [`ProcessId`].
///
/// An [`ExecutionId`] should never be re-used as it's used to collect metadata about the execution and to generate
/// A [`ProcessId`] should never be re-used as it's used to collect metadata about the execution and to generate
/// [`TraceId`]s which need to be globally unique.
#[cfg(feature = "enable")]
pub fn set_exporter(
execution_id: ExecutionId,
process_id: ProcessId,
exporter: &'static (dyn Export + Sync),
) -> Result<(), SetExporterError> {
if GLOBAL_INIT
Expand All @@ -169,7 +170,7 @@ pub fn set_exporter(
.is_ok()
{
// SAFETY: this is guarded by the atomic
unsafe { GLOBAL_COLLECTOR = Collector::new(execution_id, exporter) }
unsafe { GLOBAL_COLLECTOR = Collector::new(process_id, exporter) }
GLOBAL_INIT.store(INITIALIZED, Ordering::Release);

Ok(())
Expand Down Expand Up @@ -227,14 +228,13 @@ impl error::Error for SetExporterError {}

impl Collector {
#[cfg(feature = "enable")]
fn new(execution_id: ExecutionId, exporter: &'static (dyn Export + Sync)) -> Self {
let execution_id_raw = *execution_id;
let trace_id_prefix = (execution_id_raw >> 64) as u64;
let initial_counter_value = execution_id_raw as u64;
fn new(process_id: ProcessId, exporter: &'static (dyn Export + Sync)) -> Self {
let trace_id_prefix = (process_id.to_raw() >> 64) as u64;
let initial_counter_value = process_id.to_raw() as u64;

Self {
inner: CollectorInner {
execution_id,
process_id,
exporter,
trace_id_prefix,
trace_id_counter: AtomicU64::new(initial_counter_value),
Expand Down Expand Up @@ -271,17 +271,19 @@ impl Collector {
/// # Examples
///
/// ```rust
/// use core::num::NonZeroU64;
/// use veecle_telemetry::collector::get_collector;
/// use veecle_telemetry::protocol::{
/// ExecutionId,
/// ThreadId,
/// ProcessId,
/// InstanceMessage,
/// TelemetryMessage,
/// TimeSyncMessage,
/// };
///
/// let collector = get_collector();
/// let message = InstanceMessage {
/// execution: ExecutionId::from_raw(1),
/// thread: ThreadId::from_raw(ProcessId::from_raw(1), NonZeroU64::new(1).unwrap()),
/// message: TelemetryMessage::TimeSync(TimeSyncMessage {
/// local_timestamp: 0,
/// since_epoch: 0,
Expand Down Expand Up @@ -332,15 +334,15 @@ impl Collector {
#[inline]
pub(crate) fn log_message(&self, log: LogMessage<'_>) {
self.inner.exporter.export(InstanceMessage {
execution: self.inner.execution_id,
thread: ThreadId::current(self.inner.process_id),
message: TelemetryMessage::Log(log),
});
}

#[inline]
fn tracing_message(&self, message: TracingMessage<'_>) {
self.inner.exporter.export(InstanceMessage {
execution: self.inner.execution_id,
thread: ThreadId::current(self.inner.process_id),
message: TelemetryMessage::Tracing(message),
});
}
Expand Down
Loading