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

tracing: Replace macro-rules with procedural macros #133

Open
hawkw opened this issue Jul 2, 2019 · 6 comments
Open

tracing: Replace macro-rules with procedural macros #133

hawkw opened this issue Jul 2, 2019 · 6 comments
Assignees
Labels
crate/attributes Related to the `tracing-attributes` crate crate/macros crate/tracing Related to the `tracing` crate kind/feature New feature or request

Comments

@hawkw
Copy link
Member

hawkw commented Jul 2, 2019

Feature Request

Crates

tracing

Motivation

Now that we are not supporting Rust 1.26.0 as our minimum compatible version, we can ship procedural macros in tracing. Replacing the existing macro_rules macros should improve user-facing error messages, make the macros more maintainable, and make it easier to add new features to them in the future (such as #83).

Proposal

The macros should be in a separate crate, but they should be re-exported by tracing. We should re-implement the existing macro syntax prior to adding any new features, and do that separately as a follow-up.

I think the new macros could live in the existingtracing-proc-macros or tracing-macros crates. Perhaps we should use tracing-macros and move everything currently in tracing-proc-macros there (and rewrite or remove the macros currently in tracing-macros, which are very experimental).

@hawkw hawkw added kind/feature New feature or request crate/attributes Related to the `tracing-attributes` crate crate/macros crate/tracing Related to the `tracing` crate labels Jul 2, 2019
@hawkw
Copy link
Member Author

hawkw commented Jul 2, 2019

I believe @Ralith is working on this. My understanding is that it is currently blocked on dtolnay/syn#661.

@Ralith
Copy link
Collaborator

Ralith commented Jul 2, 2019

I believe @Ralith is working on this. My understanding is that it is currently blocked on dtolnay/syn#661.

This is accurate. If that issue can be fixed, I am otherwise very close to a working prototype of event!().

I think the new macros could live in the existingtracing-proc-macros or tracing-macros crates. Perhaps we should use tracing-macros and move everything currently in tracing-proc-macros there (and rewrite or remove the macros currently in tracing-macros, which are very experimental).

These macros will necessarily rely on proc-macro-hack, which means that they can't be used by downstream code directly from the crate they're implemented in; an intermediate re-exporting crate is always necessary. My understanding is that tokio(-proc)-macros are intended to be user-facing, so we'll still need an internal -impl crate.

@Ralith
Copy link
Collaborator

Ralith commented Jul 2, 2019

Looks like it might not be a syn issue: dtolnay/proc-macro-hack#34

@Ralith
Copy link
Collaborator

Ralith commented Jul 3, 2019

Now isolated to a compiler issue: rust-lang/rust#62325

@hawkw
Copy link
Member Author

hawkw commented Jul 3, 2019

Thanks for keeping us updated, @Ralith --- great to hear that progress is being made on unblocking this!

@hawkw
Copy link
Member Author

hawkw commented Aug 1, 2019

Looks like the compiler bug has been fixed in rust-lang/rust#62393, so hopefully we can move forwards with this once the fix is on stable.

hawkw added a commit that referenced this issue Aug 19, 2019
## Motivation


Currently, the `tracing` macros require curly braces as delimiters when
a `format_args` macro is used in addition to structured fields, like:

```rust
info!({ field1 = value1, field2 = value2 }, "unstructured message");
```

This is confusing, since the delimiters are not used in other cases; it
makes the syntax more complex; and, most importantly, I think it looks
kind of ugly. 

I've been planning to get rid of this when we transition to procedural
macros, but the transition is currently blocked on a compiler bug,
rust-lang/rust#62325.
(see #133 (comment))

I've been getting tired of waiting for this.

## Solution:

This branch updates the `tracing` crate's macros to support a
format_args message after the structured key-value fields without curly
braces. For example,

```rust
let yay = "WITHOUT DELIMITERS!!!";
info!(field1 = value1, field2 = value2, "message: {}", yay);
```

I've updated the tests & examples in the `tracing` crate so that they
show this usage rather than the old usage.

The old form with curly braces is still supported, since removing it
would be a breaking change, but we'll transition it out in examples &
tutorials. (can you put a `deprecated` attribute on a specific macro
arm???).

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crate/attributes Related to the `tracing-attributes` crate crate/macros crate/tracing Related to the `tracing` crate kind/feature New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants