Skip to content

Commit

Permalink
Merge branch 'v0.1.x' into hds/missed-register-callsite-fix-v0.1.x
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbarsky authored Nov 22, 2024
2 parents ff84eb5 + 6f08af0 commit ec2d78f
Show file tree
Hide file tree
Showing 80 changed files with 4,371 additions and 992 deletions.
24 changes: 13 additions & 11 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
name: cargo check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- name: Check
run: cargo check --all --tests --benches
Expand All @@ -46,7 +46,7 @@ jobs:
needs: check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt
Expand All @@ -58,7 +58,7 @@ jobs:
runs-on: ubuntu-latest
needs: check
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: clippy
Expand Down Expand Up @@ -88,7 +88,7 @@ jobs:
- tracing
- tracing-subscriber
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- name: install cargo-hack
uses: taiki-e/install-action@cargo-hack
Expand Down Expand Up @@ -146,7 +146,7 @@ jobs:
- 1.63.0
- stable
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: install Rust nightly
uses: dtolnay/rust-toolchain@nightly
- name: "install Rust ${{ matrix.toolchain }}"
Expand Down Expand Up @@ -210,7 +210,7 @@ jobs:
fail-fast: false
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: "install Rust ${{ matrix.rust }}"
uses: dtolnay/rust-toolchain@master
with:
Expand Down Expand Up @@ -252,7 +252,7 @@ jobs:
- tracing-tower
fail-fast: false
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
target: wasm32-unknown-unknown
Expand All @@ -268,9 +268,11 @@ jobs:
subcrate:
- tracing
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@stable
- uses: actions/checkout@v4
- name: Install Rust 1.81
uses: dtolnay/rust-toolchain@stable
with:
toolchain: 1.81
target: wasm32-unknown-unknown
- name: install test runner for wasm
uses: taiki-e/install-action@wasm-pack
Expand All @@ -283,7 +285,7 @@ jobs:
needs: check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- name: "Test log support"
run: cargo test
Expand Down Expand Up @@ -315,4 +317,4 @@ jobs:
- test-wasm
- test-features-stable
steps:
- run: exit 0
- run: exit 0
2 changes: 1 addition & 1 deletion .github/workflows/audit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
security_audit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: actions-rs/audit-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
if: github.repository_owner == 'tokio-rs'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: taiki-e/create-gh-release-action@v1
with:
prefix: tracing(-[a-z]+)?
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ members = [
"tracing-mock",
"tracing-subscriber",
"tracing-serde",
"tracing-test",
"tracing-appender",
"tracing-journald",
"examples"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ please let us know!)
[Tracy]: https://github.com/wolfpld/tracy
[`tracing-elastic-apm`]: https://crates.io/crates/tracing-elastic-apm
[Elastic APM]: https://www.elastic.co/apm
[`tracing-etw`]: https://github.com/microsoft/tracing-etw
[`tracing-etw`]: https://github.com/microsoft/rust_win_etw/tree/main/win_etw_tracing
[ETW]: https://docs.microsoft.com/en-us/windows/win32/etw/about-event-tracing
[`sentry-tracing`]: https://crates.io/crates/sentry-tracing
[Sentry]: https://sentry.io/welcome/
Expand Down
2 changes: 1 addition & 1 deletion examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "tracing-examples"
version = "0.0.0"
publish = false
edition = "2018"
rust-version = "1.63.0"
rust-version = "1.64.0"

[features]
default = []
Expand Down
3 changes: 2 additions & 1 deletion examples/examples/sloggish/sloggish_subscriber.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub struct CurrentSpanPerThread {
impl CurrentSpanPerThread {
pub fn new() -> Self {
thread_local! {
static CURRENT: RefCell<Vec<Id>> = const { RefCell::new(vec![]) };
static CURRENT: RefCell<Vec<Id>> = const { RefCell::new(Vec::new()) };
};
Self { current: &CURRENT }
}
Expand Down Expand Up @@ -239,6 +239,7 @@ impl Subscriber for SloggishSubscriber {
self.print_indent(&mut stderr, indent).unwrap();
stack.push(span_id.clone());
if let Some(data) = data {
#[allow(clippy::map_identity)] // TODO remove in Rust 1.77
self.print_kvs(&mut stderr, data.kvs.iter().map(|(k, v)| (k, v)), "")
.unwrap();
}
Expand Down
17 changes: 14 additions & 3 deletions tracing-attributes/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,25 @@ async-await = []

[dependencies]
proc-macro2 = "1.0.60"
syn = { version = "2.0", default-features = false, features = ["full", "parsing", "printing", "visit-mut", "clone-impls", "extra-traits", "proc-macro"] }
syn = { version = "2.0", default-features = false, features = [
"full",
"parsing",
"printing",
"visit-mut",
"clone-impls",
"extra-traits",
"proc-macro",
] }
quote = "1.0.20"

[dev-dependencies]
tracing = { path = "../tracing", version = "0.1.35" }
tracing-mock = { path = "../tracing-mock", features = ["tokio-test"] }
tracing-subscriber = { path = "../tracing-subscriber", version = "0.3.0", features = ["env-filter"] }
tracing-mock = { path = "../tracing-mock" }
tokio-test = "0.4.2"
tracing-subscriber = { path = "../tracing-subscriber", version = "0.3.0", features = [
"env-filter",
] }
tracing-test = { path = "../tracing-test" }
async-trait = "0.1.67"
trybuild = "1.0.64"
rustversion = "1.0.9"
Expand Down
32 changes: 29 additions & 3 deletions tracing-attributes/src/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ pub(crate) struct EventArgs {
#[derive(Clone, Default, Debug)]
pub(crate) struct InstrumentArgs {
level: Option<Level>,
pub(crate) name: Option<LitStr>,
target: Option<LitStr>,
pub(crate) name: Option<LitStrOrIdent>,
target: Option<LitStrOrIdent>,
pub(crate) parent: Option<Expr>,
pub(crate) follows_from: Option<Expr>,
pub(crate) skips: HashSet<Ident>,
Expand Down Expand Up @@ -87,6 +87,8 @@ impl Parse for InstrumentArgs {
// XXX: apparently we support names as either named args with an
// sign, _or_ as unnamed string literals. That's weird, but
// changing it is apparently breaking.
// This also means that when using idents for name, it must be via
// a named arg, i.e. `#[instrument(name = SOME_IDENT)]`.
if args.name.is_some() {
return Err(input.error("expected only a single `name` argument"));
}
Expand Down Expand Up @@ -211,8 +213,32 @@ impl Parse for EventArgs {
}
}

#[derive(Debug, Clone)]
pub(super) enum LitStrOrIdent {
LitStr(LitStr),
Ident(Ident),
}

impl ToTokens for LitStrOrIdent {
fn to_tokens(&self, tokens: &mut TokenStream) {
match self {
LitStrOrIdent::LitStr(target) => target.to_tokens(tokens),
LitStrOrIdent::Ident(ident) => ident.to_tokens(tokens),
}
}
}

impl Parse for LitStrOrIdent {
fn parse(input: ParseStream<'_>) -> syn::Result<Self> {
input
.parse::<LitStr>()
.map(LitStrOrIdent::LitStr)
.or_else(|_| input.parse::<Ident>().map(LitStrOrIdent::Ident))
}
}

struct StrArg<T> {
value: LitStr,
value: LitStrOrIdent,
_p: std::marker::PhantomData<T>,
}

Expand Down
21 changes: 11 additions & 10 deletions tracing-attributes/tests/async_fn.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use tracing_mock::*;

use std::convert::Infallible;
use std::{future::Future, pin::Pin, sync::Arc};

use tracing::subscriber::with_default;
use tracing_attributes::instrument;
use tracing_mock::{expect, subscriber};
use tracing_test::{block_on_future, PollN};

#[instrument]
async fn test_async_fn(polls: usize) -> Result<(), ()> {
Expand Down Expand Up @@ -199,8 +200,8 @@ fn async_fn_with_async_trait() {
let (subscriber, handle) = subscriber::mock()
.new_span(
span.clone()
.with_field(expect::field("self"))
.with_field(expect::field("v")),
.with_fields(expect::field("self"))
.with_fields(expect::field("v")),
)
.enter(span.clone())
.new_span(span3.clone())
Expand All @@ -210,7 +211,7 @@ fn async_fn_with_async_trait() {
.enter(span3.clone())
.exit(span3.clone())
.drop_span(span3)
.new_span(span2.clone().with_field(expect::field("self")))
.new_span(span2.clone().with_fields(expect::field("self")))
.enter(span2.clone())
.event(expect::event().with_fields(expect::field("val").with_value(&5u64)))
.exit(span2.clone())
Expand Down Expand Up @@ -260,7 +261,7 @@ fn async_fn_with_async_trait_and_fields_expressions() {
let span = expect::span().named("call");
let (subscriber, handle) = subscriber::mock()
.new_span(
span.clone().with_field(
span.clone().with_fields(
expect::field("_v")
.with_value(&5usize)
.and(expect::field("test").with_value(&tracing::field::debug(10)))
Expand Down Expand Up @@ -330,21 +331,21 @@ fn async_fn_with_async_trait_and_fields_expressions_with_generic_parameter() {
let span4 = expect::span().named("sync_fun");
let (subscriber, handle) = subscriber::mock()
/*.new_span(span.clone()
.with_field(
.with_fields(
expect::field("Self").with_value(&"TestImpler")))
.enter(span.clone())
.exit(span.clone())
.drop_span(span)*/
.new_span(
span2
.clone()
.with_field(expect::field("Self").with_value(&std::any::type_name::<TestImpl>())),
.with_fields(expect::field("Self").with_value(&std::any::type_name::<TestImpl>())),
)
.enter(span2.clone())
.new_span(
span4
.clone()
.with_field(expect::field("Self").with_value(&std::any::type_name::<TestImpl>())),
.with_fields(expect::field("Self").with_value(&std::any::type_name::<TestImpl>())),
)
.enter(span4.clone())
.exit(span4.clone())
Expand All @@ -357,7 +358,7 @@ fn async_fn_with_async_trait_and_fields_expressions_with_generic_parameter() {
.new_span(
span3
.clone()
.with_field(expect::field("Self").with_value(&std::any::type_name::<TestImpl>())),
.with_fields(expect::field("Self").with_value(&std::any::type_name::<TestImpl>())),
)
.enter(span3.clone())
.exit(span3.clone())
Expand Down
12 changes: 6 additions & 6 deletions tracing-attributes/tests/destructuring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fn destructure_tuples() {

let (subscriber, handle) = subscriber::mock()
.new_span(
span.clone().with_field(
span.clone().with_fields(
expect::field("arg1")
.with_value(&format_args!("1"))
.and(expect::field("arg2").with_value(&format_args!("2")))
Expand Down Expand Up @@ -40,7 +40,7 @@ fn destructure_nested_tuples() {

let (subscriber, handle) = subscriber::mock()
.new_span(
span.clone().with_field(
span.clone().with_fields(
expect::field("arg1")
.with_value(&format_args!("1"))
.and(expect::field("arg2").with_value(&format_args!("2")))
Expand Down Expand Up @@ -72,7 +72,7 @@ fn destructure_refs() {
let (subscriber, handle) = subscriber::mock()
.new_span(
span.clone()
.with_field(expect::field("arg1").with_value(&1usize).only()),
.with_fields(expect::field("arg1").with_value(&1usize).only()),
)
.enter(span.clone())
.exit(span.clone())
Expand All @@ -98,7 +98,7 @@ fn destructure_tuple_structs() {

let (subscriber, handle) = subscriber::mock()
.new_span(
span.clone().with_field(
span.clone().with_fields(
expect::field("arg1")
.with_value(&format_args!("1"))
.and(expect::field("arg2").with_value(&format_args!("2")))
Expand Down Expand Up @@ -139,7 +139,7 @@ fn destructure_structs() {

let (subscriber, handle) = subscriber::mock()
.new_span(
span.clone().with_field(
span.clone().with_fields(
expect::field("arg1")
.with_value(&format_args!("1"))
.and(expect::field("arg2").with_value(&format_args!("2")))
Expand Down Expand Up @@ -184,7 +184,7 @@ fn destructure_everything() {

let (subscriber, handle) = subscriber::mock()
.new_span(
span.clone().with_field(
span.clone().with_fields(
expect::field("arg1")
.with_value(&format_args!("1"))
.and(expect::field("arg2").with_value(&format_args!("2")))
Expand Down
3 changes: 2 additions & 1 deletion tracing-attributes/tests/err.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use tracing_attributes::instrument;
use tracing_mock::*;
use tracing_subscriber::filter::EnvFilter;
use tracing_subscriber::layer::SubscriberExt;
use tracing_test::{block_on_future, PollN};

use std::convert::TryFrom;
use std::num::TryFromIntError;
Expand Down Expand Up @@ -159,7 +160,7 @@ fn impl_trait_return_type() {
let (subscriber, handle) = subscriber::mock()
.new_span(
span.clone()
.with_field(expect::field("x").with_value(&10usize).only()),
.with_fields(expect::field("x").with_value(&10usize).only()),
)
.enter(span.clone())
.exit(span.clone())
Expand Down
Loading

0 comments on commit ec2d78f

Please sign in to comment.