Skip to content

Commit

Permalink
build: ensure msrv 1.80.1 and upgrade dependencies (#20)
Browse files Browse the repository at this point in the history
Signed-off-by: tison <[email protected]>
  • Loading branch information
tisonkun authored Aug 12, 2024
1 parent 024c101 commit 5c8c23b
Show file tree
Hide file tree
Showing 15 changed files with 80 additions and 77 deletions.
71 changes: 36 additions & 35 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,42 +13,43 @@ jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [windows-latest, macos-latest, ubuntu-latest]
rust: [stable, nightly]
os: [ windows-latest, macos-latest, ubuntu-latest ]
rust: [ "1.80.1", stable, nightly ]
env:
RUST_BACKTRACE: 1
steps:
- uses: actions/checkout@v4
- uses: Swatinem/rust-cache@v2
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust }}
components: rustfmt, clippy

- name: Check format
if: ${{ matrix.rust == 'nightly' }}
run: cargo fmt --all -- --check

- name: Check clippy
if: ${{ matrix.rust == 'nightly' }}
run: cargo clippy --all-targets --all-features -- --deny warnings

- name: Build
run: cargo build --workspace --all-targets

- name: Run tests
run: |
cargo test --workspace --all-targets -- --nocapture
cargo test --doc
# GitHub Action sometimes run out of resources to run benches
# - name: Run benches
# run: cargo bench --workspace --bench compare --bench trace

- name: Run examples
run: |
cargo run --example asynchronous
cargo run --example synchronous
cargo run --example get_started
cargo run --package test-statically-disable
- uses: actions/checkout@v4
- uses: Swatinem/rust-cache@v2
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust }}
components: rustfmt, clippy

- name: Check format
if: ${{ matrix.rust == 'nightly' }}
run: cargo fmt --all -- --check

- name: Check clippy
if: ${{ matrix.rust == 'nightly' }}
run: cargo clippy --all-targets --all-features -- --deny warnings

- name: Build
run: cargo build --workspace --all-targets

- name: Run tests
run: |
cargo test --workspace --all-targets -- --nocapture
cargo test --doc
# GitHub Action sometimes run out of resources to run benches
# - name: Run benches
# run: cargo bench --workspace --bench compare --bench trace

- name: Run examples
run: |
cargo run --example asynchronous
cargo run --example synchronous
cargo run --example get_started
cargo run --package test-statically-disable
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ authors = ["Fastrace Authors"]
edition = "2021"
license = "Apache-2.0"
repository = "https://github.com/fastracelabs/fastrace"
rust-version = "1.80.1"

[workspace.dependencies]
# workspace dependencies
Expand Down
15 changes: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

[![Crates.io](https://img.shields.io/crates/v/fastrace.svg?style=flat-square&logo=rust)](https://crates.io/crates/fastrace)
[![Documentation](https://img.shields.io/docsrs/fastrace?style=flat-square&logo=rust)](https://docs.rs/fastrace/)
[![MSRV 1.80.1](https://img.shields.io/badge/MSRV-1.80.1-green?style=flat-square&logo=rust)](https://www.whatrustisit.com)
[![CI Status](https://img.shields.io/github/actions/workflow/status/fastracelabs/fastrace/ci.yml?style=flat-square&logo=github)](https://github.com/fastracelabs/fastrace/actions)
[![Coverage](https://img.shields.io/coveralls/github/fastracelabs/fastrace?style=flat-square)](https://coveralls.io/github/fastracelabs/fastrace?branch=main)
[![License](https://img.shields.io/crates/l/fastrace?style=flat-square)](https://github.com/fastracelabs/fastrace/blob/main/LICENSE)
Expand Down Expand Up @@ -107,14 +108,18 @@ fn main() {

![Benchmark result by number of spans](etc/img/benchmark-spans.svg)

| | 1 span | 10 spans | 100 spans | 1000 spans |
|----------------------|-------------|------------|-------------|-------------|
| tokio-tracing | 19x slower | 61x slower | 124x slower | 151x slower |
| rustracing | 13x slower | 26x slower | 45x slower | 55x slower |
| fastrace (baseline) | 1x (0.4us) | 1x (0.8us) | 1x (3.4us) | 1x (27.8us) |
| | 1 span | 10 spans | 100 spans | 1000 spans |
|---------------------|------------|------------|-------------|-------------|
| tokio-tracing | 19x slower | 61x slower | 124x slower | 151x slower |
| rustracing | 13x slower | 26x slower | 45x slower | 55x slower |
| fastrace (baseline) | 1x (0.4us) | 1x (0.8us) | 1x (3.4us) | 1x (27.8us) |

Detailed results are available in [etc/benchmark-result](etc/benchmark-result).

## Supported Rust Versions (MSRV 1.80.1)

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

## Projects using fastrace

Feel free to open a PR and add your projects here:
Expand Down
1 change: 1 addition & 0 deletions fastrace-datadog/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ authors.workspace = true
edition.workspace = true
license.workspace = true
repository.workspace = true
rust-version.workspace = true

[dependencies]
fastrace = { workspace = true }
Expand Down
1 change: 1 addition & 0 deletions fastrace-futures/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ authors.workspace = true
edition.workspace = true
license.workspace = true
repository.workspace = true
rust-version.workspace = true

[dependencies]
fastrace = { workspace = true }
Expand Down
1 change: 1 addition & 0 deletions fastrace-jaeger/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ authors.workspace = true
edition.workspace = true
license.workspace = true
repository.workspace = true
rust-version.workspace = true

[dependencies]
fastrace = { workspace = true }
Expand Down
4 changes: 2 additions & 2 deletions fastrace-macro/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ authors.workspace = true
edition.workspace = true
license.workspace = true
repository.workspace = true
rust-version.workspace = true

[lib]
proc-macro = true

[dependencies]
# The macro `quote_spanned!` is added to syn in 1.0.84
proc-macro-error = "1.0"
proc-macro2 = "1.0"
quote = "1.0"
syn = { version = "1.0.84", features = [
syn = { version = "2.0", features = [
"full",
"parsing",
"extra-traits",
Expand Down
32 changes: 13 additions & 19 deletions fastrace-macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
// `async fn` into a normal fn which returns `Box<impl Future>`, and this stops the macro from
// distinguishing `async fn` from `fn`. The following code reused the `async_trait` probes from [tokio-tracing](https://github.com/tokio-rs/tracing/blob/6a61897a5e834988ad9ac709e28c93c4dbf29116/tracing-attributes/src/expand.rs).

extern crate proc_macro;

#[macro_use]
extern crate proc_macro_error;

Expand Down Expand Up @@ -57,7 +55,7 @@ impl Parse for Args {
while !input.is_empty() {
let ident: Ident = input.parse()?;
if seen.contains_key(&ident.to_string()) {
return Err(syn::Error::new(ident.span(), "duplicate argument"));
return Err(Error::new(ident.span(), "duplicate argument"));
}
seen.insert(ident.to_string(), ());
input.parse::<Token![=]>()?;
Expand All @@ -76,20 +74,16 @@ impl Parse for Args {
}
"properties" => {
let content;
let _brace_token = syn::braced!(content in input);
let property_list: Punctuated<Property, Token![,]> =
content.parse_terminated(Property::parse)?;
let _brace_token = braced!(content in input);
let property_list = content.parse_terminated(Property::parse, Token![,])?;
for property in property_list {
if properties.iter().any(|(k, _)| k == &property.key) {
return Err(syn::Error::new(
Span::call_site(),
"duplicate property key",
));
return Err(Error::new(Span::call_site(), "duplicate property key"));
}
properties.push((property.key, property.value));
}
}
_ => return Err(syn::Error::new(Span::call_site(), "unexpected identifier")),
_ => return Err(Error::new(Span::call_site(), "unexpected identifier")),
}
if !input.is_empty() {
let _ = input.parse::<Token![,]>();
Expand Down Expand Up @@ -202,7 +196,7 @@ pub fn trace(
item: proc_macro::TokenStream,
) -> proc_macro::TokenStream {
let args = parse_macro_input!(args as Args);
let input = syn::parse_macro_input!(item as ItemFn);
let input = parse_macro_input!(item as ItemFn);

let func_name = input.sig.ident.to_string();
// check for async_trait-like patterns in the block, and instrument
Expand Down Expand Up @@ -272,7 +266,7 @@ pub fn trace(
.into()
}

fn gen_name(span: proc_macro2::Span, func_name: &str, args: &Args) -> proc_macro2::TokenStream {
fn gen_name(span: Span, func_name: &str, args: &Args) -> proc_macro2::TokenStream {
match &args.name {
Some(name) if name.is_empty() => {
abort_call_site!("`name` can not be empty")
Expand All @@ -298,7 +292,7 @@ fn gen_name(span: proc_macro2::Span, func_name: &str, args: &Args) -> proc_macro
}
}

fn gen_properties(span: proc_macro2::Span, args: &Args) -> proc_macro2::TokenStream {
fn gen_properties(span: Span, args: &Args) -> proc_macro2::TokenStream {
if args.properties.is_empty() {
return quote::quote!();
}
Expand Down Expand Up @@ -424,7 +418,7 @@ struct AsyncTraitInfo<'a> {
// (this follows the approach suggested in
// https://github.com/dtolnay/async-trait/issues/45#issuecomment-571245673)
fn get_async_trait_info(block: &Block, block_is_async: bool) -> Option<AsyncTraitInfo<'_>> {
// are we in an async context? If yes, this isn't a async_trait-like pattern
// are we in an async context? If yes, this isn't an async_trait-like pattern
if block_is_async {
return None;
}
Expand All @@ -445,7 +439,7 @@ fn get_async_trait_info(block: &Block, block_is_async: bool) -> Option<AsyncTrai
// `trait` or `impl` declaration is annotated by async_trait,
// this is quite likely the point where the future is pinned)
let (last_expr_stmt, last_expr) = block.stmts.iter().rev().find_map(|stmt| {
if let Stmt::Expr(expr) = stmt {
if let Stmt::Expr(expr, None) = stmt {
Some((stmt, expr))
} else {
None
Expand All @@ -468,8 +462,8 @@ fn get_async_trait_info(block: &Block, block_is_async: bool) -> Option<AsyncTrai
}

// Does the call take an argument? If it doesn't,
// it's not gonna compile anyway, but that's no reason
// to (try to) perform an out of bounds access
// it's not going to compile anyway, but that's no reason
// to (try to) perform an out-of-bounds access
if outside_args.is_empty() {
return None;
}
Expand Down Expand Up @@ -498,7 +492,7 @@ fn get_async_trait_info(block: &Block, block_is_async: bool) -> Option<AsyncTrai
_ => return None,
};

// Was that function defined inside of the current block?
// Was that function defined inside the current block?
// If so, retrieve the statement where it was declared and the function itself
let (stmt_func_declaration, _) = inside_funs
.into_iter()
Expand Down
2 changes: 1 addition & 1 deletion fastrace-macro/tests/ui/err/has-expr-argument.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: expected identifier
error: expected identifier, found keyword `true`
--> tests/ui/err/has-expr-argument.rs:5:9
|
5 | #[trace(true)]
Expand Down
2 changes: 1 addition & 1 deletion fastrace-macro/tests/ui/err/trace-interleaved.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: expected identifier
error: expected identifier, found keyword `struct`
--> tests/ui/err/trace-interleaved.rs:6:9
|
6 | #[trace(struct)]
Expand Down
2 changes: 1 addition & 1 deletion fastrace-macro/tests/ui/ok/async-in-trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ impl MyTrait for MyStruct {
// #[logcall::logcall("info")]
#[fastrace::trace]
async fn work(&self) -> usize {
todo!()
unimplemented!()
}
}

Expand Down
2 changes: 1 addition & 1 deletion fastrace-macro/tests/ui/ok/async-trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ impl MyTrait for MyStruct {
#[logcall::logcall("info")]
#[fastrace::trace]
async fn work(&self) -> usize {
todo!()
unimplemented!()
}
}

Expand Down
1 change: 1 addition & 0 deletions fastrace-opentelemetry/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ authors.workspace = true
edition.workspace = true
license.workspace = true
repository.workspace = true
rust-version.workspace = true

[dependencies]
fastrace = { workspace = true }
Expand Down
8 changes: 3 additions & 5 deletions fastrace/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ authors.workspace = true
edition.workspace = true
license.workspace = true
repository.workspace = true
rust-version.workspace = true

[features]
enable = []
Expand All @@ -21,8 +22,6 @@ fastrace-macro = { workspace = true }
minstant = "0.1"
parking_lot = "0.12"
pin-project = "1.1"
# TODO: Remove once_cell once #![feature(once_cell)] is stabilized
once_cell = "1.19"
rand = "0.8"
rtrb = "0.3"

Expand All @@ -40,8 +39,7 @@ futures = { workspace = true }
futures-timer = "3"
log = { workspace = true }
logcall = "0.1"
mockall = "0.12"
once_cell = "1.19"
mockall = "0.13"
opentelemetry = { version = "0.24", features = ["trace"] }
opentelemetry-otlp = { version = "0.17", features = ["trace"] }
opentelemetry_sdk = { version = "0.24", features = ["trace"] }
Expand All @@ -57,7 +55,7 @@ tokio = { version = "1.38", features = [
] }
tracing = "0.1"
tracing-core = "0.1"
tracing-opentelemetry = "0.24"
tracing-opentelemetry = "0.25"
tracing-subscriber = "0.3"

[[bench]]
Expand Down
14 changes: 7 additions & 7 deletions fastrace/src/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@ pub mod tree;

use std::borrow::Cow;
use std::cell::RefCell;

use once_cell::sync::Lazy;
use std::sync::LazyLock;

use crate::collector::CollectTokenItem;
use crate::local::raw_span::RawSpan;
use crate::util::object_pool::Pool;
use crate::util::object_pool::Puller;
use crate::util::object_pool::Reusable;

static RAW_SPANS_POOL: Lazy<Pool<Vec<RawSpan>>> = Lazy::new(|| Pool::new(Vec::new, Vec::clear));
static COLLECT_TOKEN_ITEMS_POOL: Lazy<Pool<Vec<CollectTokenItem>>> =
Lazy::new(|| Pool::new(Vec::new, Vec::clear));
static RAW_SPANS_POOL: LazyLock<Pool<Vec<RawSpan>>> =
LazyLock::new(|| Pool::new(Vec::new, Vec::clear));
static COLLECT_TOKEN_ITEMS_POOL: LazyLock<Pool<Vec<CollectTokenItem>>> =
LazyLock::new(|| Pool::new(Vec::new, Vec::clear));
#[allow(clippy::type_complexity)]
static PROPERTIES_POOL: Lazy<Pool<Vec<(Cow<'static, str>, Cow<'static, str>)>>> =
Lazy::new(|| Pool::new(Vec::new, Vec::clear));
static PROPERTIES_POOL: LazyLock<Pool<Vec<(Cow<'static, str>, Cow<'static, str>)>>> =
LazyLock::new(|| Pool::new(Vec::new, Vec::clear));

thread_local! {
static RAW_SPANS_PULLER: RefCell<Puller<'static, Vec<RawSpan>>> = RefCell::new(RAW_SPANS_POOL.puller(512));
Expand Down

0 comments on commit 5c8c23b

Please sign in to comment.