Skip to content

Commit

Permalink
feat: make serde_json/preserve_order feature optional
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliboy50 committed May 3, 2024
1 parent 435c7d1 commit ef73fb6
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 18 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[workspace]
resolver = "2"
members = ["test-span", "test-span-macro"]
2 changes: 1 addition & 1 deletion test-span/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ license = "MIT OR Apache-2.0"
[dependencies]
daggy = { version = "0.8.0", features = ["serde-1", "stable_dag"] }
serde = { version = "1.0.131", features = ["derive"] }
serde_json = { version = "1.0.72", features = ["preserve_order"] }
serde_json = "1.0.72"
tokio = { version = "1.14.0", features = ["full"] }
tracing = "0.1.29"
tracing-futures = "0.2.5"
Expand Down
8 changes: 4 additions & 4 deletions test-span/src/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl Layer {

fn event(&self, event: &Event<'_>, ctx: Context<'_, impl tracing::Subscriber>) {
let current_span = ctx.current_span();
let current_span = current_span.id().map(std::clone::Clone::clone);
let current_span = current_span.id().cloned();
ALL_LOGS.lock().unwrap().event(current_span, event);
}

Expand All @@ -52,7 +52,7 @@ impl Layer {

let (root_span_id, parent_node_index) = id_to_node_index
.get(&raw_parent_id)
.map(std::clone::Clone::clone)
.copied()
.unwrap_or_else(|| panic!("missing parent attributes for {}.", raw_parent_id));

let (_, node_index) =
Expand Down Expand Up @@ -106,8 +106,8 @@ where
) {
let maybe_parent_id = attrs
.parent()
.map(std::clone::Clone::clone)
.or_else(|| ctx.current_span().id().map(std::clone::Clone::clone));
.cloned()
.or_else(|| ctx.current_span().id().cloned());

self.attributes(id.clone(), attrs, maybe_parent_id)
}
Expand Down
13 changes: 6 additions & 7 deletions test-span/src/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,20 @@ impl LogsRecorder {
) -> Vec<Record> {
self.recorders
.iter()
.filter_map(|(log_metadata, recorders)| {
(filter.is_enabled(log_metadata) && log_metadata.span_id == Some(span_id))
.then(|| recorders.contents().cloned())
.filter(|(log_metadata, _recorders)| {
filter.is_enabled(log_metadata) && log_metadata.span_id == Some(span_id)
})
.flatten()
.flat_map(|(_log_metadata, recorders)| recorders.contents().cloned())
.collect()
}

pub fn all_records_for_filter(&self, filter: &crate::Filter) -> Vec<Record> {
self.recorders
.iter()
.filter_map(|(log_metadata, recorders)| {
(filter.is_enabled(log_metadata)).then(|| recorders.contents().cloned())
.filter(|(log_metadata, _recorders)| {
filter.is_enabled(log_metadata)
})
.flatten()
.flat_map(|(_log_metadata, recorders)| recorders.contents().cloned())
.collect()
}
}
9 changes: 4 additions & 5 deletions test-span/src/report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,13 @@ impl Report {
let id_to_node = SPAN_ID_TO_ROOT_AND_NODE_INDEX.lock().unwrap().clone();
let (global_root, root_node_index) = id_to_node
.get(&root_node)
.map(std::clone::Clone::clone)
.copied()
.expect("couldn't find rood node");

let node_to_id: IndexMap<NodeIndex, u64> = id_to_node
.into_iter()
.filter_map(|(key, (root, value))| (root == global_root).then(|| (value, key)))
.filter(|&(_key, (root, _value))| root == global_root)
.map(|(key, (_root, value))| (value, key))
.collect();

let relevant_spans = node_to_id.values().cloned().collect::<HashSet<_>>();
Expand Down Expand Up @@ -165,8 +166,6 @@ impl Report {
if let Some(recorder) = self.spans.get(&self.root_id) {
let metadata = recorder
.metadata()
.as_ref()
.map(std::clone::Clone::clone)
.expect("recorder without metadata");
let span_name = format!("{}::{}", metadata.target, metadata.name);

Expand Down Expand Up @@ -194,7 +193,7 @@ impl Report {
.contents(filter);

child_record.append(self.logs.record_for_span_id_and_filter(*child_id, filter));
records.extend(child_record.entries().cloned().into_iter());
records.extend(child_record.entries().cloned());
self.dfs_logs_insert(records, child_node, filter);
}
}
Expand Down

0 comments on commit ef73fb6

Please sign in to comment.