Skip to content

Commit 095b1ef

Browse files
authored
refac: move ID rewriting to console (#244)
Currently, `console-subscriber` contains a bunch of machinery for rewriting non-sequential `span::Id`s from `tracing` to sequential IDs (see #75). Upon thinking about this for a bit, I don't actually understand why this has to be done on the instrumentation-side. This seems like extra work that's currently done in the instrumented application, when it really doesn't have to be. Instead, the client should be responsible for rewriting `tracing` IDs to pretty, sequential user-facing IDs. This would have a few advantages: - it moves some work out of the application, which is always good - if data is being emitted through an implementation other than `console-subscriber`, we will *still* get nicely ordered ids - this also makes some of the stuff i'm working on in #238 easier This branch removes ID rewriting from `console-subscriber`, and adds it to the `console` CLI's `state` module. Closes #240 Signed-off-by: Eliza Weisman <[email protected]>
1 parent ef55303 commit 095b1ef

File tree

8 files changed

+115
-133
lines changed

8 files changed

+115
-133
lines changed

console-api/src/common.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,3 +221,9 @@ impl From<Id> for u64 {
221221
}
222222

223223
impl Copy for Id {}
224+
225+
impl From<tracing_core::span::Id> for Id {
226+
fn from(id: tracing_core::span::Id) -> Self {
227+
Id { id: id.into_u64() }
228+
}
229+
}

console-subscriber/src/aggregator/id_data.rs

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use super::{shrink::ShrinkMap, DroppedAt, Id, Ids, ToProto};
2-
use std::collections::{HashMap, HashSet};
1+
use super::{shrink::ShrinkMap, DroppedAt, Id, ToProto};
2+
use std::collections::HashMap;
33
use std::ops::{Deref, DerefMut};
44
use std::time::{Duration, SystemTime};
55

@@ -66,9 +66,12 @@ impl<T> IdData<T> {
6666
match include {
6767
Include::UpdatedOnly => self
6868
.since_last_update()
69-
.map(|(id, d)| (*id, d.to_proto()))
69+
.map(|(id, d)| (id.into_u64(), d.to_proto()))
70+
.collect(),
71+
Include::All => self
72+
.all()
73+
.map(|(id, d)| (id.into_u64(), d.to_proto()))
7074
.collect(),
71-
Include::All => self.all().map(|(id, d)| (*id, d.to_proto())).collect(),
7275
}
7376
}
7477

@@ -78,7 +81,6 @@ impl<T> IdData<T> {
7881
now: SystemTime,
7982
retention: Duration,
8083
has_watchers: bool,
81-
ids: &mut Ids,
8284
) {
8385
let _span = tracing::debug_span!(
8486
"drop_closed",
@@ -90,7 +92,6 @@ impl<T> IdData<T> {
9092
// drop closed entities
9193
tracing::trace!(?retention, has_watchers, "dropping closed");
9294

93-
let mut dropped_ids = HashSet::new();
9495
stats.data.retain_and_shrink(|id, (stats, dirty)| {
9596
if let Some(dropped_at) = stats.dropped_at() {
9697
let dropped_for = now.duration_since(dropped_at).unwrap_or_default();
@@ -105,10 +106,6 @@ impl<T> IdData<T> {
105106
stats.dirty = *dirty,
106107
should_drop,
107108
);
108-
109-
if should_drop {
110-
dropped_ids.insert(*id);
111-
}
112109
return !should_drop;
113110
}
114111

@@ -118,13 +115,6 @@ impl<T> IdData<T> {
118115
// drop closed entities which no longer have stats.
119116
self.data
120117
.retain_and_shrink(|id, (_, _)| stats.data.contains_key(id));
121-
122-
if !dropped_ids.is_empty() {
123-
// drop closed entities which no longer have stats.
124-
self.data
125-
.retain_and_shrink(|id, (_, _)| stats.data.contains_key(id));
126-
ids.remove_all(&dropped_ids);
127-
}
128118
}
129119
}
130120

0 commit comments

Comments
 (0)