59 Commits

Author SHA1 Message Date
Tyson Nottingham
94dace6d60 error: add missing backtick to prelude docs (#2120) 2022-05-11 20:55:06 +00:00
Eliza Weisman
d0d5dcf6f4 chore: fix Rust 1.60 warnings (#2056)
## Motivation

The Rust 1.60 release introduced a few new lints that trigger on the
`tracing` codebase. In particular, `clippy` added some new lints for
method naming, and the `unreachable_pub` lint now seems to be triggered
incorrectly by `pub use foo as _` re-exports.

## Solution

This branch fixes the lints.

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
2022-04-07 17:08:42 -07:00
Eliza Weisman
4365b3971b chore: update MSRVs from 1.42 to 1.49 (#1913)
This updates all crates' MSRVs to 1.49 if they were not already greater
than that (`tracing-appender` is at 1.53). Rust 1.49+ is required to
update `parking_lot` to v0.12 (see #1878). Also, `futures-task` (which I
believe is only needed as a transitive dep) now needs 1.45+, so this
also fixes our CI build.

Because `tracing-opentelemetry` previously required 1.46.0, it had a
separate CI MSRV job. Since 1.49.0 is greater than 1.46.0, the separate
check for `tracing-opentelemetry` is no longer needed.

In the process, I removed deprecated uses of
`core::atomic::spin_loop_hint`, which is replaced with
`core::hint::spin_loop` in 1.49.
2022-02-07 17:52:00 +00:00
Folyd
a36cb8f7ea chore: fix cargo MSRV field typo (#1742) 2021-11-23 15:07:29 -05:00
Eliza Weisman
2e247625ac chore: add MSRV cargo metadata (#1730)
This branch adds the `[package.rust]` metadata to `Cargo.toml` for all
crates. See https://rust-lang.github.io/rfcs/2495-min-rust-version.html
for details.
2021-11-19 16:21:19 -08:00
Eliza Weisman
2b3aa06de4 subscriber: rename Subscribe::new_span to on_new_span (#1674)
While we're breaking things, we may as well do this as well.

Closes #630
Closes #662
2021-10-22 11:04:20 -07:00
Eliza Weisman
937c5d7cf0 subscriber: replace dyn Write with a Writer type (#1661)
## Motivation

Currently, the `FormatEvent` and `FormatFields` traits in
`tracing-subscriber` are passed a `&mut dyn fmt::Write` trait object to
write formatted representations of events and fields to. This is fine,
but it doesn't give us the ability to easily provide additional
configuration to the formatter, such as whether ANSI color codes are
supported.

Issue #1651 describes some approaches for adding a way to expose the
ANSI color code configuration to custom formatters. In particular, the
proposed solution involves wrapping the `fmt::Write` trait object in an
opaque struct, which can then implement additional methods for exposing
information like "are ANSI colors enabled" to the formatter. Since this
changes the signature of the `FormatEvent::format_event` and
`FormatFields::format_fields` methods, it's a breaking change.
Therefore, we need to make this change _now_ if we want to get the API
change in for `tracing-subscriber` 0.3.

## Solution

This branch adds a `Writer` struct that wraps the `&mut dyn fmt::Write`
trait object, and changes the various method signatures as appropriate.
It does **not** actually implement the change related to ANSI color
formatting. Once we change these methods' signatures to accept a
`Writer` struct, we can add as many methods to that struct as we like
without making additional breaking API changes. Therefore, this branch
_just_ makes the breaking change that's necessary to get in before v0.3
is released.

Propagating the ANSI color configuration can be implemented in a future
branch.

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
2021-10-20 16:35:22 -07:00
Christopher Durham
aea1a8042f error: allow creating SpanTrace from Span directly (#1492)
## Motivation

I'm writing a tracing subscriber layer that captures tracing events to
display in an in-program UI in a somewhat structured manner; as such I
don't want to just use the fmt layer's format-to-a-single-string
approach, and instead capture (currently) the event metadata, fields,
timestamp, thread, and spantrace, to be displayed in a
filterable/searchable/interactable manner later.

Currently, the only way to capture a `SpanTrace` is via
`SpanTrace::capture`. This (rightfully) captures the `SpanTrace` of the
current execution. However, I'm currently inside `Subscribe::on_event`;
I have the span right here! Even if `Span::current` happens to be the
same during `on_event` as when the event was fired, it seems more
"proper" to create a `SpanTrace` from the span passed in to me, rather
than looking up `Span::current`.

## Solution

The actual code change is almost trivial: all that needs to happen is to
expose a `SpanTrace::new` that takes a `Span` in addition to the
existing `SpanTrace::current`.
2021-08-05 16:27:51 -07:00
Teo Klestrup Röijezon
f54136cd14 subscriber: unify span traversal (#1445)
Forward-port of #1431 and #1434

* subscriber: unify span traversal (#1431)

## Motivation

Fixes #1429 (forwardport from v0.1.x branch)

## Solution

Implemented as described in #1429, and migrated all internal uses of the
deprecated methods. All tests passed both before and after the migration
(9ec8130).

- Add a new method `SpanRef::scope(&self)` that returns a leaf-to-root
  `Iterator`, including the specified leaf
- Add a new method `Scope::from_root(self)` (where `Scope` is the type
  returned by `SpanRef::scope` defined earlier) that returns a
  root-to-leaf `Iterator` that ends at the current leaf (in other
  words: it's essentially the same as
  `Scope::collect::<Vec<_>>().into_iter().rev()`)
- Deprecate all existing iterators, since they can be replaced by the
  new unified mechanism:
  - `Span::parents` is equivalent to `Span::scope().skip(1)` (although
    the `skip` is typically a bug)
  - `Span::from_root` is equivalent to `Span::scope().skip(1).from_root()`
    (although the `skip` is typically a bug)
  - `Context::scope` is equivalent to
    `Context::lookup_current().scope().from_root()` (although the
    `lookup_current` is sometimes a bug, see also #1428)

* subscriber: add Context method for resolving an Event's SpanRef (#1434)

## Motivation

Fixes #1428 (forward-port from v0.1.x)

## Solution

Adds a new `Context::event_span` method as proposed in the issue.

No existing formatters were changed to use it yet, that seems like a
secondary issue (especially if they already work correctly).
2021-06-24 10:12:29 -07:00
Folyd
6b7051c989 chore: unify generic name of Collect (#1432) 2021-06-10 13:00:40 -04:00
Folyd
fe59f77203 chore: rename layers to subscribers and fix some typos (#1272) 2021-03-04 13:26:26 -05:00
Ole Schönburg
a458124379 core: change Collect::downcast_raw to return NonNull (#1264)
## Motivation 

Resolves #1073, quoting from there: 

> If we changed this to `Option<NonNull<()>>` we could benefit from
> niche optimization, saving us the option discriminant and making
> this return a single word pointer. That may in turn let us benefit
> from additional optimizations. This could make downcasting slightly
> faster.

## Solution

I've made the change to the function signature and let rustc guide me
through the process of fixing all callers. This was mostly
straightforward but it is `unsafe` code so I'm not sure the changes here
are correct.
2021-02-25 13:58:48 -08:00
Taiki Endo
7594d40c61 chore: disable default features of tracing dependencies (#1144)
This avoids relatively heavy dependencies (`tracing-attributes`, `syn`,
etc.) in some cases.
2020-12-18 13:22:52 -08:00
Eliza Weisman
b1baa6c2ef subscriber: add lifetime parameter to MakeWriter (#781)
## Motivation

Currently, the `tracing-subscriber` crate has the `MakeWriter` trait for
customizing the io writer used by `fmt`. This trait is necessary (rather
than simply using a `Write` instance) because the default implementation
performs the IO on the thread where an event was recorded, meaning that
a separate writer needs to be acquired by each thread (either by calling
a function like `io::stdout`, by locking a shared `Write` instance,
etc).

Right now there is a blanket impl for `Fn() -> T where T: Write`. This
works fine with functions like `io::stdout`. However, the _other_ common
case for this trait is locking a shared writer.

Therefore, it makes sense to see an implementation like this:

``` rust
impl<'a, W: io::Write> MakeWriter for Mutex<W>
where
    W: io::Write,
{
    type Writer = MutexWriter<'a, W>;
    fn make_writer(&self) -> Self::Writer {
        MutexWriter(self.lock().unwrap())
    }
}

pub struct MutexWriter<'a, W>(MutexGuard<'a, W>);

impl<W: io::Write> io::Write for MutexWriter<'_, W> {
    // write to the shared writer in the `MutexGuard`...
}
```

Unfortunately, it's impossible to write this. Since `MakeWriter` always
takes an `&self` parameter and returns `Self::Writer`, the generic
parameter is unbounded:
```
    Checking tracing-subscriber v0.2.4 (/home/eliza/code/tracing/tracing-subscriber)
error[E0207]: the lifetime parameter `'a` is not constrained by the impl trait, self type, or predicates
  --> tracing-subscriber/src/fmt/writer.rs:61:6
   |
61 | impl<'a, W: io::Write> MakeWriter for Mutex<W>
   |      ^^ unconstrained lifetime parameter

error: aborting due to previous error
```

This essentially precludes any `MakeWriter` impl where the writer is
borrowed from the type implementing `MakeWriter`. This is a significant
blow to the usefulness of the trait. For example, it prevented the use
of `MakeWriter` in `tracing-flame` as suggested in
https://github.com/tokio-rs/tracing/pull/631#discussion_r391138233.

## Proposal

This PR changes `MakeWriter` to be generic over a lifetime `'a`:

```rust
pub trait MakeWriter<'a> {
    type Writer: io::Write;

    fn make_writer(&'a self) -> Self::Writer;
}
```
The `self` parameter is now borrowed for the `&'a` lifetime, so it is
okay to return a writer borrowed from `self`, such as in the `Mutex`
case.

I've also added an impl of `MakeWriter` for `Mutex<T> where T: Writer`.

Unfortunately, this is a breaking change and will need to wait until we
release `tracing-subscriber` 0.3.

Fixes #675.

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
2020-11-21 10:42:25 -08:00
Joshua Nelson
1f3e095a5d docs: Remove deny(broken_intra_doc_links) (#1114)
As of Rust 1.48, these are stable and the warnings are enabled by default.
2020-11-19 15:02:13 -08:00
Joshua Nelson
9e07ff8143 docs: Switch to even more intra-doc links (#1084) 2020-11-19 10:53:20 -05:00
Jane Lusby
ef1d940bfb Add support for converting errors wrapped by TracedError (#1055)
## Motivation

Right now TracedError is pretty much incompatible with enum heavy error
handling implementations. The way its currently designed you'd have to make
sure that each leaf error independently is wrapped in a `TracedError` so that
all sources end up capturing a SpanTrace.

## Solution

To resolve this I've added a `map` method for transforming the inner type of a
TracedError while preserving the existing SpanTrace. This is still a bit
cumbersome, where before you'd be able to write `result.map_err(|source|
MyError { source, some_context })` now you'll have to write
`result.map_err(|source| source.map(|source| MyError { source, some_context
}))`. To fix this we should probably eventually add an extension trait on
`Result` but I want to experiment with that half of the change in `zebra`
before committing to an API, since it can easily be done out of tree.

Co-authored-by: Eliza Weisman <eliza@buoyant.io>
2020-11-05 16:42:20 -08:00
Joshua Nelson
a0e1daa7be docs: Convert even more intra-doc links (#1077)
## Motivation

#940

## Solution

This changes the docs.rs links, many of which were broken (or would have
been broken on the next release). It also converts some links I missed
the first time (maybe they were added after I opened the PR?).
2020-11-02 13:01:07 -08:00
Joshua Nelson
879b350708 docs: Convert _all_ the intra-doc links (#1022)
## Motivation

Closes https://github.com/tokio-rs/tracing/issues/940.

## Solution

Uses ~~a heavily patched version~~ the latest master version of
https://github.com/poliorcetics/cargo-intraconv/ to automatically
convert the links. Fixes remaining issues by hand.
2020-11-02 09:47:49 -08:00
David
eadf2a23da chore: Fix several renames missed in #1015 (#1066)
The changes were in tests, tracing-error, and example.
2020-10-27 13:46:32 -04:00
David Barsky
98ba44c22e core: rename Subscriber to Collect (#1015)
This PR renames the following:

- `tracing_core::Subscriber` to `tracing_core::Collect`
- `tracing_subscriber::layer::Layer` to `tracing_subscriber::layer::Subscribe`

Authored-by: David Barsksy <dbarsky@amazon.com>
Co-authored-by: Eliza Weisman <eliza@buoyant.io>
2020-10-22 15:11:23 -04:00
xd009642
f841b579cb docs: add favicon for extra pretty docs (#1033)
A PR to make the docs extra swish via a favicon for the browser tab!

Before 

![image](https://user-images.githubusercontent.com/3472518/95902628-f7dd7380-0d8c-11eb-855a-f6530103917d.png)

After

![image](https://user-images.githubusercontent.com/3472518/95902709-0f1c6100-0d8d-11eb-85f7-49cdf36473ac.png)
2020-10-13 16:02:09 -07:00
Joshua Nelson
2f59b32a46 chore: fix nightly clippy warnings (#991)
## Motivation

This will avoid breaking CI on new releases of clippy. It also makes the
code a little easier to read.

## Solution

- Convert `match val { pat => true, _ => false }` to `matches!(val, pat)`
- Remove unnecessary closures
- Convert `self: &mut Self` to `&mut self`

This bumps the MSRV to 1.42.0 for `matches!`.
The latest version of rust is 1.46.0, so as per
https://github.com/tokio-rs/tracing#supported-rust-versions this is not
considered a breaking change.

I didn't fix the following warning because the fix was not trivial/needed
a decision:

```
warning: you are deriving `Ord` but have implemented `PartialOrd` explicitly
   --> tracing-subscriber/src/filter/env/field.rs:16:32
    |
16  | #[derive(Debug, Eq, PartialEq, Ord)]
    |                                ^^^
    |
    = note: `#[warn(clippy::derive_ord_xor_partial_ord)]` on by default
note: `PartialOrd` implemented here
   --> tracing-subscriber/src/filter/env/field.rs:98:1
    |
98  | / impl PartialOrd for Match {
99  | |     fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
100 | |         // Ordering for `Match` directives is based first on _whether_ a value
101 | |         // is matched or not. This is semantically meaningful --- we would
...   |
121 | |     }
122 | | }
    | |_^
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#derive_ord_xor_partial_ord
```

As a side note, this found a bug in clippy 😆 https://github.com/rust-lang/rust-clippy/issues/6089
2020-09-30 09:26:27 -07:00
Eliza Weisman
19440dd6ba chore: bump all crate versions (#998)
This branch updates all crate versions to 0.2.x. After this PR merges,
we can now develop `tracing`/`tracing-core` v0.2.x on `master`. 

There is now a separate, protected `v0.1.x` branch. Changes backported
to 0.1 versions of `tracing` crates can be merged to that branch. 

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
2020-09-29 11:49:54 -07:00
Takayuki Maeda
6f01226570 docs: add deny(broken_intra_doc_links) (#981)
## Motivation

In order to get a compiler warning (or error) when links are broken. 
Closes #940

## Solution

- [x] add `deny(broken_intra_doc_links)`
- [x] add a note to the CONTRIBUTING.md documentation on building docs locally

Co-authored-by: Eliza Weisman <eliza@buoyant.io>
Co-authored-by: Joshua Nelson <joshua@yottadb.com>
2020-09-23 10:24:34 -07:00
Eliza Weisman
f470db1b03 docs: add a version of the logo with text (#953)
This changes the logo to a wordmark. This should be consistent
with the ones for all the other Tokio crates, when we add them
elsewhere.

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
2020-08-24 15:55:00 -07:00
Eliza Weisman
3f8280ae69 docs: consistent MSRV docs & policy explanation (#941)
## Motivation

PR #934 fixed a bug in the CI configuration where MSRV checks were not
being run correctly. After this was fixed, it was necessary to bump the
MSRV to 1.40.0, as the tests were no longer actually passing on 1.39,
because some dependencies no longer support it.

While updating the documentation to indicate that the new MSRV is 1.40,
I noticed that the note on the MSRV was located inconsistently in the
READMEs and `lib.rs` documentation of various crates, and missing
entirely in some cases. Additionally, there have been some questions on
what our MSRV _policies_ are, and whether MSRV bumps are considered
breaking changes (see e.g. #936). 

## Solution

I've updated all the MSRV notes in the documentation and READMEs to
indicate that the MSRV is 1.40. I've also ensured that the MSRV note is
in the same place for every crate (at the end of the "Overview" section
in the docs), and that it's formatted consistently.

Furthermore, I added a new section to the READMEs and `lib.rs` docs
explaining the current MSRV policy in some detail. Hopefully, this
should answer questions like #936 in the future. The MSRV note in the
overview section includes a link to the section with further details.

Finally, while doing this, I noticed a couple of crates
(`tracing-journald` and `tracing-serde`) were missing top-level `lib.rs`
docs. Rather than just adding an MSRV note and nothing else, I went
ahead and fixed this using documentation from those crate's READMEs.

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
2020-08-18 12:11:16 -07:00
Eliza Weisman
bb8e977ab7 docs: fix broken splash graphic link (#913)
Somehow a single line of whitespace is load-bearing I guess? MARKDOWN!

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
2020-08-10 15:24:31 -07:00
Eliza Weisman
59da1ccc60 docs: put splash graphic in all READMEs (#911)
This puts the splash SVG in every crate's README, so
that it will be rendered on crates.io.

I also changed the link to an absolute URL, to ensure that
it works even outside of the repo.

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
2020-08-10 14:04:02 -07:00
Eliza Weisman
2dd8fef355 subscriber: prepare to release 0.2.10 (#872)
### Fixed

- **docs**: Incorrect formatting (#862)

### Changed

- **filter**: `LevelFilter` is now a re-export of the
  `tracing_core::LevelFilter` type, it can now be used interchangably
  with the versions in `tracing` and `tracing-core` (#853)
- **filter**: Significant performance improvements when comparing
  `LevelFilter`s  and `Level`s (#853)
- Updated the minimum `tracing-core` dependency to 0.1.12 (#853)

### Added

- **filter**: `LevelFilter` and `EnvFilter` now participate in
  `tracing-core`'s max level hinting, improving performance
  significantly in some use cases where levels are disabled globally
  (#853)

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
2020-07-31 11:43:06 -07:00
Eliza Weisman
4c36130211 subscriber: prepare to release 0.2.9 (#846)
### Fixed

- **fmt**: Fixed compilation failure on MSRV when the `chrono` feature
  is disabled (#844)

### Added

- **fmt**: Span lookup methods defined by `layer::Context` are now also
  provided by `FmtContext` (#834)
2020-07-23 17:11:18 -07:00
Josh Stone
0de7d51689 chore: Include the LICENSE in every crate (#842)
## Motivation

The MIT license states:

> The above copyright notice and this permission notice
> shall be included in all copies or substantial portions
> of the Software.

## Solution

Therefore the LICENSE files should be present in each crate directory,
so they are included with `cargo publish`.
2020-07-23 12:23:04 -07:00
Eliza Weisman
add986d651 chore: add tracing logo to RustDoc (#832)
Now that the new https://tokio.rs is live, we can add the new Tracing
logo to the RustDoc!

I also added a couple missing `html_root_url` attributes in published
crates.

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
2020-07-21 14:25:36 -07:00
Eliza Weisman
68556f2fe8 subscriber: prepare to release 0.2.7 (July 1, 2020) (#775)
### Changed

- **parking_lot**: Updated the optional `parking_lot` dependency to
  accept the latest `parking_lot` version (#774)

### Fixed

- **fmt**: Fixed events with explicitly overridden parent spans being
  formatted  as though they were children of the current span (#767)

### Added

- **fmt**: Added the option to print synthesized events when spans are
  created, entered, exited, and closed, including span durations (#761)
- Documentation clarification and improvement (#762, #769)

Thanks to @rkuhn, @greenwoodcm, and @Ralith for contributing to this
release!

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
2020-07-01 09:43:54 -07:00
Eliza Weisman
971a46b46d subscriber: prepare to release 0.2.6 (#757)
Fixed

- **fmt**: Fixed an issue in the JSON formatter where using
  `Span::record` would result in malformed spans (#709)

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
2020-06-19 09:55:47 -07:00
Jane Lusby
02b7c4c028 docs: add tracing-error, tracing-flame, and eyre to related crates (#728)
* Add related crates for tracing-error

* boop

* boop
2020-05-23 11:58:47 -07:00
Jane Lusby
4e47811988 update readmes for flame and error (#695) 2020-05-04 10:28:50 -07:00
Eliza Weisman
351ac21809 subscriber: prepare to release 0.2.4 (#666)
# 0.2.4 (April 6, 2020)

This release includes several API ergonomics improvements, including
shorthand constructors for many types, and an extension trait for
initializing subscribers using method-chaining style. Additionally,
several bugs in less commonly used `fmt` APIs were fixed.

### Added

- **fmt**: Shorthand free functions for constructing most types in `fmt`
  (including `tracing_subscriber::fmt()` to return a
  `SubscriberBuilder`, `tracing_subscriber::fmt::layer()` to return a
  format `Layer`, etc) (#660)
- **registry**: Shorthand free function `tracing_subscriber::registry()`
  to construct a new registry (#660)
- Added `SubscriberInitExt` extension trait for more ergonomic
  subscriber initialization (#660)
  
### Changed

- **fmt**: Moved `LayerBuilder` methods to `Layer` (#655)

### Deprecated

- **fmt**: `LayerBuilder`, as `Layer` now implements all builder methods
  (#655)
  
### Fixed

- **fmt**: Fixed `Compact` formatter not omitting levels with
  `with_level(false)` (#657)
- **fmt**: Fixed `fmt::Layer` duplicating the fields for a new span if
  another layer has already formatted its fields (#634)
- **fmt**: Added missing space when using `record` to add new fields to
  a span that already has fields (#659)
- Updated outdated documentation (#647)


Signed-off-by: Eliza Weisman <eliza@buoyant.io>
2020-04-06 10:21:48 -07:00
Jane Lusby
3ec041a9a3 error: fix example of using TracedError with error kind pattern (#635) 2020-03-13 14:33:51 -07:00
Eliza Weisman
58291b5dca error: Bump minimum version for tracing dep (#626)
## Motivation

tracing-error's ErrorLayer depends upon subscriber changes that were
introduced in tracing "0.1.12" and depending on tracing = "0.1" allows
it to select versions that will not compile.
2020-03-05 16:09:07 -08:00
Eliza Weisman
83886fcc7c subscriber: prepare to release 0.2.3 (#625)
# 0.2.3 (March 5, 2020)

### Fixed

- **env-filter**: Regression where filter directives were selected in the order
  they were listed, rather than most specific first (#624)

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
2020-03-05 14:49:52 -08:00
Eliza Weisman
a0adec01b8 error: prepare to release 0.1.2 (#621)
### Added

- **TracedError**: `TracedError`, an error type wrapper that annotates
  an error with the current span.
- **SpanTrace**:`SpanTrace::status` method and `SpanTraceStatus` type
  for determing whether a `SpanTrace` was successfully captured (#614)

### Changed

- **SpanTrace**: Made backtrace formatting more consistent with upstream
  changes to `std::backtrace` (#584)

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
2020-03-04 10:21:46 -08:00
Jane Lusby
f58fb21fe7 Only export the generic traced error version (#619)
This removes the boxed error type in favor of only exposing the generic error type and gates it behind a default-enabled feature flag.
2020-03-02 22:23:49 -08:00
Jane Lusby
b9c415ab4a Fix receiver type to avoid a reborrow (#617)
## Motivation

The current impl for `ExtractSpanTrace` is implemented for references and takes &self as its receiver type, which causes it to reborrow the error and the lifetime of the returned SpanTrace is tied to this new borrow. This prevents the SpanTrace from outliving the borrow created from the `span_trace` call which functionally means you cannot return references to the borrowed `SpanTrace`s

## Solution

This changes the receiver type from `&dyn Error` to `dyn Error` so that the `&` in the `&self` pattern ends up matching against the original borrow, which could be a borrow that was passed in from another function, which lets us use the longer lifetime as the lifetime for the reference to the SpanTrace.
2020-02-28 19:05:58 -08:00
Jane Lusby
6b1c5a8605 Add a status fn to SpanTrace (#614)
## Motivation

Because `SpanTrace` does not have a header, implementations that wish to print a `SpanTrace` must print their own header before printing the `SpanTrace` itself. When the `SpanTrace` is empty this ends up inserting a header with no content after it, and the only way to avoid this via the current API is to `to_string` the `SpanTrace` prior to printing the header to check if `SpanTrace` would print any content.

## Solution

This change adds a `SpanTrace::status()` fn and accompanying `SpanTraceStatus` enum type to indicate to the user what will be printed if anything when the user attempts to display/debug print the `SpanTrace`.
2020-02-28 18:49:09 -08:00
Lucio Franco
77e589906d subscriber: Prepare 0.2.2 release (#609)
### Added

- **fmt**: Added `flatten_event` to `SubscriberBuilder` (#599)
- **fmt**: Added `with_level` to `SubscriberBuilder` (#594)

Signed-off-by: Lucio Franco <luciofranco14@gmail.com>
2020-02-27 16:13:29 -08:00
Jane Lusby
503d93605d error: add error instrumentation type and traits (#574)
## Motivation

The tracing_error crate should provide some basic functionality for
instrumenting Errors with `SpanTraces` generically. The goal is to make
it easy for users to instrument their errors without needing to add a
`SpanTrace` to every error they construct.

## Solution

Critically this trait provides 3 traits for instrumenting errors,
`InstrumentResult`, `InstrumentError`, and `ExtractSpanTrace`. The first
two traits expose a `in_current_span()` method that can work on a
`Result<T, E: InstrumentError>` and an `Error`, respectively, that wraps
the error type in a `TracedError` that stores the inner error and a
SpanTrace. The third trait, `ExtractSpanTrace`, is used to retrieve the
span_trace member of a `TracedError` from a `&dyn Error` trait object.

This is done by downcasting the error to a `TracedError` and returning
the inner `span_trace` if it is successful. By default this only works
because the inner error is stored in a Box as a trait object, which
prevents it from being part of the type signature for `TracedError`.

However, this crate also exposes a second version of `TracedError` that
does not box the inner error, thus avoiding the need for heap
allocation, which it accomplishes by type erasing the `TracedError<E>`
into a `TracedError<()>` while iterating through the error `source()`
chain.
2020-02-24 16:00:10 -08:00
Eliza Weisman
b8a1d40287 docs: fix broken and unresolvable links (#595)
This commit fixes several RustDoc links which were either broken
(without references) or had unresolvable references.

It looks like nightly RustDoc has recently gotten much smarter about
finding links that were unresolvable. These had always been broken, but
they used to silently 404. Now, the nightly build of RustDoc will emit a
warning, which we deny, causing the build to fail. This should fix CI
(as well as actually fixing the wrong links).

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
2020-02-21 15:05:49 -08:00
Eliza Weisman
4dad420ee1 subscriber: prepare to release 0.2.1 (#586)
### Changed

- **filter**: `EnvFilter` directive selection now behaves correctly
  (i.e. like `env_logger`) (#583)

### Fixed

- **filter**: Fixed `EnvFilter` incorrectly allowing less-specific
  filter directives to enable events that are disabled by more-specific
  filters (#583)
- **filter**: Multiple significant `EnvFilter`  performance
  improvements, especially when filtering events generated by `log`
  records (#578, #583)
- **filter**: Replaced `BTreeMap` with `Vec` in `DirectiveSet`,
  improving iteration performance significantly with typical numbers of
  filter directives (#580)

A big thank-you to @samschlegel for lots of help with `EnvFilter` 
performance tuning in this release!

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
2020-02-14 10:56:03 -08:00
Jane Lusby
d1416f17c1 Match changes to std::Backtrace output format (#584)
This PR changes the SpanTrace display format so that it no longer outputs a header prior to the output of the spans, and it changes the debug format to add one without newlines and support pretty formatting when formatting with `{:#?}`. These changes match recent changes made to the format of std::backtrace::Backtrace.
2020-02-13 15:06:22 -08:00