Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Tags and Fields enums. #8

Merged
merged 1 commit into from
Mar 3, 2018
Merged

Add Tags and Fields enums. #8

merged 1 commit into from
Mar 3, 2018

Conversation

daschl
Copy link
Contributor

@daschl daschl commented Feb 20, 2018

This changeset adds the tags and fields enums as they are
currently represented in the java implementation.

Completes #7

@daschl
Copy link
Contributor Author

daschl commented Feb 20, 2018

@stefano-pogliani

@daschl
Copy link
Contributor Author

daschl commented Feb 20, 2018

For completeness I'll also implement FromStr as well as Displayso its easier to convert from and to its textual representation

Copy link
Contributor

@stefano-pogliani stefano-pogliani left a comment

Choose a reason for hiding this comment

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

Look good.

To be sure though, is the plan for these to be used as follows?

trait Span {
    // ... snip ...
    fn log<F: Into<String>>(field: F, value: Value) {
        let field: String = field.into();
        // ... snip ...
    }
}

fn main() {
    let mut span = SomeSpan::new();
    span.log(Fields::Event, "some event");
}

@daschl
Copy link
Contributor Author

daschl commented Feb 23, 2018

@stefano-pogliani fleshed out with errors and conversion traits.. its now pretty easy (see unit tests) how to convert and from, so it gives us lots of flexibility on how to use them

fn cause(&self) -> Option<&Error> {
None
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Nit-pick: newline at the end and start of this block is inconsistent with other blocks.

Copy link
Contributor

@stefano-pogliani stefano-pogliani left a comment

Choose a reason for hiding this comment

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

Couple of minor style comments but otherwise looks good 👍

assert_eq!(Ok(Fields::Message), "message".parse());
assert_eq!(Err(ParseFieldsError::UnknownField), Fields::from_str("some_other_field"));
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Same here: block has new line at end and start that most blocks do not have.

/// The following log fields are recommended for instrumentors who are trying to capture more
/// information about a logged event. Tracers may expose additional features based on these
/// standardized data points.
#[derive(Debug, PartialEq)]
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a couple of days ago I found the rust api guidelines which has a section about derives.

I think we want to follow those guidelines, what do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

agreed, will add them!

@daschl
Copy link
Contributor Author

daschl commented Feb 25, 2018

@stefano-pogliani which traits do you think we should implement as well? I found derive, and partialeq sufficient - but happy to add more!

@stefano-pogliani
Copy link
Contributor

stefano-pogliani commented Feb 25, 2018

That is a good question.
Personally I am not sure but the rust's lib team is suggesting all of these: Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Display, Default.

Following the philosophy of "Who am I to dismiss the experience of the rust's lib team?" I'd say as many as possible?
The Default trait does not make much sense here so I'd skip that but the rest should be derivable.

What do you think @daschl?

This changeset adds the tags and fields enums as they are
currently represented in the java implementation.

Completes #7
@daschl daschl force-pushed the tags-and-fields branch from 8641e05 to 9e0ee38 Compare March 2, 2018 16:12
@daschl
Copy link
Contributor Author

daschl commented Mar 2, 2018

@stefano-pogliani added all the tags which I think make sense (also checked with for example std::Result which also implements those, so we can't be too way off here)

Copy link
Contributor

@stefano-pogliani stefano-pogliani left a comment

Choose a reason for hiding this comment

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

👍

@daschl daschl merged commit 87fb663 into master Mar 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants