Commit Graph

1354 Commits

Author SHA1 Message Date
Eliza Weisman
5d65b4591d rename callsite in new macro cases from #2699 2023-09-05 14:21:33 -07:00
Eliza Weisman
cb5b499f68 Merge branch 'master' into constant_field_name 2023-09-05 14:19:20 -07:00
Eliza Weisman
a680b4c835 expand doc comment 2023-09-05 14:13:41 -07:00
Finomnis
672dfdf694 journald: allow custom journal fields (#2708)
## Motivation

It's currently not possible to customize how messages will get send to journald.

This became apparent in #2425, where first a specific API got designed, but then
it was decided that users should not get restricted in only a subset of fields,
but should be able to simply choose by themselves what fields get set with what
values.

So in a sense, this is the successor/rework of #2425.

## Solution

Allow custom fields to be set in tracing-journald.

## Open Questions

- [x] How should we deal with fields that also get supplied by other options?
  For example, setting `SYSLOG_IDENTIFIER` here and also setting
  `.with_syslog_identifier()` will send said field twice, potentially with
  differing values. Is that a problem?
    - Answer: No, this is not a problem.

Closes #2425
2023-09-05 20:13:43 +00:00
Aaron Roney
c5736519c3 tracing: allow setting event names in macros (#2699)
## Motivation

The motivation is #1426.  Currently, event names are set to a default
value of `event file:line`, which (1) doesn't allow for customization,
and (2) prevents events from working for some opentelemetry endpoints
(they often use the event name `exception` to designate something like a
panic).

## Solution

Went through the event macros, and added new parameterization that
allows for setting the `name`.  In addition, added some comments, and
reordering, to make life a bit better for the next person that comes
along to edit those macros.  Finally, added tests for the macro
expansion alongside the existing tests with a reasonable amount of
coverage (though, admittedly, more could be added for all of the macro
invocation types

Fixes #1426
2023-09-05 20:09:00 +00:00
Ethan Brierley
1c855ae045 core: allow ValueSets of any length (#2508)
## Motivation

Fixes: #1566

## Solution

This change removes the maximum of 32 fields limitation using const
generics.

Having this arbitrary restriction in place to prevent stack overflows
feels a little misplaced to me since stack size varies between
environments.
2023-09-05 17:57:39 +00:00
Kornel
683cc8a1a4 attributes: generate less dead code for async block return type hint (#2709)
## Motivation

`#[tracing::instrument]` uses `unreachable!()` macro which needlessly
expands to panicking and formatting code. It only needs any `!` type.

## Solution

`loop {}` works just as well for a `!` type, and it crates less work for
the compiler. The code is truly unreachable, so the message would never
be useful. Rust used to be concerned about semantics of empty loops in
LLVM, but this [has been solved](https://reviews.llvm.org/D85393).
2023-09-05 17:37:53 +00:00
Gabi
bab2e29955 flame: fix folded formatting (#2710)
## Motivation

The `.folded` format expects a `;`-separated list of the stack function,
optionally followed up by a sample count.

The implementation before this commit added a blank space after each `;`
which made parsers, such as `inferno-flamegraph` mis-interpret the data.

Furthermore, normally one wouldn't expect the filename and line-number
in such stack trace.

## Solution

Remove white-space between `;` for the generated file and remove
filename and line-number by default.
2023-09-05 10:26:03 -07:00
C L Eckhardt
9a7257d7ff appender: clarify file appender docs (#2689)
## Motivation

There are a few errors in the file appender docs - this fixes them.

It also wasn't clear/apparent to me that you can create a non-rolling
file appender with the `rolling` module - this calls that out more
clearly.

## Solution

Updates to docs.
2023-09-05 10:20:06 -07:00
Michael Wigard
81ceb65008 attributes: fix instrument with "log" feature (#2599)
## Motivation

The instrument macro currently doesn't work with the "log" crate
feature: #2585

## Solution

Change the generated code to create a span if either
`tracing::if_log_enabled!` or `tracing::level_enabled!`. I'm not sure
how to add a test for this or if this is the best solution.

Fixes #2585
2023-09-05 17:18:40 +00:00
Eliza Weisman
bf05c61b72 chore: fix new warnings in Rust 1.72.0 (#2700)
This branch fixes a handful of new warnings which have shown up after
updating to Rust 1.72.0.

This includes:

* `clippy::redundant_closure_call` in macros --- allowed because the
  macro sometimes calls a function that isn't a closure, and the closure
  is just used in the case where it's not a function.
* Unnecessary uses of `#` in raw string literals that don't contain `"`
  characters.
* Dead code warnings with specific feature flag combinations in
  `tracing-subscriber`.

In addition, I've fixed a broken RustDoc link that was making the 
Netlify build sad.
2023-08-29 18:16:59 +00:00
David M. Lary
81ab9d6fae subscriber: support NO_COLOR in fmt::Subscriber (#2647)
## Motivation

It's necessary at times to be able to disable ANSI color output for 
rust utilities using `tracing`.  The informal standard for this is the
`NO_COLOR` environment variable described here: https://no-color.org/

Further details/discussion in #2388

## Solution

This commit updates `fmt::Subscriber` to check the `NO_COLOR`
environment variable when determining whether ANSI color output is
enabled by default. As described in the spec, any non-empty value set
for `NO_COLOR` will cause ANSI color support to be disabled by default.

If the user manually overrides ANSI color support, such as by calling
`with_ansi(true)`, this will still enable ANSI colors, even if
`NO_COLOR` is set. The `NO_COLOR` env var only effects the default
behavior.

Fixes #2388
2023-08-17 16:56:29 +00:00
Harry Barber
6c530d5b07 tracing: fix wasm_bindgen_test macros (#2675)
## Motivation

Tests involving `wasm_bindgen_test` currently fail:

https://github.com/tokio-rs/tracing/actions/runs/5756318807/job/15605512576

## Solution

- [x] Use `extern crate wasm_bindgen_test` to side-step `no_implicit_prelude`.
- [x] https://github.com/rustwasm/wasm-bindgen/pull/3549
- [ ] Consume the release `wasm_bindgen_test` containing said change.
2023-08-17 09:36:34 -07:00
Jonathan Woollett-Light
887b9e79ba docs: Add clippy-tracing to related crates (#2628)
## Motivation

Sharing tooling.

## Solution

Adds `clippy-tracing` to related crates.

Closes #2627
2023-08-14 10:11:28 -07:00
Alexander Tesfamichael
8f4157e0f8 docs(field): remove duplicate wording (#2674) 2023-08-14 10:09:18 -07:00
Nikita Popov
5321e52263 core: ensure callsites in test have unique addresses (#2681)
The test relies on TEST_CALLSITE_1 and TEST_CALLSITE_2 to have
different addresses. However, as they are zero-sized types, this
is not guaranteed.

This fixes the test failure with LLVM 17 and certain optimization
options reported at https://github.com/rust-lang/rust/issues/114699.
2023-08-14 10:08:45 -07:00
Ana Hobden
941b1591fa documentation: Add article and talk by hoverbear (#2679) 2023-08-09 18:52:16 +00:00
Yuta Yamaguchi
79dd541ff6 tracing: add tracing-cloudwatch to related cates in README (#2667) 2023-08-07 18:28:05 +00:00
David Barsky
ef201ab3a9 chores: fix clippy lints (#2673) 2023-08-03 22:38:14 +00:00
Harry Barber
27f688efb7 tracing: use fully qualified names in macros for items exported from std prelude (#2621)
## Motivation

Currently, in many places, macros do not use fully qualified names for
items exported from the prelude. This means that naming collisions
(`struct Some`) or the removal of the std library prelude will cause
compilation errors.

## Solution

- Identify and use fully qualified names in macros were we previously
  assumed the Rust std prelude. We use `::core` rather than `::std`.
- Add
  [`no_implicit_prelude`](https://doc.rust-lang.org/reference/names/preludes.html#the-no_implicit_prelude-attribute)
  to `tracing/tests/macros.rs`. I'm unsure if this is giving us good
  coverage - can we improve on this approach? I'm not confident I've
  caught everything.
2023-07-11 19:39:10 +00:00
Eliza Weisman
c6e8a8f679 tracing: fix recursive register_callsite deadlock (#2634)
## Motivation

A deadlock exists when a collector's `register_callsite` method calls
into code that also contains tracing instrumentation and triggers a
second `register_callsite` call for the same callsite. This is because
the current implementation of the `MacroCallsite` type holds a
`core::sync::Once` which it uses to ensure that it is only added to the
callsite registry a single time. This deadlock was fixed in v0.1.x in PR
#2083, but the issue still exists on v0.2.x.

## Solution

This branch forward-ports the solution from #2083. Rather than using a
`core::sync::Once`, we now track the callsite's registration state
directly in `MacroCallsite`. If a callsite has started registering, but
has not yet completed, subsequent `register` calls will just immediately
receive an `Interest::sometimes` until the registration has completed,
rather than waiting to attempt their own registration.

I've also forward-ported the tests for this that were added in #2083.
2023-06-24 10:13:17 -07:00
Hayden Stainsby
9ad27405f8 mock: document public API in collector module (#2389)
There has been interest around publishing `tracing-mock` to crates.io
for some time. In order to make this possible, documentation and some
code clean up is needed.

This change adds documentation to the collector module itself and to all the
public APIs in the module. This includes doctests on all the methods
that serve as examples.

Additionally the implementation for the `Expect` struct has been moved
into the module with the definition, this was missed in #2369.

Refs: #539
2023-06-23 19:09:29 -07:00
James Munns
2906278ba7 core: add ValueSet::len and Record::len (#2152)
## Motivation

This PR adds two new accessor functions that are useful for creating a
structured serde implementation for tracing.

This is a sort of "distilled" version of
https://github.com/tokio-rs/tracing/pull/2113, based on the `v0.1.x`
branch.

As it is unlikely that "structured serde" will be 1:1 compatible with
the existing JSON-based `tracing-serde` (or at least - I'm not sure how
to do it in a reasonable amount of effort), these functions will allow
me to make a separate crate to hold me over until breaking formatting
changes are possible in `tracing-serde`.

CC @hawkw, as we've discussed this pretty extensively
2023-06-22 09:54:35 -07:00
Joseph Perez
8f3d935685 macros: refine constant field names tests 2023-06-22 09:41:23 +02:00
Joseph Perez
38a723280f doc: fix typo
Co-authored-by: Eliza Weisman <eliza@buoyant.io>
2023-06-22 09:17:39 +02:00
David Mládek
ebd437cf1a attributes: allow unknown_lints in generated code (#2626)
## Motivation

#2609 added an allow to generated code to allow a lint that was added in
Clippy 1.70.0. This was released with a patch bump so anyone who uses an
older version and latest tracing gets a compilation warning about an
unkonwn lint.

## Solution

Allowing unkonwn lints should fix this now and prevent similar issues in
the future. If the lints are unknown it will most likely be because the
lints are introduced only in newer compiler. There is just a higher risk
that a future contributor tries to add another allow and if they make a
typo, the issue will not be caught.
2023-06-20 14:36:12 +00:00
Guillaume Desmottes
c14525e161 core: fix typo in field docs (#2611)
## Motivation

Module `tracing::field` documentation is missing a word.

## Solution

Fixing the typo by adding `event`.
2023-06-16 15:43:59 +00:00
Eliza Weisman
2fc09f47ca chore: silence clippy::redundant_clone warning (#2619)
The purpose of this test is to assert two clones of the same span are
equal to each other, so the clone is kind of the whole point of the
test. This commit adds an allow attribute to make clippy shut up about
it.
2023-06-16 08:24:06 -07:00
Noa
3bde225fda attributes: fix clippy::let_with_type_underscore in generated code (#2609)
Co-authored-by: Hayden Stainsby <hds@caffeineconcepts.com>
Co-authored-by: Eliza Weisman <eliza@buoyant.io>
2023-06-15 22:34:23 +00:00
Cijo Thomas
e6f4ff15b8 docs: fix deadlink to tracing-etw repo (#2602) 2023-06-15 21:19:58 +00:00
Joseph Perez
a3cc393b05 Add documentation 2023-06-15 17:52:39 +02:00
Joseph Perez
48495eb43f macros: Handle constant field names 2023-06-15 17:19:56 +02:00
John Gillott
e603c2a254 Fix doc link to RAI pattern crate documentation (#2612) 2023-06-09 14:17:08 +00:00
Jason Heeris
29146260fb subscriber: document registry feature requirement for fmt feature (#2590)
## Motivation

This was inconsistent with other features, which mention their
requirements, and a reader might assume they don't need to inspect the
feature flags page or manifest.
2023-05-11 10:59:37 -07:00
Alice Ryhl
bfc44ba2fd docs: add SECURITY.md (#2591)
We should make it explicit that tracing uses the security policy of Tokio.
2023-05-11 09:09:52 -07:00
Devin Bidwell
998774eb7a subscriber: add "unicode-case" and "unicode-perl" features to regex dependency (#2566)
## Motivation

Missing features for the `regex` crate were causing build time errors
due to the the use of unicode characters in the regex without using
the proper features within the regex crate

 ## Solution

Add the missing feature flags.

Fixes #2565

Authored-by: Devin Bidwell <dbidwell@biddydev.com>
2023-04-21 20:59:25 +00:00
Devin Bidwell
c59a7fb14d attributes: update UI tests with the latest stable version of Rust (#2568)
updated UI tests using TRYBUILD=overwrite with the latest stable version of Rust

## Motivation

UI tests are failing on the latest stable version of Rust

## Solution

Run `TRYBUILD=overwrite cargo test` to update the effected files.
2023-04-21 13:47:44 -07:00
Ilya Salauyeu
8aae1c37b0 tracing, tracing-futures: instrument Future inside Drop (#2562)
## Motivation

Currently it is not possible to disable ANSI in `fmt::Subscriber`
without enabling the "ansi" crate feature. This makes it difficult for
users to implement interoperable settings that are controllable with
crate features without having to pull in the dependencies "ansi" does.

I hit this while writing an application with multiple logging options
set during compile-time and I wanted to cut down on dependencies if
possible.

## Solution

This changes `fmt::Subscriber::with_ansi()` to not require the "ansi"
feature flag. This way, `with_ansi(false)` can be called even when the
"ansi" feature is disabled. Calling `with_ansi(true)` when the "ansi"
feature is not enabled will panic in debug mode, or print a warning if
debug assertions are disabled.

Co-authored-by: daxpedda <daxpedda@gmail.com>
Co-authored-by: Eliza Weisman <eliza@buoyant.io>
2023-04-18 15:55:46 -07:00
daxpedda
1cb523b87d subscriber: add ability to disable ANSI without crate feature (#2532)
## Motivation

Currently it is not possible to disable ANSI in `fmt::Subscriber`
without enabling the "ansi" crate feature. This makes it difficult for
users to implement interoperable settings that are controllable with
crate features without having to pull in the dependencies "ansi" does.

I hit this while writing an application with multiple logging options
set during compile-time and I wanted to cut down on dependencies if
possible.

## Solution

This changes `fmt::Subscriber::with_ansi()` to not require the "ansi"
feature flag. This way, `with_ansi(false)` can be called even when the
"ansi" feature is disabled. Calling `with_ansi(true)` when the "ansi"
feature is not enabled will panic in debug mode, or print a warning if
debug assertions are disabled.

Co-authored-by: Eliza Weisman <eliza@buoyant.io>
2023-04-14 19:38:48 +00:00
Eliza Weisman
a351b978d5 subscriber: revert "subscriber: update time crate to 0.3.18 (#2550)"
This reverts commit 9744ec03f9. This
change breaks MSRV compatibility, and was accidentally auto-merged due
to what appears to be an issue with the CI configuration, which
(apparently) doesn't require the MSRV minimal-versions check runs to
complete before allowing a branch to merge.

We'll have to solve the original issue here through documentation for
now. See [this comment] for details.

[this comment]: https://github.com/tokio-rs/tracing/pull/2550#issuecomment-1507656030
2023-04-13 14:58:19 -07:00
David Pedersen
539ffbe189 attributes: update to syn 2.0 (#2516)
## Motivation

syn 2.0 is out!

## Solution

Update to syn 2.0 🚀

Co-authored-by: David Barsky <me@davidbarsky.com>
Co-authored-by: Eliza Weisman <eliza@buoyant.io>
2023-04-13 21:29:33 +00:00
klensy
ca26746391 attributes: remove unused syn's feature visit (#2530)
Remove unused `syn`s feature `visit`
2023-04-13 14:12:53 -07:00
keepsimple1
9744ec03f9 subscriber: update time crate to 0.3.18 (#2550)
Bump up the version of the `time` crate so that we don't need to
build with `--cfg unsound_local_offset` for using `fmt::time::LocalTime`.
2023-04-13 20:24:51 +00:00
Jiahao XU
5722b4503e Remove dep cfg-if from tracing (#2553)
## Motivation

Same reason as https://github.com/rust-lang/log/pull/536 :

`cfg_if` is only used in a single place and `tracing` is used by many
other crates, so even removing one dependency will be beneficial.

## Solution

Remove dependency `cfg-if` and replace `cfg_if::cfg_if!` with a `const
fn get_max_level_inner() -> LevelFilter` and uses `if cfg!(...)` inside.

Using if in const function is stablised in
[1.46](https://github.com/rust-lang/rust/blob/master/RELEASES.md#version-1460-2020-08-27)
so this should work fine in msrv 1.56

Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
2023-04-12 14:06:59 -07:00
Donough Liu
db64fc2d18 tracing: inline methods to make macro-generated code smaller (#2555)
## Motivation

Make `tracing::event!` codegen smaller

## Solution

Add `inline` to several functions called by `tracing::event!`.

Simple example: https://github.com/ldm0/tracing_test

After inlining, executable size drops from 746kb to 697kb
(`cargo build --release + strip`), saves 50 bytes per `event!`.

Test environment:
```
toolchain: nightly-aarch64-apple-darwin
rustc-version: rustc 1.70.0-nightly (88fb1b922 2023-04-10)
```

There are also performance improvements in the benchmarks:

```
event/scoped [-40.689% -40.475% -40.228%]
event/scoped_recording [-14.972% -14.685% -14.410%]
event/global [-48.412% -48.217% -48.010%]
span_fields/scoped [-25.317% -24.876% -24.494%]
span_fields/global [-39.695% -39.488% -39.242%]
span_repeated/global [-27.514% -26.633% -25.298%]
static/baseline_single_threaded [-32.275% -32.032% -31.808%]
static/single_threaded [-29.628% -29.376% -29.156%]
static/enabled_one [-29.777% -29.544% -29.305%]
static/enabled_many [-30.901% -30.504% -30.140%]
dynamic/baseline_single_threaded [-20.157% -19.880% -19.603%]
```

I retried benchmark several times and the improvements seem to be fairly
stable.

raw log: https://gist.github.com/ldm0/6573935f4979d2645fbcf5bde7361386
2023-04-11 15:43:23 -07:00
Eliza Weisman
49cbc5a68b chore: fix clippy::needless_borrow lint in journald tests (#2547) 2023-04-05 12:19:20 -07:00
David Barsky
1406b4cbe3 chore: bump MSRV to 1.56 (#2546)
As part of upgrading syn to 2.0 (e.g.,
https://github.com/tokio-rs/tracing/pull/2516), we need to bump the MSRV
to 1.56. As part of this PR, I've:
- Updated the text descriptions of what would be an in-policy MSRV bump
  to use more recent versions of rustc. The _niceness_ of said version
  numbers are purely coincidental.
- I've removed some of the exceptions made in CI.yml in order to support
  some crates with a higher MSRV.
2023-04-05 11:19:55 -07:00
David Barsky
666537c7d7 chore: move tracing-opentelemetry to its own repo (#2523)
This PR removes tracing-opentelemetry to a dedicated repo located at
https://github.com/tokio-rs/tracing-opentelemetry. (Note that at time of
writing this PR, the new repo has not be made public). We're moving
tracing-opentelemetry to a dedicated repository for the following
reasons:
1. opentelemetry's MSRV is higher than that of `tracing`'s.
2. more importantly, the main `tracing` repo is getting a bit unweildy
   and it feels unreasonable to maintain backports for crates that
   integrate with the larger tracing ecosystem.

(https://github.com/tokio-rs/tracing-opentelemetry does not have the
examples present in this repo; this will occur in a PR that will be
linked from _this_ PR.)
2023-04-04 16:18:53 -07:00
Arif Driessen
a0126b2e2d docs: fix typo in panic_hook example (#2453) 2023-02-08 10:26:50 -08:00
Scott Robinson
52fbf75818 attributes: document default level for err (#2433)
## Motivation

The current description for the default level of the `err` return value
event _strongly implies_ it's the same as the span. However, the
implementation actually defaults to `ERROR`.

## Solution

This PR documents that, so future generations don't have to chase down
the truth, like I did. 😉
2023-02-08 10:26:13 -08:00