Skip to content

Commit

Permalink
subscriber: look at event parents to determine resource id (#114)
Browse files Browse the repository at this point in the history
This PR changes the way poll and state update ops are associated
with resource by incorporating the feedback in tokio-rs/tokio#4072 (comment)
Instead of only looking at entered spans, we now use `Context::event_span`

Signed-off-by: Zahari Dichev <zaharidichev@gmail.com>
  • Loading branch information
zaharidichev committed Sep 6, 2021
1 parent b0c5a9d commit 0685482
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions console-subscriber/src/lib.rs
Expand Up @@ -413,8 +413,8 @@ where
}
// else unknown waker event... what to do? can't trace it from here...
} else if self.poll_op_callsites.contains(event.metadata()) {
match ctx.current_span().id() {
Some(resource_id) if self.is_id_resource(resource_id, &ctx) => {
match ctx.event_span(event) {
Some(resource_span) if self.is_resource(resource_span.metadata()) => {
let mut poll_op_visitor = PollOpVisitor::default();
event.record(&mut poll_op_visitor);
if let Some((op_name, is_ready)) = poll_op_visitor.result() {
Expand All @@ -432,21 +432,28 @@ where
self.send(Event::PollOp {
metadata,
at,
resource_id: resource_id.clone(),
resource_id: resource_span.id(),
op_name,
async_op_id,
task_id,
is_ready,
});
} else {
eprintln!(
"poll op event should be emitted in the context of an async op and task spans: {:?}",
event
)
}
// else poll op event should be emitted in the context of an async op and task spans
}
}
_ => {} // poll op event should be emitted in the context of a resource span
_ => eprintln!(
"poll op event should have a resource span parent: {:?}",
event
),
}
} else if self.state_update_callsites.contains(event.metadata()) {
match ctx.current_span().id() {
Some(resource_id) if self.is_id_resource(resource_id, &ctx) => {
match ctx.event_span(event) {
Some(resource_span) if self.is_resource(resource_span.metadata()) => {
let meta_id = event.metadata().into();
let mut state_update_visitor = StateUpdateVisitor::new(meta_id);
event.record(&mut state_update_visitor);
Expand All @@ -455,13 +462,13 @@ where
self.send(Event::StateUpdate {
metadata,
at,
resource_id: resource_id.clone(),
resource_id: resource_span.id(),
update,
});
}
}
_ => eprintln!(
"state update event should be emitted in the context of a resource span: {:?}",
"state update event should have a resource span parent: {:?}",
event
),
}
Expand Down

0 comments on commit 0685482

Please sign in to comment.