Skip to content
This repository has been archived by the owner on Jan 12, 2019. It is now read-only.

Add trait methods for follows_from #49

Merged
merged 7 commits into from
Oct 25, 2018
Merged

Conversation

hawkw
Copy link
Owner

@hawkw hawkw commented Oct 24, 2018

This branch adds Subscriber and Span methods for annotating spans
with prior spans from which they follow. For the most part, this branch
doesn't add implementations of this interface for now, besides proxying
to it in composite subscribers.

It would be good to get a review of the interface before getting too deep
into implementation.

Signed-off-by: Eliza Weisman eliza@buoyant.io

@hawkw hawkw added the kind/enhancement New feature or request label Oct 24, 2018
@hawkw hawkw self-assigned this Oct 24, 2018
@@ -124,6 +124,10 @@ pub struct Data {
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct Id(u64);

pub trait AsId {
fn as_id(&self) -> Option<Id>;
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Abstracts over anything that may have a span ID, so we can add a follows-from annotation from a Span handle, an Id, and so on. I was hoping there was a trait in the standard library that could be used here, but this seemed simpler.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I guess this depends on rust-lang/rust#33417 landing.

@@ -38,6 +38,8 @@ pub trait Subscriber {
value: &dyn IntoValue,
) -> Result<(), AddValueError>;

fn add_follows_from(&self, span: &span::Id, follows: span::Id);
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this return an error if the span corresponding to that ID doesn't exist, like how add_value does?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think so. I can imagine two types of subscribers:

  • Subscribers that do care whether a span corresponds to that ID doesn't exist. An example might be a profiler like pprof or hawktracer.
  • Subscribers that don't care whether a span corresponds to that ID doesn't exist. An example might be a metrics emission system.

A metrics emission system could just ignore the error, but an implementer of a profiler might be frustrated if they don't get an error when calling this method. Introducing an error down the line would be a breaking error, so I'd opt for an error that can be ignored now.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's reasonable. Good point.

@@ -38,6 +38,8 @@ pub trait Subscriber {
value: &dyn IntoValue,
) -> Result<(), AddValueError>;

fn add_follows_from(&self, span: &span::Id, follows: span::Id);
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Taking the ID of the span to annotate by-reference may not really be necessary...


/// Queries the registry for an iterator over the IDs of the spans that
/// `span` follows from.
fn get_follows_from(&self, span: &Id) -> Self::FollowsFrom;
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there other ways of querying these relationships that ought to be part of the registry API?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the subscriber interface also have a similar function? I kept it out because I didn't want to add too many more methods to that trait...

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there other ways of querying these relationships that ought to be part of the registry API?

I'm thinking the follows_from family of methods should be named succeeds/proceeds to more clearly delineate ordering. Alternatively—and this might be a infeasible—but a PartialOrd implementation could be helpful.

Should the subscriber interface also have a similar function? I kept it out because I didn't want to add too many more methods to that trait.

No, probably not, but I can be convinced otherwise.

Copy link
Owner Author

@hawkw hawkw Oct 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@davidbarsky

I'm thinking the follows_from family of methods should be named succeeds/proceeds to more clearly delineate ordering.

That's reasonable --- this naming is per tokio-rs/tokio#561 (comment), but I'm open to renaming it. I'm not sure how I feel about succeeds here, though, since that seems easy to confuse with a notion of success/failure...

Alternatively—and this might be a infeasible—but a PartialOrd implementation could be helpful.

Having something like this would certainly be ergonomic, but I don't think it's immediately possible in the current scheme --- it's the subscriber that knows these relationships, not the spans themselves. That said, I'll keep thinking about the potential of doing that.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's reasonable --- this naming is per tokio-rs/tokio#561 (comment), but I'm open to renaming it. I'm not sure how I feel about succeeds here, though, since that seems easy to confuse with a notion of success/failure...

True. What about “prior/subsequent?”

Having something like this would certainly be ergonomic, but I don't think it's immediately possible in the current scheme --- it's the subscriber that knows these relationships, not the spans themselves. That said, I'll keep thinking about the potential of doing that.

Good point, didn't consider that that part.

Copy link
Owner Author

@hawkw hawkw Oct 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's reasonable --- this naming is per tokio-rs/tokio#561 (comment), but I'm open to renaming it. I'm not sure how I feel about succeeds here, though, since that seems easy to confuse with a notion of success/failure...

True. What about “prior/subsequent?”

That works for me!

[...] I don't think it's immediately possible in the current scheme --- it's the subscriber that knows these relationships, not the spans themselves.

Good point, didn't consider that that part.

I am considering changing the SpanRef type in the tokio-trace-subscriber crate to have a reference back to the registry for querying it to get span data, so it may be possible to implement something like that for SpanRefs in the more batteries-included crate...but that'll be its own branch.

Copy link
Collaborator

@davidbarsky davidbarsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some comments that aren't blocking, but might be useful directions to explore.

@hawkw
Copy link
Owner Author

hawkw commented Oct 25, 2018

There is one other potential concern that comes to mind here: namely, how should the similar follows-from annotations for events be handled? Do we want each one to correspond to an event_follows_from method invocation on the subscriber, or is passing them as an array on the Event struct itself okay?

The former would be more consistent with spans, but it also introduces some additional complexity --- currently, there isn't a way to refer to an event that's already occurred (there's no event ID type), and the event! macro doesn't return a persistent handle for calling methods on. I'd rather not introduce a lot of complexity to Events, but I'd also prefer both APIs to be consistent...

@hawkw
Copy link
Owner Author

hawkw commented Oct 25, 2018

@davidbarsky I think I've addressed all your feedback --- any other concerns?

@davidbarsky
Copy link
Collaborator

davidbarsky commented Oct 25, 2018 via email

@hawkw hawkw merged commit ca00836 into master Oct 25, 2018
@hawkw hawkw deleted the eliza/follows-from-sketch branch October 25, 2018 21:54
@hawkw hawkw added this to Done in core 0.1 Oct 30, 2018
@hawkw hawkw mentioned this pull request Oct 30, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind/enhancement New feature or request
Projects
core 0.1
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

2 participants