Skip to content

Commit 0685482

Browse files
authored
subscriber: look at event parents to determine resource id (console-rs#114)
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 <[email protected]>
1 parent b0c5a9d commit 0685482

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

console-subscriber/src/lib.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -413,8 +413,8 @@ where
413413
}
414414
// else unknown waker event... what to do? can't trace it from here...
415415
} else if self.poll_op_callsites.contains(event.metadata()) {
416-
match ctx.current_span().id() {
417-
Some(resource_id) if self.is_id_resource(resource_id, &ctx) => {
416+
match ctx.event_span(event) {
417+
Some(resource_span) if self.is_resource(resource_span.metadata()) => {
418418
let mut poll_op_visitor = PollOpVisitor::default();
419419
event.record(&mut poll_op_visitor);
420420
if let Some((op_name, is_ready)) = poll_op_visitor.result() {
@@ -432,21 +432,28 @@ where
432432
self.send(Event::PollOp {
433433
metadata,
434434
at,
435-
resource_id: resource_id.clone(),
435+
resource_id: resource_span.id(),
436436
op_name,
437437
async_op_id,
438438
task_id,
439439
is_ready,
440440
});
441+
} else {
442+
eprintln!(
443+
"poll op event should be emitted in the context of an async op and task spans: {:?}",
444+
event
445+
)
441446
}
442-
// else poll op event should be emitted in the context of an async op and task spans
443447
}
444448
}
445-
_ => {} // poll op event should be emitted in the context of a resource span
449+
_ => eprintln!(
450+
"poll op event should have a resource span parent: {:?}",
451+
event
452+
),
446453
}
447454
} else if self.state_update_callsites.contains(event.metadata()) {
448-
match ctx.current_span().id() {
449-
Some(resource_id) if self.is_id_resource(resource_id, &ctx) => {
455+
match ctx.event_span(event) {
456+
Some(resource_span) if self.is_resource(resource_span.metadata()) => {
450457
let meta_id = event.metadata().into();
451458
let mut state_update_visitor = StateUpdateVisitor::new(meta_id);
452459
event.record(&mut state_update_visitor);
@@ -455,13 +462,13 @@ where
455462
self.send(Event::StateUpdate {
456463
metadata,
457464
at,
458-
resource_id: resource_id.clone(),
465+
resource_id: resource_span.id(),
459466
update,
460467
});
461468
}
462469
}
463470
_ => eprintln!(
464-
"state update event should be emitted in the context of a resource span: {:?}",
471+
"state update event should have a resource span parent: {:?}",
465472
event
466473
),
467474
}

0 commit comments

Comments
 (0)