Skip to content

Commit

Permalink
native_layer: Add sequence id to counter events (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
dflemstr authored Nov 1, 2024
1 parent 73efad9 commit 19ee477
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
6 changes: 6 additions & 0 deletions crates/layer/src/ids.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ impl SequenceId {
SequenceId(h.finish() as u32)
}

pub fn for_counter(counter_name: &str) -> SequenceId {
let mut h = hash::DefaultHasher::new();
(SEQUENCE_ID_NS, COUNTER_NS, counter_name).hash(&mut h);
SequenceId(h.finish() as u32)
}

pub fn as_raw(self) -> u32 {
self.0
}
Expand Down
5 changes: 5 additions & 0 deletions crates/layer/src/native_layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,11 @@ where
fn write_counter_event(&self, meta: &tracing::Metadata, counter: debug_annotations::Counter) {
let packet = schema::TracePacket {
timestamp: Some(ffi::trace_time_ns()),
optional_trusted_packet_sequence_id: Some(
trace_packet::OptionalTrustedPacketSequenceId::TrustedPacketSequenceId(
ids::SequenceId::for_counter(counter.name).as_raw(),
),
),
data: Some(trace_packet::Data::TrackEvent(schema::TrackEvent {
r#type: Some(track_event::Type::Counter as i32),
track_uuid: Some(ids::TrackUuid::for_counter(counter.name).as_raw()),
Expand Down

0 comments on commit 19ee477

Please sign in to comment.