113 Commits

Author SHA1 Message Date
dependabot[bot]
7f39eadf40 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-08 14:14:38 -08:00
Eliza Weisman
e5921bacdc
docs: update Compact formatter docs (#1926)
## Motivation

Currently, the RustDoc for the `format::Compact` formatter in
`tracing-subscriber` describes the output from the `master` (v0.2.x)
version of the formatter, not the version on the v0.1.x branch.

## Solution

This PR updates the documentation to describe the actual output format.
Also, I added an example of the formatter in the `examples` directory.

Closes #1909
2022-02-15 10:56:14 -08:00
Eliza Weisman
32225276a9 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 15:39:26 -08:00
Eliza Weisman
bfd6802570
subscriber, serde: add valuable support to the JSON formatter (#1862)
This branch introduces support for `valuable` in `tracing-subscriber`'s
JSON formatter, and in `tracing-serde`, using the `valuable-serde`
bridge.

This allows the `fmt::Json` subscriber to actually record `valuable`
values as structured JSON. Here's an example, where a field is first
recorded using `fmt::Debug`, and then again using `field::valuable`:

```
:; RUSTFLAGS="--cfg tracing_unstable" cargo run --example valuable_json | jq
    Finished dev [unoptimized + debuginfo] target(s) in 0.09s
     Running `target/debug/examples/valuable_json`
{
  "timestamp": "2022-01-25T21:36:30.729658Z",
  "level": "INFO",
  "fields": {
    "valuable": false,
    "user": "User { name: \"Arwen Undomiel\", age: 3000, address: Address { country: \"Middle Earth\", city: \"Rivendell\", street: \"leafy lane\" } }"
  },
  "target": "valuable_json"
}
{
  "timestamp": "2022-01-25T21:36:30.729720Z",
  "level": "INFO",
  "fields": {
    "valuable": true,
    "user": {
      "name": "Arwen Undomiel",
      "age": 3000,
      "address": {
        "country": "Middle Earth",
        "city": "Rivendell",
        "street": "leafy lane"
      }
    }
  },
  "target": "valuable_json"
}
```

As a side note, this branch also nicely validates that recording `Valuable`
values from a subscriber is actually possible, which the previous valuable PR
didn't have an example of. 

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
2022-02-03 22:27:41 +00:00
Eliza Weisman
1a9ee003ce
ci: add tracing_unstable to CI (#1894)
* ci: add `tracing_unstable` to CI

Currently, the `valuable` support requires the `tracing_unstable` cfg to
be set. Because none of our current CI jobs set this, we aren't
currently testing that code, and have no way of even ensuring that it
compiles. This is Bad.

This PR adds a CI job to run tests with the unstable cfg enabled.

* core: fix wrong `self` types with `valuable`

This should fix the build.

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
2022-02-03 13:50:58 -08:00
Julian Tescher
3bf5fc24ca 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`.
# Conflicts:
#	.github/workflows/check_msrv.yml
#	tracing-opentelemetry/Cargo.toml
#	tracing-opentelemetry/benches/trace.rs
#	tracing-opentelemetry/src/layer.rs
#	tracing-opentelemetry/src/span_ext.rs
#	tracing-opentelemetry/tests/trace_state_propagation.rs
2022-02-03 10:54:08 -08:00
Eliza Weisman
532b61c7b6
core: record Valuable values as valuable::Value (#1881)
This changes the `valuable` integration so that `record_value` takes
instances of `valuable::Value<'_>`, rather than `&dyn
valuable::Valuable` trait objects. The primary advantage of this is that
a `Value` can be produced by calling `Valuable::as_value`, so it allows
users to write code like this:

```rust
#[derive(Valuable, Debug)]
struct Foo {
    // ...
}

tracing::trace!(foo = foo.as_value());
```

rather than this:

```rust
#[derive(Valuable, Debug)]
struct Foo {
    // ...
}

tracing::trace!(foo = tracing::field::valuable(&foo));
```

which feels a bit more ergonomic. It also simplifies the code in
`tracing-core`, since we no longer need our own `ValuableValue` wrapper
type to turn things into trait objects.

It might also reduce boilerplate a bit on the visitor side, as
`as_value()` doesn't have to be called on the trait object, although
that's probably not as big a deal.

I didn't remove the `field::valuable` function, as I thought it was nice
to have for consistency with the existing `field::debug` and
`field::display` functions.

## Performance Considerations

@carllerche pointed out that a `Value<'_>` might be slightly more bytes
to pass on the stack than a trait object (always two words). I believe
this is only the case when the `Value` is a `Listable`, `Enumerable`,
`Structable`, `Mappable`, or `Tupleable`, where the `Value` would be an
enum descriminant _and_ a wide pointer to a trait object. However, in
the cases where the value is a primitive, `Value` will be two words if
the primitive is word-sized (e.g. `u64` on 64-bit platforms), for the
enum descriminant + the value, or one word if the primitive is smaller
than word size (`bool`, `char`, etc). Also, for primitive `Value`s,
there's no pointer dereference, which the trait object always requires.

I'm not sure how the enum dispatch compares to vtable dispatch when
calling `visit` on the value. However, if the `tracing` visitor is going
to call `as_value()` on the recorded value, this approach is better,
because calling `as_value()` in the macro _prior_ to recording the
span/event will use the statically dispatched `as_value()` impl on a
known type, rather than the the dynamically dispatched `as_value()` impl
on the trait object. Since `as_value` impls are generally quite trivial,
I'd guess they usually (always?) will get inlined, which is never
possible with the dynamically dispatched call after passing a trait
object into `tracing`.

In practice I'm not sure if there's a huge perf diff either way, but it
was interesting to think through the implications.
2022-02-02 22:07:44 +00:00
xd009642
5d08634501
core: add initial support for valuable field values (#1608)
This branch adds initial support for using the [`valuable`] crate as an
opt-in `Value` type in `tracing`. `valuable` provides a mechanism for
defining custom ways to record user-implemented types, as well as
structured recording of standard library data structures such as maps,
arrays, and sets.

For more details, see the tracking issue #1570.

In `tracing` v0.2, the intent is for `valuable` to replace the existing
`tracing_core::field::Value` trait. However, in v0.1.x, `valuable`
support must be added in a backwards-compatible way, so recording types
that implement `valuable::Valueable` currently requires opting in using
a `field::valuable` wrapper function.

Since this is the first release of `valuable` and the API is still
stabilizing, we don't want to tie `tracing-core`'s stability to
`valuable`'s. Therefore, the valuable dependency is feature-flagged
*and* also requires `RUSTFLAGS="--cfg tracing_unstable"`.

[`valuable`]: https://github.com/tokio-rs/valuable

Co-authored-by: Daniel McKenna <daniel@emotech.co>
Co-authored-by: David Barsky <me@davidbarsky.com>
Co-authored-by: Eliza Weisman <eliza@buoyant.io>
2022-01-21 21:29:38 +00:00
Renê Couto e Silva
35d177626b 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 12:12:09 -08:00
Eliza Weisman
fc52d45a0f 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-19 16:23:54 -08:00
Folyd
3a86d4810c chore: fix cargo MSRV field typo (#1742) 2021-11-23 13:50:24 -08:00
Eliza Weisman
e62e7165f4 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:57:37 -08:00
Eliza Weisman
aaa419b90a
appender: prepare to release v0.2.0 (#1678)
# 0.2.0 (October 22, 2021)

This breaking change release adds support for the new v0.3.x series of
`tracing-subscriber`. In addition, it resolves the security advisory for
the `chrono` crate, [RUSTSEC-2020-0159].

This release increases the minimum supported Rust version (MSRV) to
1.51.0.
### Breaking Changes

- Updated `tracing-subscriber` to v0.3.x ([#1677])
- Changed `NonBlocking::error_counter` to return an `ErrorCounter` type,
  rather than an `Arc<AtomicU64>` ([#1675])
  ### Changed

- Updated `tracing-subscriber` to v0.3.x ([#1677])
  ### Fixed

- **non-blocking**: Fixed compilation on 32-bit targets ([#1675])
- **rolling**: Replaced `chrono` dependency with `time` to resolve
  [RUSTSEC-2020-0159] ([#1652])
- **rolling**: Fixed an issue where `RollingFileAppender` would fail to
  print errors that occurred while flushing a previous logfile ([#1604])

Thanks to new contributors @dzvon and @zvkemp for contributing to this
release!

[RUSTSEC-2020-0159]: https://rustsec.org/advisories/RUSTSEC-2020-0159.html
[#1677]: https://github.com/tokio-rs/tracing/pull/1677
[#1675]: https://github.com/tokio-rs/tracing/pull/1675
[#1652]: https://github.com/tokio-rs/tracing/pull/1675
[#1604]: https://github.com/tokio-rs/tracing/pull/1604
2021-10-22 17:04:04 -07:00
Eliza Weisman
4e56741c65
subscriber: prepare to release v0.3.0 (#1677)
# 0.3.0 (Oct 22, 2021)

This is a breaking release of `tracing-subscriber`. The primary breaking
change in this release is the removal of the dependency on the [`chrono`
crate], due to [RUSTSEC-2020-0159]. To replace `chrono`, support is
added for formatting timestamps using the [`time` crate] instead.

In addition, this release includes a number of other breaking API
changes, such as adding (limited) support for `#![no_std]` targets,
removing previously deprecated APIs, and more.

### Breaking Changes

- Removed APIs deprecated in the v0.2.x release series.
- Renamed `Layer::new_span` to `Layer::on_new_span` ([#1674])
- Removed `Layer` impl for `Arc<L: Layer<S>>` and `Arc<dyn Layer<S> +
  ...>` ([#1649])
- Replaced the [`chrono` crate] with the [`time` crate] for timestamp
  formatting, to resolve [RUSTSEC-2020-0159] ([#1646])
- Removed `json` and `env-filter` from default features. They must now
  be enabled explictly ([#1647])
- Changed `FormatEvent::format_event` and `FormatFields::format_fields`
  trait methods to take a `Writer` type, rather than a `&mut dyn
  fmt::Write` trait object ([#1661])
- Changed the signature of the `MakeWriter` trait by adding a lifetime
  parameter ([#781])
  ### Changed

- **layer**: Renamed `Layer::new_span` to `Layer::on_new_span` ([#1674])
- **fmt**: Changed `FormatEvent::format_event` and
  `FormatFields::format_fields` trait methods to take a `Writer` type,
  rather than a `&mut dyn fmt::Write` trait object ([#1661])
- **json**, **env-filter**: `json` and `env-filter` feature flags are no
  longer enabled by default ([#1647])
  ### Removed

- Removed deprecated `CurrentSpan` type ([#1320])
- **registry**: Removed deprecated `SpanRef::parents` iterator, replaced
  by `SpanRef::scope` in [#1431] ([#1648)])
- **layer**: Removed deprecated `Context::scope` iterator, replaced by
  `Context::span_scope` and `Context::event_scope` in [#1431] and
  [#1434] ([#1648)])
- **layer**: Removed `Layer` impl for `Arc<L: Layer<S>>` and `Arc<dyn
  Layer<S> + ...>`. These interfere with per-layer filtering. ([#1649])
- **fmt**: Removed deprecated `LayerBuilder` type ([#1673])
- **fmt**: Removed `fmt::Layer::on_event` (renamed to
  `fmt::Layer::fmt_event`) ([#1673])
- **fmt**, **chrono**: Removed the `chrono` feature flag and APIs for
  using the [`chrono` crate] for timestamp formatting ([#1646])
  ### Added

- **fmt**, **time**: `LocalTime` and `UtcTime` types for formatting
  timestamps using the [`time` crate] ([#1646])
- **fmt**: Added a lifetime parameter to the `MakeWriter` trait,
  allowing it to return a borrowed writer. This enables implementations
  of `MakeWriter` for types such as `Mutex<T: io::Write>` and
  `std::fs::File`. ([#781])
- **env-filter**: Documentation improvements ([#1637])
- Support for some APIs on `#![no_std]` targets, by disabling the `std`
  feature flag ([#1660])

Thanks to @Folyd and @nmathewson for contributing to this release!

[#1320]: https://github.com/tokio-rs/tracing/pull/1320
[#1673]: https://github.com/tokio-rs/tracing/pull/1673
[#1674]: https://github.com/tokio-rs/tracing/pull/1674
[#1646]: https://github.com/tokio-rs/tracing/pull/1646
[#1647]: https://github.com/tokio-rs/tracing/pull/1647
[#1648]: https://github.com/tokio-rs/tracing/pull/1648
[#1649]: https://github.com/tokio-rs/tracing/pull/1649
[#1660]: https://github.com/tokio-rs/tracing/pull/1660
[#1661]: https://github.com/tokio-rs/tracing/pull/1661
[#1431]: https://github.com/tokio-rs/tracing/pull/1431
[#1434]: https://github.com/tokio-rs/tracing/pull/1434
[#781]: https://github.com/tokio-rs/tracing/pull/781

[`chrono` crate]: https://crates.io/crates/chrono
[`time` crate]: https://crates.io/crates/time
[RUSTSEC-2020-0159]: https://rustsec.org/advisories/RUSTSEC-2020-0159.html

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
2021-10-22 16:01:35 -07:00
Eliza Weisman
c8b91caa05 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-21 12:39:23 -07:00
Eliza Weisman
3634c9120f 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-21 12:39:23 -07:00
Eliza Weisman
4f9987dcd1 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-10-01 14:34:01 -07:00
Eliza Weisman
ac4a8dd27c chore: fix inconsistent terminology
I noticed a handful of places where `v0.1.x` refers to `Subscriber`s as
 "collectors". This probably happened because we backported some commits
 from master and forgot to change every instance of "collector" back to
 "subscriber".

 This commit fixes that. Whoops.

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
2021-09-04 11:57:42 -07:00
Eliza Weisman
978624e2c4 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:57:42 -07:00
Eliza Weisman
e6c53e649d 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 17:38:30 -07:00
Eliza Weisman
20e1588cfb 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 17:38:30 -07:00
Eliza Weisman
cc40b68ed0 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 17:38:30 -07:00
Eliza Weisman
f62c4d3826 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 17:38:30 -07:00
David Barsky
a766b70473 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-08-16 17:38:30 -07:00
Julian Tescher
8568a3010f
opentelemetry: update to otel v0.16.x (#1497) (#1500)
Updates to the latest otel spec version and addresses small internal
method and module updates.
2021-08-11 16:43:40 -04:00
Teo Klestrup Röijezon
aeae4fab32
subscriber::fmt: print all error sources (#1460)
## Motivation

Fixes #1347  

## Solution

Change the format from `err=message, err: source1` to `err=message
err.sources=[source1, source2, source3, ...]`, as suggested in
https://github.com/tokio-rs/tracing/issues/1347#issuecomment-813674313
(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-06 10:06:03 -07:00
Teo Klestrup Röijezon
5f0f5cc97e
chore: fix warnings introduced by Rustc 1.54 (#1495)
Split from #1460
2021-08-06 09:36:27 -07:00
Kirill Mironov
bc1c3a32ec opentelemetry: update opentelemetry to 0.15 (#1441)
This backports PR #1441 from `master`

## 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-25 17:01:47 -07:00
Teo Klestrup Röijezon
7a012603ea
subscriber: unify span traversal (#1431)
## Motivation

Fixes #1429 

## 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)
2021-06-22 10:33:42 -07:00
Julian Tescher
df95d06537
opentelemetry: update to otel 0.14.x (#1394) (#1403)
## 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-17 16:02:02 -07:00
Eliza Weisman
f9a3f17fbb 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-30 11:27:10 -07:00
Tim
bab71acb28
opentelemetry: support otel 0.13.0 (#1322) (#1330)
This backports #1322 from `master` to `v0.1.x`,

* opentelemetry: support otel 0.13.0

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

* Add simple vs batch comment

Co-authored-by: Julian Tescher <jatescher@gmail.com>
Co-authored-by: Eliza Weisman <eliza@buoyant.io>
2021-03-31 14:45:13 -07:00
Julian Tescher
1a1d5b01f8 opentelemetry: update to otel v0.12.x (#1200) 2021-01-26 10:08:31 -08:00
David Barsky
ea91df3662
examples: backport fmt-multiple-writers.rs to v0.1.0 branch (#1187)
It turns out that this example never existed on v0.1.x, which is my bad.

Resolves https://github.com/tokio-rs/tracing/issues/1179.
2021-01-12 15:46:45 -08:00
Julian Tescher
49b4a589bf
opentelemetry: update to otel v0.11.x (#1161) (#1162)
## 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-30 12:09:16 -08:00
Julian Tescher
642ad19d62
opentelemetry: update to latest otel release version (#1049) (#1099)
This backports  #1049, which was already approved on master.

## 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>
# Conflicts:
#	examples/examples/opentelemetry-remote-context.rs
#	tracing-opentelemetry/Cargo.toml
#	tracing-opentelemetry/src/layer.rs
#	tracing-opentelemetry/src/span_ext.rs
#	tracing-opentelemetry/src/tracer.rs
2020-11-13 12:16:22 -08:00
Eliza Weisman
8bdc6c367d
subscriber: add Pretty formatter (backports #1067) (#1080)
This backports PR #1067 to v0.1.x. Since this has already been approved
on master, I'm just going to go ahead and merge it when CI passes.

## 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-11-02 13:20:46 -08:00
Eliza Weisman
89418ee612
subscriber: prepare to release 0.2.13 (#1024)
### Changed

- Updated `tracing-core` to 0.1.17 ([#992])

### Added

- **env-filter**: Added support for filtering on targets which contain
  dashes ([#1014])
- **env-filter**: Added a warning when creating an `EnvFilter` that
  contains directives that would enable a level disabled by the
  `tracing` crate's `static_max_level` features ([#1021])

Thanks to @jyn514 and @bkchr for contributing to this release!

[#992]: https://github.com/tokio-rs/tracing/pull/992
[#1014]: https://github.com/tokio-rs/tracing/pull/1014
[#1021]: https://github.com/tokio-rs/tracing/pull/1021
2020-10-07 15:06:37 -07:00
David Barsky
a8cc977e01
tracing: Instrument std::future::Future (#808)
Authored-by: David Barsky <dbarsky@amazon.com>
Co-authored-by: Eliza Weisman <eliza@buoyant.io>
2020-09-25 16:15:06 -04:00
Eliza Weisman
3dd5c03d90
subscriber: prepare to release 0.2.12 (#970)
# 0.2.12 (September 8, 2020)

### Fixed

- **env-filter**: Fixed a regression where `Option<Level>` lost its
  `Into<LevelFilter>` impl ([#966])
- **env-filter**: Fixed `EnvFilter` enabling spans that should not be enabled
  when multiple subscribers are in use ([#927])
  
### Changed

- **json**: `format::Json` now outputs fields in a more readable order ([#892])
- Updated `tracing-core` dependency to 0.1.16

### Added

- **fmt**: Add `BoxMakeWriter` for erasing the type of a `MakeWriter`
  implementation ([#958])
- **fmt**: Add `TestWriter` `MakeWriter` implementation to support libtest
  output capturing ([#938])
- **layer**: Add `Layer` impl for `Option<T> where T: Layer` ([#910])
- **env-filter**: Add `From<Level>` impl for `Directive` ([#918])
- Multiple documentation fixes and improvements

Thanks to @Pothulapati, @samrg472, @bryanburgers, @keetonian, 
and @SriRamanujam for contributing to this release!

[#927]: https://github.com/tokio-rs/tracing/pull/927
[#966]: https://github.com/tokio-rs/tracing/pull/966
[#958]: https://github.com/tokio-rs/tracing/pull/958
[#892]: https://github.com/tokio-rs/tracing/pull/892
[#938]: https://github.com/tokio-rs/tracing/pull/938
[#910]: https://github.com/tokio-rs/tracing/pull/910
[#918]: https://github.com/tokio-rs/tracing/pull/918
2020-09-08 20:16:56 -07:00
Eliza Weisman
b3582013d8 examples: disable opentelemetry's default features
The `opentelemetry` crate depends on `prometheus`, which depends on
`protobuf`, a crate which doesn't compile on our MSRV (Rust 1.39). This
was missed due to issues with the MSRV CI checks, which will be fixed
fixed in #934. Therefore, once the MSRV checks work properly, the
`protobuf` dependency will break our builds.

We don't _need_ the `opentelemetry/metrics` feature, which is what
enables the `prometheus` (and thus `protobuf`) dependency.
`tracing-opentelemetry` already has a `default-features = false`
dependency on `opentelemetry`, but the examples don't. Therefore, I've
changed the examples crate to disable `opentelemetry`'s default features
as well.
2020-08-17 10:55:42 -07:00
Maxime Bedard
798ed9d31a
Bump to opentelemetry:0.8, opentelemetry-jaeger:0.7 (#932) 2020-08-14 10:35:52 -07:00
Tarun Pothulapati
e9b6645f0c
subscriber: impl Layer for Option<T:Layer> (#910)
## Motivation

Fixes #894

## Solution

This PR implements Layer for Option, allowing users to wrap a Layer with
an Option, allowing it to be passed internally wherever Layer is used
there by allowing by allowing layers to be enabled or disabled.

Using this with `reload` further allows a Layer to be dynamically
toggled based by using `handle.modify`

This PR also consists of a basic example.

Signed-off-by: Tarun Pothulapati <tarunpothulapati@outlook.com>
2020-08-14 10:29:16 -07:00
Eliza Weisman
e016e0435b
subscriber: prepare to release 0.2.11 (#916)
### Fixed

- **env-filter**: Incorrect max level hint when filters involving span
  field values are in use (#907)
- **registry**: Fixed inconsistent span stacks when multiple registries
  are in use on the same thread (#901)

### Changed

- **env-filter**: `regex` dependency enables fewer unused feature flags
  (#899)

Thanks to @bdonlan and @jeromegn for contributing to this release!
2020-08-10 17:38:32 -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
Julian Tescher
6935338edb
opentelemetry: Upgrade to opentelemetry v0.7.0 (#867)
Upgrade `opentelemetry` to latest release version
2020-07-31 09:29:09 -07:00
Robert Collins
32cf418c3b
tracing: add support literals for field names (#790)
## Motivation

Some opentracing systems use fields with : in the names, which are not
legal rust identifiers. We could special case :, but then we have
complicated double-nested patterns (repeated idents separated by : and a
nested repeat separated by .), and this may by a case of always being
one-step-behind as more cases turn up; so this patch instead just gets
in front and lets users put in whatever they want: as they are not rust
identifiers, they miss out on some niceness. 

## Solution

This permits : in field names but also potentially anything
stringifiable, which may be overly liberal.

Signed-off-by: Robert Collins <robert.collins@cognite.com>
2020-07-29 17:36:44 -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
Eliza Weisman
96e9d6d4f0
subscriber: prepare to release 0.2.8 (#823)
### Changed

- **fmt**: When the `chrono` dependency is enabled, the `SystemTime`
  timestamp now emits human-readable timestamps rather than using
  `SystemTime`'s fmt::Debug`implementation (`chrono` is still required
  for customized timestamp formatting) (#807)
- **ansi**: Updated `ansi_term` dependency to 0.12 (#816)

### Added

- **json**: `with_span_list` method to configure the JSON formatter to
  include a list of all spans in the current trace in formatting events
  (similarly to the text formatter) (#741)
- **json**: `with_current_span` method to configure the JSON formatter
  to include a field for the _current_ span (the leaf of the trace) in
  formatted events (#741)
- **fmt**: `with_thread_names` and `with_thread_ids` methods to
  configure `fmt::Subscriber`s and `fmt::Layer`s to include the thread
  name and/or thread ID of the current thread when formatting events
  (#818)

Thanks to new contributors @mockersf, @keetonian, and @Pothulapati for
contributing to this release!
2020-07-17 11:03:23 -07:00
Tarun Pothulapati
c109197c3e
subscriber: allow thread name and ID to be displayed in traces (#818)
## Motivation

Fixes #809 

## Solution

This PR adds two new methods i.e `with_thread_ids` and
`with_thread_names` to the fmt Layer which passed till
the pre-configured Format type, where the check is performed
and these the above values are formatted based on the flags.

The formatting is done by creating to new Types that impl Display
for Id and Name. For Thread Name, we keep track of the max length
of the thread name that occured till now using a thread safe static
type and pad accordingly. For Thread Id, we pad directly with 2
as in most cases we would see a double digit number of threads.

Signed-off-by: Tarun Pothulapati <tarunpothulapati@outlook.com>
2020-07-17 10:09:59 -07:00