Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

opentelemetry: Add extension to link spans #1480

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
126 commits
Select commit Hold shift + click to select a range
5c457e5
macros: fix the `tracing-macros` crate not compiling (#1000)
hawkw Sep 29, 2020
be2f80a
subscriber: support dash in target names (v0.1.x) (#1014)
bkchr Oct 5, 2020
ca9b668
tracing-opentelemetry: implement additional record types (bool, i64, …
lovesegfault Oct 5, 2020
a14ff8d
subscriber: warn if trying to enable a statically disabled level (#1021)
jyn514 Oct 7, 2020
4b54cbc
chore: fix nightly clippy warnings (#991) (#1025)
hawkw Oct 7, 2020
89418ee
subscriber: prepare to release 0.2.13 (#1024)
hawkw Oct 7, 2020
73c0c10
opentelemetry: Assign default ids if missing (#1029)
jtescher Oct 10, 2020
1aa9eff
opentelemetry: Backport #1036 - prepare for 0.8.0 release (#1037)
jtescher Oct 13, 2020
8406cbc
subscriber: make Registry::enter/exit much faster (#1058) (#1059)
hawkw Oct 22, 2020
a6e7d5e
subscriber: update sharded-slab, pool hashmaps (#1064)
hawkw Oct 22, 2020
3bc2fd3
subscriber: prepare to release 0.2.14 (#1065)
hawkw Oct 22, 2020
8bdc6c3
subscriber: add `Pretty` formatter (backports #1067) (#1080)
hawkw Nov 2, 2020
2d27703
subscriber: fix accessing the field formatter from `FmtContext` (#108…
hawkw Nov 2, 2020
692c56f
subscriber: prepare to release 0.2.15 (#1083)
hawkw Nov 2, 2020
642ad19
opentelemetry: update to latest otel release version (#1049) (#1099)
jtescher Nov 13, 2020
1cdd554
opentelemetry: prepare for 0.9.0 release (#1104) (#1105)
jtescher Nov 15, 2020
50e1fad
ci: install cargo-hack from GitHub release instead of using cache (#1…
taiki-e Nov 13, 2020
75ba278
ci: switch to `audit-check` GitHub Action for `cargo audit` (#1117)
hawkw Nov 23, 2020
43440ef
chore(deps): update pin-project-lite requirement from 0.1 to 0.2 (#1116)
hawkw Nov 23, 2020
fc3eb9f
tracing: prepare to release v0.1.22 (#1119)
hawkw Nov 23, 2020
199aa1a
chore: fix netlify build (#1131)
mraerino Dec 10, 2020
0b35268
subscriber: directives: accept legit log level names in mixed case (e…
salewski Dec 10, 2020
09a5509
docs: update README.md (#1133)
smhmayboudi Dec 14, 2020
e904a05
tracing-flame: add module_path and file_and_line configs (#1134)
xiaopengli89 Dec 14, 2020
91119f8
chore: don't check examples on MSRV (#1128)
hawkw Dec 8, 2020
9cb829f
appender: fix race condition when logging on shutdown (#1125)
thekeys93 Dec 11, 2020
763aa64
chore(deps): update crossbeam-channel requirement from 0.4.2 to 0.5.0…
dependabot-preview[bot] Oct 12, 2020
679fd0d
docs: add missing example for Rotation::MINUTELY (#1110)
salewski Nov 17, 2020
9549be9
docs: fix minor typo for DEFAULT_BUFFERED_LINES_LIMIT (#1109)
salewski Nov 17, 2020
6ce7189
appender: prepare to release v0.1.2 (#1157)
hawkw Dec 29, 2020
49b4a58
opentelemetry: update to otel v0.11.x (#1161) (#1162)
jtescher Dec 30, 2020
035342b
opentelemetry: prepare for v0.10.0 release (#1166) (#1169)
jtescher Jan 4, 2021
ea91df3
examples: backport fmt-multiple-writers.rs to v0.1.0 branch (#1187)
davidbarsky Jan 12, 2021
05efda1
chore: fix deprecation and clippy warnings (#1195) (#1208)
davidbarsky Jan 26, 2021
1a1d5b0
opentelemetry: update to otel v0.12.x (#1200)
jtescher Jan 25, 2021
2003af6
opentelemetry: prepare for v0.11.0 release (#1206) (#1207)
jtescher Jan 26, 2021
8cbc00e
chore: disable default features of tracing dependencies (#1144)
taiki-e Dec 18, 2020
46137e7
docs: add tracing-elastic-apm to related crates (#1146)
krojew Dec 21, 2020
cd79b11
tracing: check `log` max level prior to dispatch check (#1175)
hawkw Jan 28, 2021
54eff34
subscriber: add sample implementation of `FormatEvent` (#1189)
davidpdrsn Jan 28, 2021
ab9ba48
chore(deps): update pin-project requirement from 0.4 to 1.0 (#1038)
dependabot-preview[bot] Oct 18, 2020
672b175
docs: fix broken link due to typo
hawkw Jan 28, 2021
220f873
chore(deps): update chrono dependency to 0.4.16 (#1173)
markdingram Jan 28, 2021
a018071
attributes: update & improve docs (#1215)
hawkw Feb 2, 2021
f5f99dd
opentelemetry: clarify otel.kind field usage in docs (#1218)
jtescher Jan 30, 2021
72eb468
attributes: fix #[instrument(err)] with mutable parameters (#1167)
okready Feb 4, 2021
a3f2c0c
attributes: prepare to release v0.1.12 (#1221)
hawkw Feb 4, 2021
b130785
tracing: update minimum `tracing-attributes` to 0.1.12 (#1222)
hawkw Feb 4, 2021
27929d9
tracing: prepare to release v0.1.23 (#1223)
hawkw Feb 4, 2021
4609f22
tracing: fix some links in changelog (#1224)
nickelc Feb 5, 2021
e1e3431
attributes: fix `#[instrument(err)]` with `impl Trait` return types (…
hawkw Feb 11, 2021
f8b7d69
futures: prepare to release 0.2.5 (#1241)
hawkw Feb 16, 2021
9d4b7e7
tracing: fix a typo and adds a note about the supported field syntax …
lfrancke Feb 17, 2021
66b1ced
tracing: fix broken match arms in event macros (#1239) (#1242)
hawkw Feb 17, 2021
7f3d94f
attributes: prepare to release v0.1.13 (#1243)
hawkw Feb 17, 2021
d173c2d
tracing: prepare to release v0.1.24 (#1244)
hawkw Feb 17, 2021
2a9d17f
log: compare `log` record `Level`s against the max level (#1247)
hawkw Feb 18, 2021
31aa6af
subscriber: set the max `log` `LevelFilter` in `init` (#1248)
hawkw Feb 18, 2021
8d83326
subscriber: fix FmtCollector not forwarding max level (#1251)
hawkw Feb 19, 2021
0cdd5e8
log: forward `LogTracer::enabled` to the subscriber (#1254)
hawkw Feb 19, 2021
a0201ba
log: prepare to release v0.1.2
hawkw Feb 19, 2021
4538d74
subscriber: prepare to release v0.2.16 (#1256)
hawkw Feb 20, 2021
a358728
tracing: simplify common case of immediately entering the span (#1252)
matklad Feb 19, 2021
c22b62e
tracing: highlight `Span::entered` in more docs
hawkw Feb 23, 2021
4ad1e62
tracing: prepare to release v0.1.25
hawkw Feb 23, 2021
8f68311
attributes: update `#[instrument]` to support `async-trait` 0.1.43+ (…
hawkw Mar 10, 2021
88611cb
attributes: prepare to release v0.1.14 (#1292)
hawkw Mar 10, 2021
6f9b537
subscriber: Remove trailing space from ChronoLocal time formatter. (#…
najamelan Nov 17, 2020
5181226
subscriber: use struct update syntax when constructing from `self` (#…
Folyd Mar 10, 2021
14d11eb
subscriber: remove unnecessary transparent attribute (#1282)
matklad Mar 10, 2021
544da6b
subscriber: Add a public `current_span()` method for `FmtContext` (#1…
Folyd Mar 11, 2021
ac0aa97
attributes: fix `#[instrument]` skipping code when returning pinned f…
nightmared Mar 11, 2021
f3eb5cc
subscriber: fix extra padding in pretty format (#1275)
lenaschoenburg Mar 11, 2021
a947c5a
subscriber: change `FmtSpan` to a combinable bitflag (#1277)
zicklag Mar 11, 2021
ec73134
subscriber: update pretty formatter for no ansi (#1240)
Mar 11, 2021
742b214
attributes: prepare to release v0.1.15 (#1301)
hawkw Mar 12, 2021
8868541
subscriber: prepare to release 0.2.17 (#1302)
hawkw Mar 12, 2021
84ff3a4
chore: reverse the polarity of conversions, fix clippy (#1335)
hawkw Mar 29, 2021
18bd9f3
chore: ignore flaky field filter tests (#1336)
hawkw Mar 29, 2021
ebd3ee9
tracing: reverse one more conversion (#1338)
hawkw Mar 31, 2021
bab71ac
opentelemetry: support otel 0.13.0 (#1322) (#1330)
tikue Mar 31, 2021
1512556
opentelemetry: disabled tracked inactivity perf (#1315)
jtescher Mar 30, 2021
51965bf
docs: fix a broken link (and minor typo) on README (#1337)
JohnTitor Mar 30, 2021
f2c1825
subscriber: fix `on_event` serialization when no fields set on span (…
akinnane Mar 31, 2021
865f650
opentelemetry: prepare for v0.12.0 release (#1341) (#1342)
jtescher Apr 1, 2021
ca33d3f
opentelemetry: add preliminary benchmarks (#1303)
jtescher Mar 15, 2021
073c842
docs: fix typo in tracing/README.md (#1305)
rmsc Mar 16, 2021
07af5f8
subscriber: fix span data for new, exit, and close events (#1334)
akinnane Apr 7, 2021
3d65a48
tracing: remove duplicated event macro pattern (#1352)
Folyd Apr 13, 2021
b3490ff
subscriber: add span status fields (#1351)
aym-v Apr 13, 2021
eea2bb8
subscriber: remove space when timestamps are disabled (#1355)
hawkw Apr 15, 2021
95fe9a3
core: expose an accessor for the `FieldSet` on `Attributes` (#1331)
Folyd Apr 15, 2021
5e435b1
subscriber: deprecate `CurrentSpan` (#1321)
Folyd Apr 30, 2021
396d9f4
chore: fix cargo docs warnings (#1362)
Folyd Apr 20, 2021
1e8446e
subscriber: support special chars in span names (#1368)
aym-v Apr 27, 2021
e63d8e4
core: add `Subscriber` impl for `Box<dyn Subscriber + ...>` (#1358)
hawkw Apr 27, 2021
f9a3f17
tracing: add an example of `tracing` in a panic hook (#1375)
hawkw Apr 28, 2021
ccfa2cc
core: add support for `Arc<dyn Subscriber + ...>`
hawkw Apr 28, 2021
88b176c
tracing: impl `From<EnteredSpan>` for `Option<Id>` (#1325)
Folyd Apr 28, 2021
848ee2d
docs: document span.in_scope() at top-level (#1344)
Fishrock123 Apr 30, 2021
8d428b2
core: prepare to release v0.1.18
hawkw Apr 30, 2021
d9e8ece
tracing: prepare to release 0.1.26 (#1383)
hawkw Apr 30, 2021
dd49b99
subscriber: prepare to release 0.2.18 (#1384)
hawkw May 1, 2021
614a327
chore: fix clippy's awful new "inconsistent struct constructor" lint …
hawkw May 14, 2021
df95d06
opentelemetry: update to otel 0.14.x (#1394) (#1403)
jtescher May 17, 2021
2920a89
opentelemetry: prepare for v0.13.0 release (#1404) (#1406)
jtescher May 20, 2021
9702bf5
core: add `as_str()` for `Level` (#1413) (#1416)
Folyd May 27, 2021
9c031d7
attributes: don't record primitive types of the function arguments as…
Folyd May 6, 2021
d936628
core: impl `Value` for `&mut T` where `T: Value` (#1385)
Folyd May 3, 2021
dcd537e
tracing: blanket-implement WithSubscriber (#1424)
nightkr Jun 7, 2021
f910a2a
docs: Fix rendering issue with misaligned tooltips. (#1435)
davidbarsky Jun 13, 2021
7a01260
subscriber: unify span traversal (#1431)
nightkr Jun 22, 2021
067d214
subscriber: add Context method for resolving an Event's SpanRef (#1434)
nightkr Jun 23, 2021
4dbe03c
docs: Fix typo (#1442)
dzvon Jun 24, 2021
805eb51
subscriber: add `MakeWriter::make_writer_for` (#1141)
hawkw May 14, 2021
3795596
tracing: Fix link to RAII pattern document (#1398)
mbergkvist May 14, 2021
1e361e4
opentelemetry: add opentelemetry source code attributes to spans (#1411)
lilymara-onesignal May 25, 2021
bc1c3a3
opentelemetry: update opentelemetry to 0.15 (#1441)
Drevoed Jun 21, 2021
de76e55
chore: fix new clippy warnings (#1444)
hawkw Jun 23, 2021
ab62076
subscriber: explain why we always call `inner.register_callsite()` be…
Folyd Jun 23, 2021
29291af
opentelemetry: improve performance by pre-determining attribute lengt…
Folyd Jun 24, 2021
4bf3d00
subscriber: add `MakeWriter` combinators (#1274)
hawkw Jun 25, 2021
204077f
core: add a brief docs section on comparing levels (#1446)
hawkw Jun 25, 2021
807bc8f
subscriber: prepare to release 0.2.19 (#1448)
hawkw Jun 26, 2021
8cc3c51
opentelemetry: prepare to release v0.14.0 (#1464)
hawkw Jul 9, 2021
b602520
opentelemetry: Add extension to link spans
LehMaxence Jul 28, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 31 additions & 59 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
rust: [stable, 1.40.0]
rust: [stable, 1.42.0]
steps:
- uses: actions/checkout@main
- uses: actions-rs/toolchain@v1
Expand All @@ -24,30 +24,9 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: check
args: --all --bins --examples --tests --benches

cache-cargo-hack:
runs-on: ubuntu-latest
steps:
- name: Fetch latest release version of cargo-hack
run: |
mkdir -p .github/caching
curl -sL https://api.github.com/repos/taiki-e/cargo-hack/releases/latest | jq -r '.name' > .github/caching/cargo-hack.lock
- name: Cache cargo-hack/bin
id: cache-cargo-hack
uses: actions/cache@v1
with:
path: ${{ runner.tool_cache }}/cargo-hack/bin
key: cargo-hack-bin-${{ hashFiles('.github/caching/cargo-hack.lock') }}
- name: Install cargo-hack
if: "steps.cache-cargo-hack.outputs.cache-hit != 'true'"
uses: actions-rs/cargo@v1
with:
command: install
args: --root ${{ runner.tool_cache }}/cargo-hack --force cargo-hack
args: --all --bins --tests --benches

cargo-hack:
needs: cache-cargo-hack
runs-on: ubuntu-latest
strategy:
matrix:
Expand All @@ -73,19 +52,9 @@ jobs:
toolchain: stable
profile: minimal
override: true
- name: Fetch latest release version of cargo-hack
- name: Install cargo-hack
run: |
mkdir -p .github/caching
curl -sL https://api.github.com/repos/taiki-e/cargo-hack/releases/latest | jq -r '.name' > .github/caching/cargo-hack.lock
- name: Restore cargo-hack/bin
uses: actions/cache@v1
with:
path: ${{ runner.tool_cache }}/cargo-hack/bin
key: cargo-hack-bin-${{ hashFiles('.github/caching/cargo-hack.lock') }}
- run: echo "::add-path::${{ runner.tool_cache }}/cargo-hack/bin"
# if `cargo-hack` somehow doesn't exist after loading it from the cache,
# make *sure* it's there.
- run: cargo hack --help || { cargo install --force cargo-hack; }
curl -LsSf https://github.com/taiki-e/cargo-hack/releases/latest/download/cargo-hack-x86_64-unknown-linux-gnu.tar.gz | tar xzf - -C ~/.cargo/bin
- name: cargo hack check
working-directory: ${{ matrix.subcrate }}
run: cargo hack check --feature-powerset --no-dev-deps
Expand Down Expand Up @@ -145,7 +114,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
rust: [stable, beta, nightly, 1.40.0]
rust: [stable, beta, nightly]
steps:
- uses: actions/checkout@main
- uses: actions-rs/toolchain@v1
Expand All @@ -159,6 +128,32 @@ jobs:
command: test
args: --all

test-msrv:
# Test against the minimum supported Rust version
needs: check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@main
- uses: actions-rs/toolchain@v1
with:
toolchain: 1.42.0
profile: minimal
override: true
# We can't use `cargo test --all`, as that will also compile the examples.
# We don't guarantee the examples will work on the MSRV, because they have
# external dependencies which may not comply with our MSRV policy, but don't
# actually impact users on our MSRV.
- name: Run tests
uses: actions-rs/cargo@v1
with:
command: test
args: --workspace --lib --tests
- name: Run doctests
uses: actions-rs/cargo@v1
with:
command: test
args: --workspace --doc

test-build-wasm:
needs: check
runs-on: ubuntu-latest
Expand Down Expand Up @@ -282,26 +277,3 @@ jobs:
with:
token: ${{ secrets.GITHUB_TOKEN }}
args: --all --bins --examples --tests --benches -- -D warnings

cargo-audit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@main
- name: Fetch latest release version of cargo-audit
run: |
mkdir -p .github/caching
cargo search cargo-audit | grep '^cargo-audit' | awk '{gsub(/"/,"",$3); print $3}' > .github/caching/cargo-audit.lock
- name: Cache cargo-audit/bin
id: cache-cargo-audit
uses: actions/cache@v1
with:
path: ${{ runner.tool_cache }}/cargo-audit/bin
key: cargo-audit-bin-${{ hashFiles('.github/caching/cargo-audit.lock') }}
- name: Install cargo-audit
if: "steps.cache-cargo-audit.outputs.cache-hit != 'true'"
uses: actions-rs/cargo@v1
with:
command: install
args: --root ${{ runner.tool_cache }}/cargo-audit --force cargo-audit
- run: echo "::add-path::${{ runner.tool_cache }}/cargo-audit/bin"
- run: cargo audit
14 changes: 14 additions & 0 deletions .github/workflows/audit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Security audit
on:
push:
paths:
- '**/Cargo.toml'
- '**/Cargo.lock'
jobs:
security_audit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions-rs/audit-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ pub fn shave_all(yaks: usize) -> usize {

if let Err(ref error) = res {
// Like spans, events can also use the field initialization shorthand.
// In this instance, `yak` is the field being initalized.
// In this instance, `yak` is the field being initialized.
error!(yak, error = error.as_ref(), "failed to shave yak!");
} else {
yaks_shaved += 1;
Expand All @@ -192,7 +192,7 @@ set the default later.

### In Asynchronous Code

To trace `async fn`s, the preferred method is using the [`#[instrument]`] attribute:
To trace `async fn`s, the preferred method is using the [`#[instrument]`][instrument] attribute:

```rust
use tracing::{info, instrument};
Expand Down Expand Up @@ -244,19 +244,19 @@ my_future
`Future::instrument` attaches a span to the future, ensuring that the span's lifetime
is as long as the future's.

Under the hood, the `#[instrument]` macro performs same the explicit span
Under the hood, the [`#[instrument]`][instrument] macro performs same the explicit span
attachment that `Future::instrument` does.

[std-future]: https://doc.rust-lang.org/stable/std/future/trait.Future.html
[`tracing-futures`]: https://docs.rs/tracing-futures
[closing]: https://docs.rs/tracing/latest/span/index.html#closing-spans
[closing]: https://docs.rs/tracing/latest/tracing/span/index.html#closing-spans
[`Future::instrument`]: https://docs.rs/tracing/latest/tracing/trait.Instrument.html#method.instrument
[`#[instrument]`]: https://docs.rs/tracing/0.1.11/tracing/attr.instrument.html
[instrument]: https://docs.rs/tracing/0.1.11/tracing/attr.instrument.html

## Supported Rust Versions

Tracing is built against the latest stable release. The minimum supported
version is 1.40. The current Tracing version is not guaranteed to build on Rust
version is 1.42. The current Tracing version is not guaranteed to build on Rust
versions earlier than the minimum supported version.

Tracing follows the same compiler support policies as the rest of the Tokio
Expand Down Expand Up @@ -399,6 +399,7 @@ are not maintained by the `tokio` project. These include:
- [`diesel-tracing`] provides integration with [`diesel`] database connections.
- [`tracing-tracy`] provides a way to collect [Tracy] profiles in instrumented
applications.
- [`tracing-elastic-apm`] provides a layer for reporting traces to [Elastic APM].

(if you're the maintainer of a `tracing` ecosystem crate not in this list,
please let us know!)
Expand Down Expand Up @@ -426,6 +427,8 @@ please let us know!)
[`diesel-tracing`]: https://crates.io/crates/diesel-tracing
[`tracing-tracy`]: https://crates.io/crates/tracing-tracy
[Tracy]: https://github.com/wolfpld/tracy
[`tracing-elastic-apm`]: https://crates.io/crates/tracing-elastic-apm
[Elastic APM]: https://www.elastic.co/apm

**Note:** that some of the ecosystem crates are currently unreleased and
undergoing active development. They may be less stable than `tracing` and
Expand Down
15 changes: 8 additions & 7 deletions examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,25 @@ default = []
[dev-dependencies]

# tracing crates
tracing = { path = "../tracing", version = "0.1"}
tracing-core = { path = "../tracing-core", version = "0.1"}
tracing = { path = "../tracing", version = "0.1" }
tracing-core = { path = "../tracing-core", version = "0.1" }
tracing-error = { path = "../tracing-error" }
tracing-flame = { path = "../tracing-flame" }
tracing-tower = { version = "0.1.0", path = "../tracing-tower" }
tracing-subscriber = { path = "../tracing-subscriber", version = "0.2.12", features = ["json", "chrono"] }
tracing-subscriber = { path = "../tracing-subscriber", version = "0.2.13", features = ["json", "chrono"] }
tracing-futures = { version = "0.2.1", path = "../tracing-futures", features = ["futures-01"] }
tracing-attributes = { path = "../tracing-attributes", version = "0.1.2"}
tracing-attributes = { path = "../tracing-attributes", version = "0.1.2" }
tracing-log = { path = "../tracing-log", version = "0.1.1", features = ["env_logger"] }
tracing-serde = { path = "../tracing-serde" }
tracing-opentelemetry = { path = "../tracing-opentelemetry" }
tracing-journald = { path = "../tracing-journald" }
tracing-appender = { path = "../tracing-appender", version = "0.1.2" }

# serde example
serde_json = "1.0"

futures = "0.3"
tokio = { version = "0.2.12", features = ["full"] }
tokio = { version = "0.2.13", features = ["full"] }

# env-logger example
env_logger = "0.7"
Expand All @@ -52,5 +53,5 @@ inferno = "0.10.0"
tempdir = "0.3.7"

# opentelemetry example
opentelemetry = { version = "0.8", default-features = false, features = ["trace"] }
opentelemetry-jaeger = "0.7"
opentelemetry = { version = "0.15", default-features = false, features = ["trace"] }
opentelemetry-jaeger = "0.14"
2 changes: 2 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ This directory contains a collection of examples that demonstrate the use of the
fields on spans and events.
+ `fmt-custom-event`: Demonstrates overriding how the `fmt` subscriber formats
events.
+ `fmt-multiple-writers.rs`: demonstrates how `fmt::Layer` can write
to multiple destinations (in this instance, stdout and a file) simultaneously.
+ `subscriber-filter`: Demonstrates the `tracing-subscriber::filter` module,
which provides a layer which adds configurable filtering to a subscriber
implementation.
Expand Down
21 changes: 21 additions & 0 deletions examples/examples/fmt-json.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#![deny(rust_2018_idioms)]
#[path = "fmt/yak_shave.rs"]
mod yak_shave;

fn main() {
tracing_subscriber::fmt()
.json()
.with_max_level(tracing::Level::TRACE)
.with_current_span(false)
.init();

let number_of_yaks = 3;
// this creates a new event, outside of any spans.
tracing::info!(number_of_yaks, "preparing to shave yaks");

let number_shaved = yak_shave::shave_all(number_of_yaks);
tracing::info!(
all_yaks_shaved = number_shaved == number_of_yaks,
"yak shaving completed"
);
}
32 changes: 32 additions & 0 deletions examples/examples/fmt-multiple-writers.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//! An example demonstrating how `fmt::Layer` can write to multiple
//! destinations (in this instance, `stdout` and a file) simultaneously.

#[path = "fmt/yak_shave.rs"]
mod yak_shave;

use std::io;
use tempdir::TempDir;
use tracing_subscriber::{fmt, layer::SubscriberExt, EnvFilter};

fn main() {
let dir = TempDir::new("directory").expect("Failed to create tempdir");

let file_appender = tracing_appender::rolling::hourly(dir, "example.log");
let (non_blocking, _guard) = tracing_appender::non_blocking(file_appender);

let subscriber = tracing_subscriber::registry()
.with(EnvFilter::from_default_env().add_directive(tracing::Level::TRACE.into()))
.with(fmt::Layer::new().with_writer(io::stdout))
.with(fmt::Layer::new().with_writer(non_blocking));
tracing::subscriber::set_global_default(subscriber).expect("Unable to set a global collector");

let number_of_yaks = 3;
// this creates a new event, outside of any spans.
tracing::info!(number_of_yaks, "preparing to shave yaks");

let number_shaved = yak_shave::shave_all(number_of_yaks);
tracing::info!(
all_yaks_shaved = number_shaved == number_of_yaks,
"yak shaving completed."
);
}
23 changes: 23 additions & 0 deletions examples/examples/fmt-pretty.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#![deny(rust_2018_idioms)]
#[path = "fmt/yak_shave.rs"]
mod yak_shave;

fn main() {
tracing_subscriber::fmt()
.pretty()
.with_thread_names(true)
// enable everything
.with_max_level(tracing::Level::TRACE)
// sets this to be the default, global collector for this application.
.init();

let number_of_yaks = 3;
// this creates a new event, outside of any spans.
tracing::info!(number_of_yaks, "preparing to shave yaks");

let number_shaved = yak_shave::shave_all(number_of_yaks);
tracing::info!(
all_yaks_shaved = number_shaved == number_of_yaks,
"yak shaving completed"
);
}
13 changes: 5 additions & 8 deletions examples/examples/fmt.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
#![deny(rust_2018_idioms)]
use tracing::{info, Level};

#[path = "fmt/yak_shave.rs"]
mod yak_shave;

fn main() {
tracing_subscriber::fmt()
// all spans/events with a level higher than DEBUG (e.g, info, warn, etc.)
// will be written to stdout.
.with_max_level(Level::DEBUG)
// sets this to be the default, global subscriber for this application.
// enable everything
.with_max_level(tracing::Level::TRACE)
// sets this to be the default, global collector for this application.
.init();

let number_of_yaks = 3;
// this creates a new event, outside of any spans.
info!(number_of_yaks, "preparing to shave yaks");
tracing::info!(number_of_yaks, "preparing to shave yaks");

let number_shaved = yak_shave::shave_all(number_of_yaks);
info!(
tracing::info!(
all_yaks_shaved = number_shaved == number_of_yaks,
"yak shaving completed."
);
Expand Down
Loading