126 Commits

Author SHA1 Message Date
Christopher Durham
44d9ee3650 chore: fix minimal-versions correctness (#2231)
## Motivation

Fix minimal-versions failure.

## Solution

Upgrade all the dependencies to their most recent semver-compatible
version, adjusting back down as necessary for MSRV.

## Context

[cargo-minimal-versions](https://lib.rs/crates/cargo-minimal-versions)
is wonderful. With this PR, the full repo passes under all of

- `cargo hack --workspace minimal-versions check --all-features`
- `cargo +1.49 hack --workspace --exclude tracing-appender
  minimal-versions check --all-features`
- `cargo +1.53 hack -p tracing-appender minimal-versions check
  --all-features`
- All of CI 😇
2022-07-20 11:19:39 -07:00
Bryan Garza
388fff8371 opentelemetry: add more comments to example (#2140)
This patch adds a bit more context around why we are creating a smaller
scope for the spans, and also what happens when we call
`global::shutdown_tracer_provider()` (that comment was copied from
the`rust-opentelemetry` repo).

Co-authored-by: Eliza Weisman <eliza@buoyant.io>
2022-06-06 18:53:01 +00:00
zz
fbfef9c9ca fix opentelemetry example (#2110)
Co-authored-by: Bryan Garza <1396101+bryangarza@users.noreply.github.com>
2022-05-10 00:13:29 +00:00
Lily Ballard
c4bcf5c2c4 core: impl Value for dyn Error + Send/Sync (#2066)
## Motivation

`Value` was already implemented for `dyn Error + 'static`, but rust
doesn't silently coerce trait objects. This means that passing an error
of type `dyn Error + Send + Sync + 'static` would not work. This is
related to #1308.

## Solution

Add impls for `dyn Error + …` variants for `Send`, `Sync`, and `Send +
Sync`. These extra impls just delegate to the existing `dyn Error +
'static` impl.

Also update one of the examples to use `dyn Error + Send + Sync` to
demonstrate that this works.

Refs: #1308
2022-04-11 22:42:00 +00:00
dependabot[bot]
45008da959 build(deps): update inferno requirement from 0.10.0 to 0.11.0 (#1966)
Updates the requirements on [inferno](https://github.com/jonhoo/inferno) to permit the latest version.
- [Release notes](https://github.com/jonhoo/inferno/releases)
- [Changelog](https://github.com/jonhoo/inferno/blob/master/CHANGELOG.md)
- [Commits](https://github.com/jonhoo/inferno/compare/v0.10.0...v0.11.0)

---
updated-dependencies:
- dependency-name: inferno
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-03-04 13:58:28 -08: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
Julian Tescher
e005548bfc opentelemetry: Update otel to 0.17.0 (#1853)
## Motivation

Support the latest OpenTelemetry specification.

## Solution

Update `opentelemetry` to the latest `0.17.x` release. Breaking changes
upstream in the tracking of parent contexts in otel's `SpanBuilder` have
necessitated a new `OtelData` struct to continue pairing tracing spans
with their associated otel `Context`.
2022-01-27 19:13:00 +00:00
Renê Couto e Silva
6f23c128fc subscriber: add Format::with_file and with_line_number (#1773)
## Motivation

Logging line numbers and file names can be useful for debugging. This
feature was suggested by #1326

## Solution

As per @hawkw's suggestions, fields were added on `Format`, along with
builder methods. Filename and line number information was gathered from
the `meta` variable.

The `Pretty` formatter already supports printing source locations, but
this is configured separately on the `Pretty` formatter rather than on
the `Format` type. This branch also changes `Pretty` to honor the
`Format`-level configurations and deprecates the `Pretty`-specific
method.

Fixes #1326 Closes #1804

Co-authored-by: David Barsky <me@davidbarsky.com>
Co-authored-by: Eliza Weisman <eliza@buoyant.io>
2022-01-14 09:30:28 -08:00
Eliza Weisman
6dd9d236fa appender: impl MakeWriter for RollingFileAppender (#1760)
## Motivation

Currently, `tracing-appender`'s `RollingFileAppender` does not implement
the `MakeWriter` trait. This means it can only be used by either
wrapping it in `NonBlocking`, or by wrapping it in a `Mutex`. However,
this shouldn't be strictly necessary, as `&File` implements `io::Write`.
It should thus only be necessary to introduce locking when we are in the
process of _rotating_ the log file.

## Solution

This branch adds a `MakeWriter` implementation for
`RollingFileAppender`. This is done by moving the file itself inside of
an `RwLock`, so that a read lock is acquired to write to the file. This
allows multiple threads to write to the file without contention. When
the file needs to be rolled, the rolling thread acquires the write lock
to replace the file. Acquiring the write lock is guarded by an atomic
CAS on the timestamp, so that only a single thread will try to roll the
file. This prevents other threads from immediately rolling the file
_again_ when the write lock is released.

I...should probably write tests for that, though.

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
2021-12-17 14:50:51 -08:00
Folyd
a36cb8f7ea chore: fix cargo MSRV field typo (#1742) 2021-11-23 15:07:29 -05:00
walfie
500021c46c chore: Fix typos (#1740) 2021-11-22 12:17:10 -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
545fc18f8b subscriber: reduce default features (#1647)
This changes `tracing-subscriber` so that the `env-filter`, `json`,
 and `chrono` features are not enabled by default, and instead require
users to opt in. This should significantly reduce the default
dependency footprint.

Of course, this is a breaking change, and therefore will be part of
`tracing-subscriber` v0.3.

Fixes #1258

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
2021-10-18 16:32:52 -07:00
Eliza Weisman
6614b2f9ed subscriber: replace chrono with time for timestamp formatting (#1646)
## Motivation

Currently, `tracing-subscriber` supports the `chrono` crate for
timestamp formatting, via a default-on feature flag. When this code was
initially added to `tracing-subscriber`, the `time` crate did not have
support for the timestamp formatting options we needed.

Unfortunately, the `chrono` crate's maintainance status is now in
question (see #1598). Furthermore, `chrono` depends on version 0.1 of
the `time` crate, which contains a security vulnerability
(https://rustsec.org/advisories/RUSTSEC-2020-0071.html). This
vulnerability is fixed in more recent releases of `time`, but `chrono`
still uses v0.1.

## Solution

Fortunately, the `time` crate now has its own timestamp formatting
support.

This branch replaces the `ChronoLocal` and `ChronoUtc` timestamp
formatters with new `LocalTime` and `UtcTime` formatters. These
formatters use the `time` crate's formatting APIs rather than
`chrono`'s. This removes the vulnerable dependency on `time` 0.1

Additionally, the new `time` APIs are feature flagged as an _opt-in_
feature, rather than as an _opt-out_ feature. This should make it easier
to avoid accidentally depending on the `time` crate when more
sophisticated timestamp formatting is _not_ required.

In a follow-up branch, we could also add support for `humantime` as an
option for timestamp formatting.

Naturally, since this removes existing APIs, this is a breaking change,
and will thus require publishing `tracing-subscriber` 0.3. We'll want to
do some other breaking changes as well.

Fixes #1598.
2021-10-18 13:42:44 -07:00
Eliza Weisman
ee8fd2876d examples: add tokio_panic_hook example (#1593)
It turns out panic hooks also work nicely even when panics are captured.
I figured we may as well have an example demoing this!
2021-09-24 12:15:43 -07:00
Eliza Weisman
8817e407d7 tracing: add Span::or_current to help with efficient propagation (#1538)
This adds a new `Span::or_current` method that returns the span it's
called on, if that span is enabled, or the current span if that span
is not enabled.

This should provide a more efficient alternative to writing code like
```rust
tokio::spawn(
    future
        .instrument(some_span)
        .in_current_span()
);
```
since it doesn't wrap the future in two different spans which are
(potentially) both entered on polls. It's also a little more concise
to write, which (hopefully) will encourage people to use it instead
of the less efficient alternative.

`Span::or_current` may be useful in other cases as well.

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
2021-09-04 11:15:58 -07:00
Eliza Weisman
cdde7c770e examples: use tempfile infmt-multiple-writers
Whoops, this example _also_ uses `tempdir`. My bad!

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
2021-08-16 14:10:12 -07:00
Eliza Weisman
f013913c89 examples: use tempfile in inferno-flame
This commit updates the `inferno-flame` example to use the `tempfile`
crate as a replacement
for the unmaintained `tempdir` crate.

Also, the previous version of the example output the flamegraph inside
the temporary directory. Since the temporary directory is cleaned up
when the program exits, this means the user can't actually look at the
flamegraph when running this example. I've changed the example to put the
flamegraph in the current working dir instead, so the user can look at
it.

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
2021-08-16 14:10:12 -07:00
Eliza Weisman
81aa1584fb examples: bump hyper dep to 0.14.11
This version includes patches for a couple of RUSTSEC advisories that
`cargo audit` is mad about. These aren't actually security-critical,
since the affected hyper versions are only used in examples, not in
actual`tracing` crates, but bumping makes `cargo audit` chill out. And
we should keep up to date regardless.

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
2021-08-16 14:10:12 -07:00
Eliza Weisman
340cfd7678 examples: use argh instead of clap
Currently, there are a few examples that include CLI argument parsing.
These currently use the `clap` crate. `clap` is one of the most flexible
and full-featured argument parsing libraries in Rust. However, or
perhaps *because* of this, `clap` is also a fairly heavy-weight
dependency which pulls in a lot of transitive deps.

We don't *need* most of `clap`'s features for the very simple argument
parsing in these examples. Therefore, this commit replaces `clap` with
`argh`, which is a much lighter dependency.

Also, `clap` is currently pulling a version of `bitflags` that breaks
our MSRV...

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
2021-08-16 14:10:12 -07:00
Julian Tescher
35f3d6e51d opentelemetry: update to otel v0.16.x (#1497)
Updates to the latest otel spec version and addresses small internal
method and module updates.
2021-08-07 14:39:26 -07:00
Teo Klestrup Röijezon
c307e2a9e9 subscriber::fmt: print all error sources (#1496)
Forward-port of #1460 to the 0.2.x (master) branch.

## Motivation

Fixes #1347  

## Solution

Change the format from `err=message, err: source1` to `err=message
err.sources=[source1, source2, source3, ...]`, as suggested in
#1347 (comment)
(still leaving out the sources if there are none). 

## Caveats

Haven't changed the JSON formatter, since I'm not really sure about how
to do that. The current format is `{.., "fields": {.., "err":
"message"}}`, disregarding the sources entirely. 

We could change that to `{.., "fields": {.., "err": "message",
"err.sources": ["source1", "source2", "source3", ..]}}`, which would
keep backwards compatibility but looks pretty ugly.

Another option would be `{.., "fields": {.., "err": {"message":
"message", "sources": ["source1", "source2", "source3", ..]}}}` which
leaves room for future expansion.

Then again, that begs the question about why the first error is special,
so maybe it ought to be `{.., "fields": {.., "err": {"message":
"message", "source": {"message": "source1", "source": ..}}}}`.

But that style of linked list is pretty annoying to parse, so maybe it
ought to be flattened to `{.., "fields": {.., "err": [{"message":
"message"}, {"message": "source1"}, ..]}}`?

Co-authored-by: Eliza Weisman <eliza@buoyant.io>
2021-08-07 13:54:14 -07:00
Eliza Weisman
e0db056306 chore: fix a giant pile of annoying clippy lints (#1486)
Clippy added a new lint detecting unnecessary borrows in expressions
where the borrowed thing is already a reference...which is nice, and
all, but the downside is that now we have to fix this.

This PR fixes it.
2021-08-01 07:16:55 -07:00
Eliza Weisman
4af08fac6c chore: fix new clippy warnings (#1444)
This fixes a handful of new clippy lints. Should fix CI.

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
2021-06-23 10:37:38 -07:00
Kirill Mironov
13e398d085 opentelemetry: update opentelemetry to 0.15
## Motivation

Newest versions of opentelemetry and opentelemetry-jaeger don't work
with the tracing-opentelemtry due to the latter still depending on a
0.14 version.

## Solution

Adjust dependencies and use new TraceFlags struct instead of constants
2021-06-21 11:53:45 -07:00
Ole Schönburg
944abacb2d core: Remove default impl of Collect::current_span (#1268)
- Removes the default implementation.
- Makes tracing_core::span::Current::unknown public so that implementers
of Collect can use it if they didn't implement current_span() before.
- Copy the old default implementation to all implementers of Collect.

Co-authored-by: Eliza Weisman <eliza@buoyant.io>
2021-06-21 12:14:44 -04:00
Jonas Platte
44d355800f subscriber: Stop using prelude imports in doctests (#1422)
## Motivation

I dislike using `*` imports in my code, so I'm not using prelude modules
provided by libraries. With the way the examples in the
`tracing-subscriber` docs are currently set up, there is no hint on
where some methods are coming from. Just removing the prelude import
unfortunately doesn't lead to a solution. The compiler prefers the
prelude re-export:

```
    = help: items from traits can only be used if the trait is in scope
help: the following trait is implemented but not in scope; perhaps add a `use` for it:
    |
3   | use crate::tracing_subscriber::prelude::__tracing_subscriber_SubscriberExt;
    |
```

## Solution

Use the traits directly in the documentation examples.

Since the compiler hints around this are currently very bad, it's good
to have a hint where methods in doc examples could come from in there,
for users who prefer not using the prelude.
2021-06-07 10:15:01 -07:00
Julian Tescher
bee0d48237 opentelemetry: update to otel 0.14.x (#1394)
## Motivation

Support the latest OpenTelemetry specification.

## Solution

Update `opentelemetry` to the latest `0.14.x` release. Despite breaking
changes upstream, no additional public API or behavioral changes are
necessary in `tracing-opentelemetry`, but simplifications in the
propagation of span information have removed the need for the current
internal `CompatSpan` and custom parent context construction.

Performance has improved by ~30% on current benchmarks.
2021-05-15 14:27:17 -04:00
Eliza Weisman
7fc6a06048 tracing: add an example of tracing in a panic hook (#1375)
It turns out that when using the global dispatcher, emitting tracing
events in a panic hook will capture the span in which the program
panicked. This is very handy for debugging panics! Thanks a lot to
@nate_mara for pointing this out to me on twitter --- I hadn't even
thought of it!

Since it isn't necessarily immediately obvious that this works, I
thought it would be nice to add an example.
2021-04-28 15:15:21 -07:00
Julian Tescher
6c7ce6389c opentelemetry: support otel 0.13.0 (#1322)
* opentelemetry: support otel 0.13.0

Switches to `Cow<'static, str>` for otel event names and updates docs to
show simplified install methods.

Resolves #1323, resolves #1324

* Add simple vs batch comment

Co-authored-by: Eliza Weisman <eliza@buoyant.io>
2021-03-29 16:33:31 -07:00
Folyd
b9f722ff71 opentelemetry: rename Layer to Subscriber (#1226) 2021-03-10 14:41:59 -05:00
Folyd
fe59f77203 chore: rename layers to subscribers and fix some typos (#1272) 2021-03-04 13:26:26 -05:00
Folyd
82363a7e32 examples: rename the rest of the legacy subscribers to collectors (#1265)
Yeah, another renaming PR. Hahaha ^-^
2021-02-25 10:21:30 -08:00
Alan Somers
fa109679ed examples: fix some comments in the examples (#1235)
## Motivation

Fixes some comments in the tracing examples, making it easier
to copy/paste into a terminal.
2021-02-12 09:44:03 -08:00
David Barsky
7f6acc5b7e examples: update Tokio to 1.0 (#1213)
Not sure that there's a issue tracking this, but anyways. Here's an
update to Tokio 1.0!

This closes the various Dependabot dependency update PRs that we can't
just merge due to breaking changes.

Closes #1149
Closes #1164
Closes #1177

Co-authored-by: Eliza Weisman <eliza@buoyant.io>
2021-01-30 13:43:07 -08:00
Julian Tescher
93a2d287a3 opentelemetry: update to otel v0.12.x (#1200) 2021-01-25 11:19:42 -08:00
Julian Tescher
705613c3ef opentelemetry: update to otel v0.11.x (#1161)
## Motivation

Support the latest OpenTelemetry specification

## Solution

In order to support the latest spec, this patch makes the following
breaking API changes:

* Update `opentelemetry` to 0.11.x
* Update `OpenTelemetrySpanExt::set_parent` to take a context by value
  as it is now stored and propagated.
* Rename `PreSampledTracer::sampled_span_context` to
  `PreSampledTracer::sampled_context` as it now returns a full otel
  context

Additionally the following doc and example changes:

* Show w3c trace context propagator as recommendation in examples
2020-12-29 17:31:20 -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
David Barsky
48c415fcef examples: add fmt-multiple-writers.rs (#1106)
This PR:

* Adds an example demonstrating how `fmt::Subscriber` can be used to write to stdout and a file simultaneously.
* Removes a few mentions of "Layers" in the examples directory; opting for "Subscribers" instead.

Resolves #1091
2020-11-21 09:52:40 -08:00
Alan D. Salewski
b3c1e0eb8d subscriber: rename trait CollectorExt to CollectExt (#1115)
The trait being augmented is the 'Collect' trait, so name the trait
that extends should be called 'CollectExt'.

This is in keeping with the extension trait naming conventions
documented in RFC 445 and the spirit of the discussion in
tokio-rs/tracing PR #1015.
2020-11-20 21:11:08 -05:00
David Barsky
0d661b6160 examples: fix echo example by reintroducing concurrency (#1107) 2020-11-17 11:29:51 -05:00
Julian Tescher
4f7356100f opentelemetry: update to latest otel release version (#1049)
## Motivation

Support the latest OpenTelemetry specification

## Solution

In order to support the latest spec, this patch makes the following
breaking API changes:

* Update `opentelemetry` to 0.10.x
* Update `CompatSpan` to reflect changes to `Span` trait
* Record `u64` values as strings as they are no longer supported in 
  OpenTelemetry.

Additionally the following non-public api, doc, and example changes:

* Update examples and docs to use new simplified pipeline builder.
* As `opentelemetry::api` no longer exports trace types, internally use
`opentelemetry::trace as otel` to disambiguate from tracing types.
* Remove `rand` dependency as it is no longer needed

Co-authored-by: Eliza Weisman <eliza@buoyant.io>
2020-11-12 14:20:35 -08: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
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
Eliza Weisman
70d55afba0 subscriber: make Compact formatter not be useless (#1069)
Depends on #1067 

## Motivation

Currently, the `Compact` event formatter in `tracing-subscriber`
is...kind of bad, and nobody seems to use it. It outputs the names of
all the spans in the current context, and (inexplicably) the _names_ of
all the fields on the current span, but not their values. This isn't
very useful.

## Solution

This branch rewrites the `Compact` formatter to be a little less bad.
Now, we output all the fields from the current span context, but skip
span names, and we shorten the level to a single character when it's
enabled. Additionally, using the `compact` formatter disables targets by
default. Now, the lines are nicely short, but maybe still useful.

Example output before this change:
![Screenshot_20201024_122857](https://user-images.githubusercontent.com/2796466/97093422-a2ad2780-1600-11eb-94bf-ee13011a3e73.png)
...and after:
![Screenshot_20201024_133352](https://user-images.githubusercontent.com/2796466/97093410-8e692a80-1600-11eb-9b42-1aefa1725957.png)

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
2020-10-26 14:05:29 -07:00
Eliza Weisman
bd8c6da0ce subscriber: add Pretty formatter (#1067)
## Motivation

Currently, the `tracing_subscriber::fmt` module contains only
single-line event formatters. Some users have requested a
human-readable, pretty-printing event formatter optimized for
aesthetics.

## Solution

This branch adds a new `Pretty` formatter which uses an _excessively_
pretty output format. It's neither compact, single-line oriented, nor
easily machine-readable, but it looks _quite_ nice, in my opinion. This
is well suited for local development or potentially for user-facing logs
in a CLI application.

Additionally, I tried to improve the docs for the different formatters
currently provided, including example output. Check out [the Netlify
preview][1]!

[1]: https://deploy-preview-1067--tracing-rs.netlify.app/tracing_subscriber/fmt/index.html#formatters

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
2020-10-26 10:11:59 -07: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
dependabot-preview[bot]
499d3da19c chore(deps): update env_logger requirement from 0.7 to 0.8 (#1050)
Updates the requirements on [env_logger](https://github.com/env-logger-rs/env_logger) to permit the latest version.
- [Release notes](https://github.com/env-logger-rs/env_logger/releases)
- [Changelog](https://github.com/env-logger-rs/env_logger/blob/master/CHANGELOG.md)
- [Commits](https://github.com/env-logger-rs/env_logger/compare/v0.7.0...v0.8.1)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
2020-10-19 15:46:18 -07:00
Eliza Weisman
83760225fa subscriber: fix reload ergonomics (#1035)
## Motivation

Currently, the `reload` layer is generic over both the type of the layer
being reloaded, *and* the type of the subscriber that the layer is
layered onto. This means that the `reload::Handle` type that's used to
reload the value of the layer *also* is parameterized over the
subscriber's type.

The subscriber type parameter makes the `reload` API significantly
harder to use. Any time a `reload::Handle` is returned by a function,
taken as an argument, or stored in a struct, the full type of the
subscriber under the layer must be written out --- and often, it is
quite long. What makes this worse is that sometimes the type of the
subscriber may vary at runtime based on some configuration, while the
type of the layer that's reloaded remains the same. For example, in
Linkerd, we've had to do [this][1], which is really not ideal.

## Solution

This branch removes the `Subscriber` type parameter from `reload::Layer`
and `reload::Handle`. Now, the `Handle` type is only generic over the
type of the inner layer that's being reloaded. It turns out that the
`Subscriber` type parameter was only necessary to add a `L: Layer<S>`
bound to `reload::Layer`'s constructor, which isn't really necessary ---
if the layer does not implement `Layer<S>`, the type error will occur
when `Subscriber::with` is actually used to layer it, which is fine.

I also changed the `with_filter_reloading` option on the `FmtSubscriber`
builder to also work with `LevelFilter`s, since there's no reason for it
not to, and added an example.

Since this breaks existing code, this change has to be made as part of
0.3.

[1]: 6c484f6dcd/linkerd/app/core/src/trace.rs (L19-L36)
2020-10-13 14:47:49 -07:00
Eliza Weisman
515255fe4f tracing: make Entered !Send (#1001)
## Motivation

The `Entered` guard returned by `Span::enter` represents entering and
exiting a span _on the current thread_. Calling `Span::enter` enters the
span, returning an `Entered`, and dropping the `Entered` ensures that
the span is exited. This ensures that all spans, once entered, are
eventually exited.

However, `Entered` has an auto-impl of `Send`, because it doesn't
contain any `!Send` types. This means that the `Entered` guard _could_
be sent to another thread and dropped. This would cause the original
thread to never exit the span,. and the thread to which the `Entered`
guard was sent would exit a span that it never observed an enter for.
This is incorrect.

## Solution

This PR adds a `*mut ()` field to `Entered` so that it no longer
implements `Send`. There's now a manual `Sync` impl so structs holding
an `Entered` can still be `Sync`.

Fixes #698

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
2020-09-30 09:44:54 -07:00