160 Commits

Author SHA1 Message Date
Jarrod Davis
b6ad438c4f attributes: remove direct dep on proc-macro2 (#296)
## Motivation

As discussed in #292:

> A follow-up to remove an explicit dependency on `proc-macro2` would be
> great, though, as it would make it easier to avoid pulling duplicate
> versions of that crate.

## Solution

Remove `proc-macro2` as a direct dependency and replace usages of types
from it accordingly.

- remove `proc-macro2` as a direct dependency
- replace usage of `TokenStream` from `proc-macro2` with `impl ToTokens`
  from `quote`
- remove usage of `Span::call_site` as that is used by default for the
  `quote!` macro
2019-08-20 09:56:12 -07:00
Jarrod Davis
52dc09d573 attributes: update dependencies (#292)
## Motivation

`tokio` 0.2 introduced a `tokio-macros` crate that uses macro-related
dependencies similar to `tracing-attributes`. Recently, [those
dependencies were updated][1], incorporating breaking changes from those
dependencies. This means that users of `tokio` 0.2 and
`tracing-attributes` will have duplicate dependencies.

[1]: https://github.com/tokio-rs/tokio/pull/1432

## Solution

Update `proc-macro2`, `syn`, and `quote` to version 1, and react to the
breaking changes (mostly in `syn`).

Note that this is currently a naive, compiler-error-driven refactoring
of `tracing-attributes`. Everything appears to be working, but I'm not
sure if there's a better (e.g. more performant) way to use the new
dependencies. Additionally, I noticed that `tokio-macros` dropped having
a direct dependency on `proc-macro2`, and I don't know if
`tracing-attributes` should do the same.

- update `quote`, `syn`, and `proc-macro2` all to version 1 
- react to breaking changes in `syn`

Fixes: #270
2019-08-19 16:52:46 -07:00
Eliza Weisman
99e061f795
examples: make use of tracing APIs more idiomatic (#273)
## Motivation

Some Tracing examples, especially in unstable crates, were written
against earlier versions of `tracing`. They don't always demonstrate
the most idiomatic use of Tracing APIs.

## Solution

This updates the examples to use newer Tracing APIs and syntax. Now, the
examples will demonstrate the preferred idioms.

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
2019-08-13 16:04:34 -07:00
Eliza Weisman
30c62e02a1
examples: update to use Rust 2018 idioms (#271)
## Motivation

`tracing` is built with Rust's 2018 edition, but some examples use
outdated idioms. Ideally, examples would show code using the currently
preferred idioms. This improves clarity, especially for newer Rust
programmers who may not be familiar with the idioms of earlier editions.
 
## Solution

This branch updates all the examples to use Rust 2018 edition idioms,
and adds `deny` attributes to prevent the use of outdated idioms.

* deny rust 2018 idiom lints in examples
* examples: update to use Rust 2018 idioms
* examples: remove most uses of `extern crate`

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
2019-08-13 11:56:54 -07:00
Eliza Weisman
ecdb675150
tracing: support no-std + alloc (#263)
## Motivation

Users have expressed interest in using `tracing` on no_std platforms
with `liballoc`. Now that `tracing-core` supports no_std (see #256), 
we can now add no_std support to `tracing` as well.

## Solution

This branch adds `no_std` support to `tracing` by adding a `std`
feature flag (on by default) which can be disabled to use `libcore` +
`liballoc` instead of `libstd`.

When the `std` feature is disabled, `tracing-core` will use
`spin::Once` rather than `std::sync::Once`, and the thread-local
scoped dispatcher will be disabled (since it necessitates a defined OS
threading model, which may not exist on `no_std` platforms).

Some tests, which rely on the thread-local dispatcher, are disabled when
the standard lib is disabled. The alternative is to use
`set_global_default` in those tests, which would necessitate placing
each test in its own separate file. Since the behavior being tested is
otherwise the same regardless of whether or not the standard library is
used, I opted to disable these tests instead.

Refs: #256
Closes: #213

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
2019-08-09 17:11:07 -07:00
Eliza Weisman
557c71b719
attributes: prepare to release 0.1.1 (#260)
# 0.1.1 (August 9, 2019)

### Changed

- Using the `#[instrument]` attribute on `async fn`s no longer requires a
  feature flag (#258)

### Fixed

- The `#[instrument]` macro now works on generic functions (#262)

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


Signed-off-by: Eliza Weisman <eliza@buoyant.io>
2019-08-09 16:56:35 -07:00
Eliza Weisman
562bca3c53
core: prepare to release 0.1.4 (#261)
Changes:

### Added

- Support for `no-std` + `liballoc` (#256)

### Fixed

- Broken links in RustDoc (#259)

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
2019-08-09 16:26:52 -07:00
Sam Scott
4f09f2ecaf attributes: add generics to instrumented methods. (#262)
## Motivation

Want to be able to use the amazing `#[instrument]` attribute on
functions which have generics/bounds.

## Solution

Add these to the proc macro.
2019-08-09 16:24:48 -07:00
Eliza Weisman
44e5e5fca4
attributes: remove need to feature flag async-await support (#258)
## Motivation

Currently, using `tracing-attributes` with an `async fn` requires a
feature flag, as well as being on a compiler that supports async-await.
This is an unfortunate usability speedbump that is necessary as the Rust
1.34 compiler will fail on any file _containing_ `async` or `await`,
even if they are inside a macro input (such as `quote!`).

## Solution

This branch removes the necessity of feature-flagging async-await
support by constructing `syn::Ident` instances for the "async" and
"await" keywords, rather than quoting them. This means that
`#[instrument]` will now work for `async fn`s on any compiler that
supports async-await, without requiring a feature flag.

I've left the feature flag defined, although it no longer does anything.
Removing it would be a breaking change for code that enables it.

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
2019-08-09 15:25:23 -07:00
Eliza Weisman
d9f7858185
attributes: prepare the instrument macro to release (#251)
## Motivation

In order to re-export the `#[instrument]` attribute macro in `tracing`,
it must be released to crates.io. There are some changes that needed to
be made prior to releasing the procedural macro crate.

## Solution

This branch makes the following changes:

- Rename the attribute macro from `trace` to `instrument` (see #246)
- Add support for setting a verbosity level (see #250)
- Add support for setting a target
- Rename the `tracing-proc-macros` crate to `tracing-attributes`
- Add documentation + a README
- Update Cargo.toml metadata

The crate should now be ready to publish and re-export from `tracing`.

Fixes: #246 
Fixes: #250
Refs: #245

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
2019-08-08 15:41:27 -07:00