8 Commits

Author SHA1 Message Date
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
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
Eliza Weisman
940808c68a core: remove mandatory liballoc dependency with no-std (#1017)
## Motivation

Presently, `tracing` and `tracing-core` allow disabling the Rust
standard library. However, even when used with the standard library
disabled, they still require the use of `alloc`, which means some form
of global allocator must exist. This can be a significant limitation on
some very constrained embedded devices. Additionally, the use of any
heap allocations on these devices ought to be avoided.

Now that the callsite registry is no longer a `Vec`, we don't need heap
allocations for storing registered callsites. However, `Dispatch`s are
currently _always_ stored in `Arc`s, and the global registry always
contains a `Vec` of `Weak` refs to them. This is required in order to
support thread-local scoped dispatcher API, where multiple `Dispatch`es
can coexist. However, on `no-std` platforms without threads, we already
don't support the thread-local scoped dispatch API. In this case, we can
reduce the complexity and the number of allocations required by the
dispatcher.

Additionally, even when the standard library is in use, if the
dispatcher is a global default rather than a scoped dispatcher, it
remains set forever. This means it can never be dropped. When this is
the case, it's possible to clone the dispatcher by cloning a `'static`
reference, rather than a (comparatively) costly `Arc` bump.

## Solution

This branch changes the global default dispatcher to be represented as a
`&'static dyn Subscriber` reference on all platforms. In addition, the
dependency on `liballoc` is now feature flagged, allowing it to be
disabled along with the dependency on `libstd`. This means that
`tracing` can now be used with _no_ heap allocations required.

In order to use `tracing` without `liballoc`, `Dispatch`es can only be
created from `&'static dyn Subscriber` references, since this is the
only way to erase their types that exists without boxed trait objects.
Therefore, I've added a new `Dispatch::from_static` constructor that is
always available. This is more limiting than `Dispatch::new` --- some
ways of modeling runtime composition of the subscriber are much harder
(although it could still contain state). However, users without `alloc`
are probably fairly used to this --- the `log` crate [has the same
limitation](https://docs.rs/log/0.4.11/log/#use-with-std) when used
without `std`.

Also, I've changed the global subscriber registry when `std` _is_
enabled to use a `RwLock` rather than a mutex. Now, multiple callsites
can be registered simultaneously, and a write lock is only necessary to
add a new subscriber or deregister old ones. It's now fine to use
`RwLock` here, because we no longer use any locking at all when `std` is
not enabled --- we always use the single global default subscriber, so
we don't require a list of currently live subscribers.

I've modified the `tracing` and `tracing-core` crates to add new feature
flags for enabling `std` and `alloc` separately.

Closes #861

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
2020-10-07 12:38:08 -07:00
Bhargav
5fced339dd core: Add set_default method to set default dispatcher (#388)
## Motivation

As discussed in #383 , adds the new `set_default` method.

## Solution

* Add `tracing::subscriber::set_default` which sets the default
subscriber and returns a drop guard. This drop guard will reset the
dispatch on drop.
* Add `tracing_core::dispatcher::set_default` method which sets the
default dispatch and returns a drop guard.
* Update `tracing_core::dispatcher::with_default` method to use the new
`tracing_core::dispatcher::set_default` method.
* Add test to confirm expected behavior

Fixes: #383
2019-10-18 11:56:33 -07:00
Eliza Weisman
2572f68339 core: support no-std + alloc (#256)
* core: support `no-std` + `alloc`

Motivation

Users have expressed interest in using `tracing` on no_std platforms
with `liballoc`.

Solution

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

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

Refs: #213

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
2019-08-09 13:27:35 -07:00
Eliza Weisman
069c43b268 core: adopt Rust 2018 edition idioms
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
2019-08-08 16:30:33 -07:00
Bruce Mitchener
9936b55a61 Fix typos. (#128) 2019-07-01 10:14:14 -07:00
Eliza Weisman
6a5cb28a44 meta: rename everything to tracing (#99)
See #95 

This branch renames everything from `tokio-trace` to `tracing`.

Unlike PR #98, the nursery crates still depend on the crates.io
versions of `tokio-trace` and `tokio-trace-core`, but renamed
to `tracing`/`tracing-core` in `Cargo.toml`. We can update the
nursery crates to depend on local path dependencies in a 
subsequent PR, as that will require making code changes to the
nursery crates.

This branch _also_ updates the minimum Rust version to 1.34.0,
to the shock and horror of the millions of `tracing` users still
on Rust 1.26.0. This was necessary in order to allow renaming
crates in `Cargo.toml`, and to resolve that not using the `dyn` 
keyword is now a warning on nightly.

Closes #98 
Closes #95

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
2019-06-26 11:31:07 -07:00