diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b01d5d4e..1e84f279 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,8 +12,6 @@ env: jobs: check: runs-on: ubuntu-24.04 - env: - FORCE_COLOR: 1 steps: - uses: actions/checkout@v6 - uses: crate-ci/typos@master @@ -23,15 +21,25 @@ jobs: - uses: dtolnay/rust-toolchain@master with: toolchain: nightly - components: rustfmt, clippy + components: rustfmt,clippy - name: Cargo version run: cargo --version - - name: Check format - run: cargo fmt --all -- --check - - name: Check clippy - run: cargo clippy --all-targets --all-features -- --deny warnings + - name: Check workspace + run: | + cargo fmt --all -- --check + cargo clippy --all-targets --all-features -- --deny warnings + - name: Check benches + working-directory: benches + run: | + cargo fmt --all -- --check + cargo clippy --all-targets --all-features -- --deny warnings + - name: Check examples + working-directory: examples + run: | + cargo fmt --all -- --check + cargo clippy --all-targets --all-features -- --deny warnings - test: + tests: runs-on: ${{ matrix.os }} strategy: fail-fast: false @@ -50,21 +58,36 @@ jobs: - uses: taiki-e/install-action@v2 with: tool: nextest,cargo-nextest - - name: Cargo version run: cargo --version - - name: Build - run: cargo build --workspace --all-targets - - - name: Run tests + - name: Run workspace tests run: | + cargo build --workspace --all-features --all-targets cargo nextest run --workspace cargo test --doc - name: Run examples + working-directory: examples + shell: bash run: | - cargo run --example asynchronous - cargo run --example synchronous - cargo run --example basic - cargo run --package test-statically-disable + set -euo pipefail + + cargo metadata --no-deps --format-version 1 | jq -er ' + [ + .packages[] as $package + | $package.targets[] + | select(.kind | index("bin")) + | [$package.name, .name] + | @tsv + ] + | if length == 0 then error("no runnable example targets found") else .[] end + ' | tr -d '\r' | while IFS=$'\t' read -r package target; do + echo "::group::cargo run --package ${package} --bin ${target}" + cargo run --package "${package}" --bin "${target}" + echo "::endgroup::" + done + + - name: Run benches + working-directory: benches + run: cargo bench --workspace diff --git a/.gitignore b/.gitignore index bc92265e..ea8c4bf7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1 @@ /target -/wip - -.editorconfig -.idea diff --git a/Cargo.lock b/Cargo.lock index a8ef0503..4d8419bd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -94,47 +94,6 @@ dependencies = [ "rand_core 0.10.1", ] -[[package]] -name = "clap" -version = "4.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ddb117e43bbf7dacf0a4190fef4d345b9bad68dfc649cb349e7d17d28428e51" -dependencies = [ - "clap_builder", -] - -[[package]] -name = "clap_builder" -version = "4.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "714a53001bf66416adb0e2ef5ac857140e7dc3a0c48fb28b2f10762fc4b5069f" -dependencies = [ - "anstyle", - "clap_lex", - "terminal_size", -] - -[[package]] -name = "clap_lex" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8d4a3bb8b1e0c1050499d1815f5ab16d04f0959b233085fb31653fbfc9d98f9" - -[[package]] -name = "colored" -version = "3.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "faf9468729b8cbcea668e36183cb69d317348c2e08e994829fb56ebfdfbaac34" -dependencies = [ - "windows-sys", -] - -[[package]] -name = "condtype" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf0a07a401f374238ab8e2f11a104d2851bf9ce711ec69804834de8af45c7af" - [[package]] name = "console" version = "0.16.3" @@ -211,31 +170,6 @@ version = "0.8.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28" -[[package]] -name = "divan" -version = "0.1.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a405457ec78b8fe08b0e32b4a3570ab5dff6dd16eb9e76a5ee0a9d9cbd898933" -dependencies = [ - "cfg-if", - "clap", - "condtype", - "divan-macros", - "libc", - "regex-lite", -] - -[[package]] -name = "divan-macros" -version = "0.1.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9556bc800956545d6420a640173e5ba7dfa82f38d3ea5a167eb555bc69ac3323" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "downcast" version = "0.11.0" @@ -270,23 +204,6 @@ dependencies = [ "windows-sys", ] -[[package]] -name = "example" -version = "0.0.0" -dependencies = [ - "anyhow", - "fastrace", - "fastrace-opentelemetry", - "log", - "logcall", - "logforth", - "opentelemetry", - "opentelemetry-otlp", - "opentelemetry_sdk", - "test-harness", - "tokio", -] - [[package]] name = "fastant" version = "0.1.11" @@ -301,31 +218,19 @@ dependencies = [ name = "fastrace" version = "0.7.18" dependencies = [ - "async-trait", "crossbeam", - "divan", "fastant", "fastrace", "fastrace-macro", - "fastrace-opentelemetry", - "flume", "futures-timer", - "insta", "mockall", - "opentelemetry", - "opentelemetry-otlp", - "opentelemetry_sdk", "parking_lot", "pin-project", "pollster", "rand 0.10.1", "rtrb", "serde", - "serial_test", "tokio", - "tracing", - "tracing-opentelemetry", - "tracing-subscriber", ] [[package]] @@ -368,21 +273,6 @@ name = "fastrand" version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9f1f227452a390804cdb637b74a86990f2a7d7ba4b7d5693aac9b4dd6defd8d6" -dependencies = [ - "getrandom 0.3.4", -] - -[[package]] -name = "flume" -version = "0.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e139bc46ca777eb5efaf62df0ab8cc5fd400866427e56c68b22e414e53bd3be" -dependencies = [ - "fastrand", - "futures-core", - "futures-sink", - "spin", -] [[package]] name = "fnv" @@ -506,11 +396,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "899def5c37c4fd7b2664648c28120ecec138e4d395b459e5ca34f9cce2dd77fd" dependencies = [ "cfg-if", - "js-sys", "libc", "r-efi 5.3.0", "wasip2", - "wasm-bindgen", ] [[package]] @@ -711,47 +599,6 @@ version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" -[[package]] -name = "jiff" -version = "0.2.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4603d3033e49e2b0e31229fcab20a5d40089c607d975cd9c80551dc69eed9102" -dependencies = [ - "jiff-static", - "jiff-tzdb-platform", - "log", - "portable-atomic", - "portable-atomic-util", - "serde_core", - "windows-link", -] - -[[package]] -name = "jiff-static" -version = "0.2.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "782d32378dddf207193ac91cefb848ad41abb58195c95168e1291227a0832b47" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "jiff-tzdb" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c900ef84826f1338a557697dc8fc601df9ca9af4ac137c7fb61d4c6f2dfd3076" - -[[package]] -name = "jiff-tzdb-platform" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "875a5a69ac2bab1a891711cf5eccbec1ce0341ea805560dcd90b7a2e925132e8" -dependencies = [ - "jiff-tzdb", -] - [[package]] name = "js-sys" version = "0.3.102" @@ -763,12 +610,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "lazy_static" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" - [[package]] name = "leb128fmt" version = "0.1.0" @@ -813,106 +654,6 @@ dependencies = [ "syn", ] -[[package]] -name = "logforth" -version = "0.30.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "522000d3921e4b089de59204d2d3ca8792cd53f8ce5a54b5ac8b9a6e867259f0" -dependencies = [ - "log", - "logforth-append-fastrace", - "logforth-append-file", - "logforth-bridge-log", - "logforth-core", - "logforth-diagnostic-fastrace", - "logforth-filter-rustlog", - "logforth-layout-json", - "logforth-layout-text", -] - -[[package]] -name = "logforth-append-fastrace" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "107b4296c4dfbdca6eb3a29a0414e374d1f06e7e7738f16e28dd6b8079cb59ec" -dependencies = [ - "fastrace", - "jiff", - "logforth-core", -] - -[[package]] -name = "logforth-append-file" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80f4ed78a03a30c12285135d98330f0f5d53cb0019bd1ac6d66863dae72d8d52" -dependencies = [ - "jiff", - "logforth-core", -] - -[[package]] -name = "logforth-bridge-log" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c7224c78547e542572ae4d1f787f96c4395a4c3f24513bf221bd8e49888f610" -dependencies = [ - "log", - "logforth-core", -] - -[[package]] -name = "logforth-core" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "400ba5305e0cb6819efa6c2c503020562eb5b47fd53c91c935be55af1ffd374e" -dependencies = [ - "anyhow", - "serde", -] - -[[package]] -name = "logforth-diagnostic-fastrace" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95df712f493a6e50ab7bb10ca76ddafc3b80cf23a998b88cc3f8e8bd285d9f18" -dependencies = [ - "fastrace", - "logforth-core", -] - -[[package]] -name = "logforth-filter-rustlog" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e8431cfa1d3eeca479c363651320a66c7003350528f678b30e8c1474fb0d802" -dependencies = [ - "logforth-core", -] - -[[package]] -name = "logforth-layout-json" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d86a105f8f32151ca1e0a6d4097d478badb02d5715239ba0fa431a188a5d966" -dependencies = [ - "jiff", - "logforth-core", - "serde", - "serde_json", -] - -[[package]] -name = "logforth-layout-text" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4eafe007ac55293d807e8c7f5a23002e2518d32e476e195443cde23e7845416a" -dependencies = [ - "colored", - "jiff", - "logforth-core", -] - [[package]] name = "memchr" version = "2.8.2" @@ -956,15 +697,6 @@ dependencies = [ "syn", ] -[[package]] -name = "nu-ansi-term" -version = "0.50.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7957b9740744892f114936ab4a57b3f487491bbeafaf8083688b16841a4240e5" -dependencies = [ - "windows-sys", -] - [[package]] name = "once_cell" version = "1.21.4" @@ -1097,15 +829,6 @@ version = "1.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c33a9471896f1c69cecef8d20cbe2f7accd12527ce60845ff44c153bb2a21b49" -[[package]] -name = "portable-atomic-util" -version = "0.2.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2a106d1259c23fac8e543272398ae0e3c0b8d33c88ed73d0cc71b0f1d902618" -dependencies = [ - "portable-atomic", -] - [[package]] name = "ppv-lite86" version = "0.2.21" @@ -1268,12 +991,6 @@ dependencies = [ "bitflags", ] -[[package]] -name = "regex-lite" -version = "0.1.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cab834c73d247e67f4fae452806d17d3c7501756d98c8808d7c9c7aa7d18f973" - [[package]] name = "rtrb" version = "0.3.4" @@ -1388,15 +1105,6 @@ dependencies = [ "syn", ] -[[package]] -name = "sharded-slab" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6" -dependencies = [ - "lazy_static", -] - [[package]] name = "signal-hook-registry" version = "1.4.8" @@ -1441,15 +1149,6 @@ dependencies = [ "windows-sys", ] -[[package]] -name = "spin" -version = "0.9.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" -dependencies = [ - "lock_api", -] - [[package]] name = "syn" version = "2.0.118" @@ -1495,16 +1194,6 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "terminal_size" -version = "0.4.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "230a1b821ccbd75b185820a1f1ff7b14d21da1e442e22c0863ea5f08771a8874" -dependencies = [ - "rustix", - "windows-sys", -] - [[package]] name = "termtree" version = "0.5.1" @@ -1512,18 +1201,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f50febec83f5ee1df3015341d8bd429f2d1cc62bcba7ea2076759d315084683" [[package]] -name = "test-harness" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "540dedb2dcfa0cff7a79ec955936440a13a75839b6ac14b834a8bbae929bb489" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "test-macros-ui" +name = "tests-build" version = "0.0.0" dependencies = [ "async-stream", @@ -1537,10 +1215,17 @@ dependencies = [ ] [[package]] -name = "test-statically-disable" +name = "tests-integration" version = "0.0.0" dependencies = [ + "async-trait", + "crossbeam", "fastrace", + "futures-timer", + "insta", + "pollster", + "serial_test", + "tokio", ] [[package]] @@ -1563,15 +1248,6 @@ dependencies = [ "syn", ] -[[package]] -name = "thread_local" -version = "1.1.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f60246a4944f24f6e018aa17cdeffb7818b76356965d03b07d6a9886e8962185" -dependencies = [ - "cfg-if", -] - [[package]] name = "tokio" version = "1.52.3" @@ -1771,48 +1447,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a" dependencies = [ "once_cell", - "valuable", -] - -[[package]] -name = "tracing-log" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3" -dependencies = [ - "log", - "once_cell", - "tracing-core", -] - -[[package]] -name = "tracing-opentelemetry" -version = "0.33.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "adbc64cba7137545b8044cb1fe9814f7aacf3c6b5f9b45be8bb5db538befdb26" -dependencies = [ - "js-sys", - "opentelemetry", - "smallvec", - "tracing", - "tracing-core", - "tracing-log", - "tracing-subscriber", - "web-time", -] - -[[package]] -name = "tracing-subscriber" -version = "0.3.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb7f578e5945fb242538965c2d0b04418d38ec25c79d160cd279bf0731c8d319" -dependencies = [ - "nu-ansi-term", - "sharded-slab", - "smallvec", - "thread_local", - "tracing-core", - "tracing-log", ] [[package]] @@ -1848,12 +1482,6 @@ version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" -[[package]] -name = "valuable" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba73ea9cf16a25df0c8caa16c51acb937d5712a8429db78a3ee29d5dcacd3a65" - [[package]] name = "want" version = "0.3.1" diff --git a/Cargo.toml b/Cargo.toml index f3caba9c..31b73967 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,34 +1,28 @@ [workspace] -members = [ - "fastrace", - "fastrace-macro", - "fastrace-opentelemetry", - "fastrace-futures", - - # non-publish crates - "examples", - "tests/macros", - "tests/statically-disable", -] -resolver = "2" +exclude = ["benches", "examples"] +members = ["crates/*", "tests-build", "tests-integration"] +resolver = "3" [workspace.package] edition = "2024" license = "Apache-2.0" +readme = "README.md" repository = "https://github.com/fast/fastrace" rust-version = "1.91.0" [workspace.dependencies] # Workspace dependencies -fastrace = { version = "0.7.18", path = "fastrace" } -fastrace-macro = { version = "0.7.18", path = "fastrace-macro" } - -# Workspace leaves -fastrace-futures = { path = "fastrace-futures" } -fastrace-opentelemetry = { path = "fastrace-opentelemetry" } +fastrace = { version = "0.7.18", path = "crates/fastrace" } +fastrace-futures = { path = "crates/fastrace-futures" } +fastrace-macro = { version = "0.7.18", path = "crates/fastrace-macro" } +fastrace-opentelemetry = { path = "crates/fastrace-opentelemetry" } # crates.io dependencies -log = { version = "0.4.27" } +fastant = { version = "0.1.11" } +futures = { version = "0.3.32" } +futures-core = { version = "0.3.32" } +futures-sink = { version = "0.3.32" } +log = { version = "0.4.32" } opentelemetry = { version = "0.32.0", default-features = false, features = [ "trace", ] } @@ -36,22 +30,25 @@ opentelemetry-otlp = { version = "0.32.0", default-features = false, features = "trace", "grpc-tonic", ] } -opentelemetry_sdk = { version = "0.32.0", default-features = false, features = [ +opentelemetry_sdk = { version = "0.32.1", default-features = false, features = [ "trace", ] } -serde = { version = "1.0", features = ["derive"] } - -# test dependencies -tokio = { version = "1.45.0", features = ["full"] } - -[profile.bench] -lto = true -opt-level = 3 - -[patch.crates-io] -# Patch fastrace in crates.io because we import logforth in the examples, which -# itself depends on fastrace from crates.io. If we don't do this, example break -# because logforth brings in a different version of fastrace and the appender -# stops working. -fastrace = { path = "fastrace" } -fastrace-macro = { path = "fastrace-macro" } +parking_lot = { version = "0.12.5" } +pin-project = { version = "1.1.13" } +rand = { version = "0.10.1" } +rtrb = { version = "0.3.4" } +serde = { version = "1.0.228", features = ["derive"] } + +# test-only dependencies +async-stream = { version = "0.3.6" } +# The `fastrace::trace` procedural macro only supports async-trait>=0.1.52 +async-trait = { version = "0.1.52" } +crossbeam = { version = "0.8.4" } +futures-timer = { version = "3.0.4" } +insta = { version = "1.48.0" } +logcall = { version = "0.2.0" } +mockall = { version = "0.14.0" } +pollster = { version = "0.4.0" } +serial_test = { version = "3.5.0" } +tokio = { version = "1.52.3", features = ["full"] } +trybuild = { version = "1.0.116" } diff --git a/README.md b/README.md index a98cb37a..fb11d7da 100644 --- a/README.md +++ b/README.md @@ -4,12 +4,12 @@ [![Documentation](https://img.shields.io/docsrs/fastrace?style=flat-square&logo=rust)](https://docs.rs/fastrace/) [![MSRV 1.91.0](https://img.shields.io/badge/MSRV-1.91.0-green?style=flat-square&logo=rust)](https://www.whatrustisit.com) [![CI Status](https://img.shields.io/github/actions/workflow/status/fast/fastrace/ci.yml?style=flat-square&logo=github)](https://github.com/fast/fastrace/actions) -[![License](https://img.shields.io/crates/l/fastrace?style=flat-square)](https://github.com/fast/fastrace/blob/main/LICENSE) +[![License](https://img.shields.io/crates/l/fastrace?style=flat-square)](https://www.apache.org/licenses/LICENSE-2.0.txt) [![libs.tech recommends](https://libs.tech/project/829370199/badge.svg)](https://libs.tech/project/829370199/fastrace) Fastrace is a tracing library [100x faster](#benchmarks) than others: -![benchmark](https://raw.githubusercontent.com/fast/fastrace/refs/heads/main/etc/img/head-benchmark.svg) +![benchmark](https://raw.githubusercontent.com/fast/fastrace/refs/heads/main/benches/media/head-benchmark.svg) Features: @@ -176,7 +176,7 @@ In this context, Fastrace offers a more efficient solution by filtering out enti **By different architectures:** -![Benchmark result by architecture](https://raw.githubusercontent.com/fast/fastrace/refs/heads/main/etc/img/benchmark-arch.svg) +![Benchmark result by architecture](https://raw.githubusercontent.com/fast/fastrace/refs/heads/main/benches/media/benchmark-arch.svg) | | x86-64 (Intel Broadwell) | x86-64 (Intel Skylake) | x86-64 (AMD Zen) | ARM (AWS Graviton2) | |---------------------|--------------------------|------------------------|------------------|---------------------| @@ -186,7 +186,7 @@ In this context, Fastrace offers a more efficient solution by filtering out enti **By creating a different number of spans:** -![Benchmark result by number of spans](https://raw.githubusercontent.com/fast/fastrace/refs/heads/main/etc/img/benchmark-spans.svg) +![Benchmark result by number of spans](https://raw.githubusercontent.com/fast/fastrace/refs/heads/main/benches/media/benchmark-spans.svg) | | 1 span | 10 spans | 100 spans | 1000 spans | |---------------------|------------|------------|-------------|-------------| @@ -194,7 +194,7 @@ In this context, Fastrace offers a more efficient solution by filtering out enti | 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](https://github.com/fast/fastrace/tree/main/etc/benchmark-result). +Detailed results are available in [benches/results](https://github.com/fast/fastrace/tree/main/benches/results). ## License diff --git a/benches/.gitignore b/benches/.gitignore new file mode 100644 index 00000000..1b72444a --- /dev/null +++ b/benches/.gitignore @@ -0,0 +1,2 @@ +/Cargo.lock +/target diff --git a/benches/Cargo.toml b/benches/Cargo.toml new file mode 100644 index 00000000..05d7318f --- /dev/null +++ b/benches/Cargo.toml @@ -0,0 +1,53 @@ +[package] +name = "benches" +version = "0.0.0" + +edition = "2024" +publish = false + +[dev-dependencies] +crossbeam = { version = "0.8.4" } +divan = { version = "0.1.21" } +fastrace = { path = "../crates/fastrace", features = ["enable"] } +fastrace-opentelemetry = { path = "../crates/fastrace-opentelemetry" } +flume = { version = "0.12.0" } +opentelemetry = { version = "0.32.0", default-features = false, features = [ + "trace", +] } +opentelemetry-otlp = { version = "0.32.0", default-features = false, features = [ + "trace", + "grpc-tonic", +] } +opentelemetry_sdk = { version = "0.32.1", default-features = false, features = [ + "trace", +] } +pollster = { version = "0.4.0" } +rtrb = { version = "0.3.4" } +tokio = { version = "1.52.3", features = ["full"] } +tracing = { version = "0.1.44" } +tracing-opentelemetry = { version = "0.33.0" } +tracing-subscriber = { version = "0.3.23" } + +[profile.bench] +lto = true +opt-level = 3 + +[[bench]] +harness = false +name = "trace" + +[[bench]] +harness = false +name = "compare" + +[[bench]] +harness = false +name = "spsc" + +[[bench]] +harness = false +name = "id" + +[[bench]] +harness = false +name = "vec" diff --git a/fastrace/benches/compare.rs b/benches/benches/compare.rs similarity index 100% rename from fastrace/benches/compare.rs rename to benches/benches/compare.rs diff --git a/fastrace/benches/id.rs b/benches/benches/id.rs similarity index 100% rename from fastrace/benches/id.rs rename to benches/benches/id.rs diff --git a/fastrace/benches/spsc.rs b/benches/benches/spsc.rs similarity index 100% rename from fastrace/benches/spsc.rs rename to benches/benches/spsc.rs diff --git a/fastrace/benches/trace.rs b/benches/benches/trace.rs similarity index 100% rename from fastrace/benches/trace.rs rename to benches/benches/trace.rs diff --git a/fastrace/benches/vec.rs b/benches/benches/vec.rs similarity index 100% rename from fastrace/benches/vec.rs rename to benches/benches/vec.rs diff --git a/etc/img/benchmark-arch.svg b/benches/media/benchmark-arch.svg similarity index 100% rename from etc/img/benchmark-arch.svg rename to benches/media/benchmark-arch.svg diff --git a/etc/img/benchmark-spans.svg b/benches/media/benchmark-spans.svg similarity index 100% rename from etc/img/benchmark-spans.svg rename to benches/media/benchmark-spans.svg diff --git a/etc/img/head-benchmark.svg b/benches/media/head-benchmark.svg similarity index 100% rename from etc/img/head-benchmark.svg rename to benches/media/head-benchmark.svg diff --git a/etc/img/jaeger-asynchronous.png b/benches/media/jaeger-asynchronous.png similarity index 100% rename from etc/img/jaeger-asynchronous.png rename to benches/media/jaeger-asynchronous.png diff --git a/etc/img/jaeger-synchronous.png b/benches/media/jaeger-synchronous.png similarity index 100% rename from etc/img/jaeger-synchronous.png rename to benches/media/jaeger-synchronous.png diff --git a/etc/benchmark-result/README.md b/benches/results/README.md similarity index 100% rename from etc/benchmark-result/README.md rename to benches/results/README.md diff --git a/etc/benchmark-result/compare-m4.2xlarge.txt b/benches/results/compare-m4.2xlarge.txt similarity index 100% rename from etc/benchmark-result/compare-m4.2xlarge.txt rename to benches/results/compare-m4.2xlarge.txt diff --git a/etc/benchmark-result/compare-m5.2xlarge.txt b/benches/results/compare-m5.2xlarge.txt similarity index 100% rename from etc/benchmark-result/compare-m5.2xlarge.txt rename to benches/results/compare-m5.2xlarge.txt diff --git a/etc/benchmark-result/compare-m5a.2xlarge.txt b/benches/results/compare-m5a.2xlarge.txt similarity index 100% rename from etc/benchmark-result/compare-m5a.2xlarge.txt rename to benches/results/compare-m5a.2xlarge.txt diff --git a/etc/benchmark-result/compare-m6g.2xlarge.txt b/benches/results/compare-m6g.2xlarge.txt similarity index 100% rename from etc/benchmark-result/compare-m6g.2xlarge.txt rename to benches/results/compare-m6g.2xlarge.txt diff --git a/fastrace-futures/Cargo.toml b/crates/fastrace-futures/Cargo.toml similarity index 75% rename from fastrace-futures/Cargo.toml rename to crates/fastrace-futures/Cargo.toml index b04d3e67..8bbf3707 100644 --- a/fastrace-futures/Cargo.toml +++ b/crates/fastrace-futures/Cargo.toml @@ -15,12 +15,12 @@ rust-version.workspace = true [dependencies] fastrace = { workspace = true } -futures-core = { version = "0.3.31" } -futures-sink = { version = "0.3.31" } -pin-project = { version = "1.1.8" } +futures-core = { workspace = true } +futures-sink = { workspace = true } +pin-project = { workspace = true } [dev-dependencies] +async-stream = { workspace = true } fastrace = { workspace = true, features = ["enable"] } -async-stream = { version = "0.3" } -futures = { version = "0.3" } +futures = { workspace = true } tokio = { workspace = true } diff --git a/fastrace-futures/README.md b/crates/fastrace-futures/README.md similarity index 86% rename from fastrace-futures/README.md rename to crates/fastrace-futures/README.md index e73dd355..f08de896 100644 --- a/fastrace-futures/README.md +++ b/crates/fastrace-futures/README.md @@ -2,6 +2,6 @@ [![Documentation](https://docs.rs/fastrace-futures/badge.svg)](https://docs.rs/fastrace-futures/) [![Crates.io](https://img.shields.io/crates/v/fastrace-futures.svg)](https://crates.io/crates/fastrace-futures) -[![LICENSE](https://img.shields.io/github/license/fast/fastrace.svg)](https://github.com/fast/fastrace/blob/main/LICENSE) +[![LICENSE](https://img.shields.io/github/license/fast/fastrace.svg)](https://www.apache.org/licenses/LICENSE-2.0.txt) Utilities for tracing `Stream` with [`fastrace`](https://crates.io/crates/fastrace). diff --git a/fastrace-futures/src/lib.rs b/crates/fastrace-futures/src/lib.rs similarity index 99% rename from fastrace-futures/src/lib.rs rename to crates/fastrace-futures/src/lib.rs index f96b44e8..0ddfaf6e 100644 --- a/fastrace-futures/src/lib.rs +++ b/crates/fastrace-futures/src/lib.rs @@ -167,7 +167,8 @@ pub struct InSpan { } impl Stream for InSpan -where T: Stream +where + T: Stream, { type Item = T::Item; @@ -190,7 +191,8 @@ where T: Stream } impl Sink for InSpan -where T: Sink +where + T: Sink, { type Error = T::Error; @@ -238,7 +240,8 @@ pub struct EnterOnPollStream { } impl Stream for EnterOnPollStream -where T: Stream +where + T: Stream, { type Item = T::Item; diff --git a/fastrace-macro/Cargo.toml b/crates/fastrace-macro/Cargo.toml similarity index 83% rename from fastrace-macro/Cargo.toml rename to crates/fastrace-macro/Cargo.toml index f7c50c76..290a719c 100644 --- a/fastrace-macro/Cargo.toml +++ b/crates/fastrace-macro/Cargo.toml @@ -20,9 +20,9 @@ proc-macro = true enable = [] [dependencies] -proc-macro2 = "1.0" -quote = "1.0" -syn = { version = "2.0", features = [ +proc-macro2 = { version = "1.0.106" } +quote = { version = "1.0.45" } +syn = { version = "2.0.118", features = [ "full", "parsing", "extra-traits", diff --git a/fastrace-macro/README.md b/crates/fastrace-macro/README.md similarity index 100% rename from fastrace-macro/README.md rename to crates/fastrace-macro/README.md diff --git a/fastrace-macro/src/args.rs b/crates/fastrace-macro/src/args.rs similarity index 100% rename from fastrace-macro/src/args.rs rename to crates/fastrace-macro/src/args.rs diff --git a/fastrace-macro/src/impls.rs b/crates/fastrace-macro/src/impls.rs similarity index 100% rename from fastrace-macro/src/impls.rs rename to crates/fastrace-macro/src/impls.rs diff --git a/fastrace-macro/src/lib.rs b/crates/fastrace-macro/src/lib.rs similarity index 100% rename from fastrace-macro/src/lib.rs rename to crates/fastrace-macro/src/lib.rs diff --git a/fastrace-opentelemetry/CHANGELOG.md b/crates/fastrace-opentelemetry/CHANGELOG.md similarity index 100% rename from fastrace-opentelemetry/CHANGELOG.md rename to crates/fastrace-opentelemetry/CHANGELOG.md diff --git a/fastrace-opentelemetry/Cargo.toml b/crates/fastrace-opentelemetry/Cargo.toml similarity index 95% rename from fastrace-opentelemetry/Cargo.toml rename to crates/fastrace-opentelemetry/Cargo.toml index 79cb3398..302c03fc 100644 --- a/fastrace-opentelemetry/Cargo.toml +++ b/crates/fastrace-opentelemetry/Cargo.toml @@ -18,7 +18,7 @@ fastrace = { workspace = true } log = { workspace = true } opentelemetry = { workspace = true } opentelemetry_sdk = { workspace = true } -pollster = { version = "0.4.0" } +pollster = { workspace = true } [dev-dependencies] fastrace = { workspace = true, features = ["enable"] } diff --git a/fastrace-opentelemetry/README.md b/crates/fastrace-opentelemetry/README.md similarity index 100% rename from fastrace-opentelemetry/README.md rename to crates/fastrace-opentelemetry/README.md diff --git a/fastrace-opentelemetry/dev/docker-compose.yaml b/crates/fastrace-opentelemetry/dev/docker-compose.yaml similarity index 100% rename from fastrace-opentelemetry/dev/docker-compose.yaml rename to crates/fastrace-opentelemetry/dev/docker-compose.yaml diff --git a/fastrace-opentelemetry/dev/otel-collector-config.yaml b/crates/fastrace-opentelemetry/dev/otel-collector-config.yaml similarity index 100% rename from fastrace-opentelemetry/dev/otel-collector-config.yaml rename to crates/fastrace-opentelemetry/dev/otel-collector-config.yaml diff --git a/fastrace-opentelemetry/src/lib.rs b/crates/fastrace-opentelemetry/src/lib.rs similarity index 98% rename from fastrace-opentelemetry/src/lib.rs rename to crates/fastrace-opentelemetry/src/lib.rs index b76ffd55..5c566ebf 100644 --- a/fastrace-opentelemetry/src/lib.rs +++ b/crates/fastrace-opentelemetry/src/lib.rs @@ -237,9 +237,11 @@ impl OpenTelemetryReporter { /// .with_block_on(move |future| handle.block_on(future)); /// ``` pub fn with_block_on(mut self, block_on: F) -> Self - where F: for<'a> FnMut(Pin + Send + 'a>>) -> OTelSdkResult + where + F: for<'a> FnMut(Pin + Send + 'a>>) -> OTelSdkResult + Send - + 'static { + + 'static, + { self.block_on = Box::new(block_on); self } diff --git a/fastrace-opentelemetry/tests/context.rs b/crates/fastrace-opentelemetry/tests/context.rs similarity index 100% rename from fastrace-opentelemetry/tests/context.rs rename to crates/fastrace-opentelemetry/tests/context.rs diff --git a/crates/fastrace/Cargo.toml b/crates/fastrace/Cargo.toml new file mode 100644 index 00000000..2fcedf54 --- /dev/null +++ b/crates/fastrace/Cargo.toml @@ -0,0 +1,34 @@ +[package] +name = "fastrace" +version = "0.7.18" + +categories = ["development-tools::debugging"] +description = "A high-performance timeline tracing library for Rust" +documentation = "https://docs.rs/fastrace" +keywords = ["tracing", "span", "opentelemetry"] + +edition.workspace = true +license.workspace = true +readme.workspace = true +repository.workspace = true +rust-version.workspace = true + +[features] +enable = ["fastrace-macro/enable"] + +[dependencies] +fastant = { workspace = true } +fastrace-macro = { workspace = true } +parking_lot = { workspace = true } +pin-project = { workspace = true } +rand = { workspace = true } +rtrb = { workspace = true } +serde = { workspace = true } + +[dev-dependencies] +crossbeam = { workspace = true } +fastrace = { workspace = true, features = ["enable"] } +futures-timer = { workspace = true } +mockall = { workspace = true } +pollster = { workspace = true } +tokio = { workspace = true } diff --git a/fastrace/src/collector/command.rs b/crates/fastrace/src/collector/command.rs similarity index 100% rename from fastrace/src/collector/command.rs rename to crates/fastrace/src/collector/command.rs diff --git a/fastrace/src/collector/console_reporter.rs b/crates/fastrace/src/collector/console_reporter.rs similarity index 100% rename from fastrace/src/collector/console_reporter.rs rename to crates/fastrace/src/collector/console_reporter.rs diff --git a/fastrace/src/collector/global_collector.rs b/crates/fastrace/src/collector/global_collector.rs similarity index 100% rename from fastrace/src/collector/global_collector.rs rename to crates/fastrace/src/collector/global_collector.rs diff --git a/fastrace/src/collector/id.rs b/crates/fastrace/src/collector/id.rs similarity index 100% rename from fastrace/src/collector/id.rs rename to crates/fastrace/src/collector/id.rs diff --git a/fastrace/src/collector/mod.rs b/crates/fastrace/src/collector/mod.rs similarity index 100% rename from fastrace/src/collector/mod.rs rename to crates/fastrace/src/collector/mod.rs diff --git a/fastrace/src/collector/test_reporter.rs b/crates/fastrace/src/collector/test_reporter.rs similarity index 100% rename from fastrace/src/collector/test_reporter.rs rename to crates/fastrace/src/collector/test_reporter.rs diff --git a/fastrace/src/event.rs b/crates/fastrace/src/event.rs similarity index 100% rename from fastrace/src/event.rs rename to crates/fastrace/src/event.rs diff --git a/fastrace/src/future.rs b/crates/fastrace/src/future.rs similarity index 100% rename from fastrace/src/future.rs rename to crates/fastrace/src/future.rs diff --git a/fastrace/src/lib.rs b/crates/fastrace/src/lib.rs similarity index 99% rename from fastrace/src/lib.rs rename to crates/fastrace/src/lib.rs index 6a774a2b..0441677f 100644 --- a/fastrace/src/lib.rs +++ b/crates/fastrace/src/lib.rs @@ -260,7 +260,6 @@ //! use fastrace::collector::Config; //! use fastrace::collector::ConsoleReporter; //! use fastrace::prelude::*; -//! use pollster::block_on; //! //! #[trace] //! fn do_something(i: u64) { @@ -280,7 +279,7 @@ //! //! do_something(100); //! -//! block_on( +//! pollster::block_on( //! async { //! do_something_async(100).await; //! } diff --git a/fastrace/src/local/local_collector.rs b/crates/fastrace/src/local/local_collector.rs similarity index 100% rename from fastrace/src/local/local_collector.rs rename to crates/fastrace/src/local/local_collector.rs diff --git a/fastrace/src/local/local_span.rs b/crates/fastrace/src/local/local_span.rs similarity index 100% rename from fastrace/src/local/local_span.rs rename to crates/fastrace/src/local/local_span.rs diff --git a/fastrace/src/local/local_span_line.rs b/crates/fastrace/src/local/local_span_line.rs similarity index 96% rename from fastrace/src/local/local_span_line.rs rename to crates/fastrace/src/local/local_span_line.rs index c285b4db..74fba545 100644 --- a/fastrace/src/local/local_span_line.rs +++ b/crates/fastrace/src/local/local_span_line.rs @@ -198,13 +198,16 @@ span1 [] let span = span_line.start_span("span").unwrap(); let current_token = span_line.current_collect_token().unwrap(); - assert_eq!(current_token, CollectToken { - trace_id: TraceId(1234), - parent_id: span_line.span_queue.current_parent_id().unwrap(), - collect_id: 42, - is_root: false, - is_sampled: true, - }); + assert_eq!( + current_token, + CollectToken { + trace_id: TraceId(1234), + parent_id: span_line.span_queue.current_parent_id().unwrap(), + collect_id: 42, + is_root: false, + is_sampled: true, + } + ); span_line.finish_span(span); let current_token = span_line.current_collect_token().unwrap(); diff --git a/fastrace/src/local/local_span_stack.rs b/crates/fastrace/src/local/local_span_stack.rs similarity index 100% rename from fastrace/src/local/local_span_stack.rs rename to crates/fastrace/src/local/local_span_stack.rs diff --git a/fastrace/src/local/mod.rs b/crates/fastrace/src/local/mod.rs similarity index 100% rename from fastrace/src/local/mod.rs rename to crates/fastrace/src/local/mod.rs diff --git a/fastrace/src/local/raw_span.rs b/crates/fastrace/src/local/raw_span.rs similarity index 100% rename from fastrace/src/local/raw_span.rs rename to crates/fastrace/src/local/raw_span.rs diff --git a/fastrace/src/local/span_queue.rs b/crates/fastrace/src/local/span_queue.rs similarity index 100% rename from fastrace/src/local/span_queue.rs rename to crates/fastrace/src/local/span_queue.rs diff --git a/fastrace/src/macros.rs b/crates/fastrace/src/macros.rs similarity index 100% rename from fastrace/src/macros.rs rename to crates/fastrace/src/macros.rs diff --git a/fastrace/src/span.rs b/crates/fastrace/src/span.rs similarity index 100% rename from fastrace/src/span.rs rename to crates/fastrace/src/span.rs diff --git a/fastrace/src/util/command_bus.rs b/crates/fastrace/src/util/command_bus.rs similarity index 100% rename from fastrace/src/util/command_bus.rs rename to crates/fastrace/src/util/command_bus.rs diff --git a/fastrace/src/util/mod.rs b/crates/fastrace/src/util/mod.rs similarity index 100% rename from fastrace/src/util/mod.rs rename to crates/fastrace/src/util/mod.rs diff --git a/fastrace/src/util/spsc.rs b/crates/fastrace/src/util/spsc.rs similarity index 100% rename from fastrace/src/util/spsc.rs rename to crates/fastrace/src/util/spsc.rs diff --git a/fastrace/src/util/tree.rs b/crates/fastrace/src/util/tree.rs similarity index 100% rename from fastrace/src/util/tree.rs rename to crates/fastrace/src/util/tree.rs diff --git a/examples/.gitignore b/examples/.gitignore new file mode 100644 index 00000000..1b72444a --- /dev/null +++ b/examples/.gitignore @@ -0,0 +1,2 @@ +/Cargo.lock +/target diff --git a/examples/Cargo.toml b/examples/Cargo.toml index c74ce1f7..4185fff8 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -1,53 +1,47 @@ -[package] -name = "example" +[workspace] +members = [ + "console-reporter", + "fastrace-disabled", + "log-integration", + "opentelemetry-reporter", + "sampling", + "test-harness-integration", +] +resolver = "3" + +[workspace.package] +edition = "2024" publish = false version = "0.0.0" -edition.workspace = true -license.workspace = true -repository.workspace = true -rust-version.workspace = true - -[package.metadata.release] -release = false - -[dev-dependencies] -anyhow = { version = "1.0.98" } -fastrace = { workspace = true, features = ["enable"] } -fastrace-opentelemetry = { workspace = true } -log = { workspace = true } +[workspace.dependencies] +anyhow = { version = "1.0.102" } +fastrace = { path = "../crates/fastrace" } +fastrace-opentelemetry = { path = "../crates/fastrace-opentelemetry" } +log = { version = "0.4.32" } logcall = { version = "0.2.0" } logforth = { version = "0.30.1", features = [ - "append-fastrace", - "diagnostic-fastrace", - "starter-log", + "append-fastrace", + "diagnostic-fastrace", + "starter-log", ] } -opentelemetry = { workspace = true } -opentelemetry-otlp = { workspace = true } -opentelemetry_sdk = { workspace = true } -test-harness = { version = "0.3.0" } -tokio = { workspace = true } - -[[example]] -name = "asynchronous" -path = "asynchronous.rs" - -[[example]] -name = "basic" -path = "basic.rs" - -[[example]] -name = "harness" -path = "harness.rs" - -[[example]] -name = "logging" -path = "logging.rs" - -[[example]] -name = "synchronous" -path = "synchronous.rs" - -[[example]] -name = "sampling" -path = "sampling.rs" +opentelemetry = { version = "0.32.0", default-features = false, features = [ + "trace", +] } +opentelemetry-otlp = { version = "0.32.0", default-features = false, features = [ + "trace", + "grpc-tonic", +] } +opentelemetry_sdk = { version = "0.32.1", default-features = false, features = [ + "trace", +] } +test-harness = { version = "0.3.1" } +tokio = { version = "1.52.3", features = ["full"] } + +[patch.crates-io] +# Patch fastrace in crates.io because we import logforth in the examples, which +# itself depends on fastrace from crates.io. If we don't do this, examples break +# because logforth brings in a different version of fastrace and the appender +# stops working. +fastrace = { path = "../crates/fastrace" } +fastrace-macro = { path = "../crates/fastrace-macro" } diff --git a/examples/console-reporter/Cargo.toml b/examples/console-reporter/Cargo.toml new file mode 100644 index 00000000..4fcbb4d3 --- /dev/null +++ b/examples/console-reporter/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "console-reporter" + +edition.workspace = true +publish.workspace = true +version.workspace = true + +[dependencies] +fastrace = { workspace = true, features = ["enable"] } + +[[bin]] +name = "console-reporter" +path = "main.rs" diff --git a/examples/basic.rs b/examples/console-reporter/main.rs similarity index 53% rename from examples/basic.rs rename to examples/console-reporter/main.rs index 3371733e..fc95a4bc 100644 --- a/examples/basic.rs +++ b/examples/console-reporter/main.rs @@ -12,21 +12,40 @@ // See the License for the specific language governing permissions and // limitations under the License. +use std::time::Duration; + +use fastrace::Span; use fastrace::collector::Config; use fastrace::collector::ConsoleReporter; -use fastrace::prelude::*; +use fastrace::collector::SpanContext; +use fastrace::local::LocalSpan; + +fn func1(i: u64) { + let _guard = LocalSpan::enter_with_local_parent("func1"); + std::thread::sleep(Duration::from_millis(i)); + func2(i); +} + +#[fastrace::trace] +fn func2(i: u64) { + std::thread::sleep(Duration::from_millis(i)); +} fn main() { fastrace::set_reporter(ConsoleReporter, Config::default()); - do_main(); - fastrace::flush(); -} -fn do_main() { - let parent = SpanContext::random(); - let root = Span::root("root", parent); - let _g = root.set_local_parent(); - let _g = LocalSpan::enter_with_local_parent("child"); + { + let parent = SpanContext::random(); + let root = Span::root("root", parent); + + let _g = root.set_local_parent(); + let _span = LocalSpan::enter_with_local_parent("biz-span") + .with_property(|| ("biz-property", "biz-value")); - // do business + for i in 1..=10 { + func1(i); + } + } + + fastrace::flush(); } diff --git a/examples/fastrace-disabled/Cargo.toml b/examples/fastrace-disabled/Cargo.toml new file mode 100644 index 00000000..c8bb4034 --- /dev/null +++ b/examples/fastrace-disabled/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "fastrace-disabled" + +edition.workspace = true +publish.workspace = true +version.workspace = true + +[dependencies] +fastrace = { workspace = true } # do not turn on the "enable" feature + +[[bin]] +name = "fastrace-disabled" +path = "main.rs" diff --git a/tests/statically-disable/src/main.rs b/examples/fastrace-disabled/main.rs similarity index 93% rename from tests/statically-disable/src/main.rs rename to examples/fastrace-disabled/main.rs index 9457b341..1908b468 100644 --- a/tests/statically-disable/src/main.rs +++ b/examples/fastrace-disabled/main.rs @@ -12,10 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -// This file is derived from [1] under the original license header: -// Copyright 2020 TiKV Project Authors. Licensed under Apache-2.0. -// [1]: https://github.com/tikv/minitrace-rust/blob/v0.6.4/test-statically-disable/src/main.rs - //! The libraries may have tracing instrument embedded in the code for tracing purposes. //! //! However, if the executable does not enable fastrace, it will be statically disabled. diff --git a/examples/log-integration/Cargo.toml b/examples/log-integration/Cargo.toml new file mode 100644 index 00000000..bab3aaba --- /dev/null +++ b/examples/log-integration/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "log-integration" + +edition.workspace = true +publish.workspace = true +version.workspace = true + +[dependencies] +fastrace = { workspace = true, features = ["enable"] } +log = { workspace = true } +logcall = { workspace = true } +logforth = { workspace = true } + +[[bin]] +name = "log-integration" +path = "main.rs" diff --git a/examples/logging.rs b/examples/log-integration/main.rs similarity index 89% rename from examples/logging.rs rename to examples/log-integration/main.rs index bc98d280..771c29db 100644 --- a/examples/logging.rs +++ b/examples/log-integration/main.rs @@ -12,17 +12,17 @@ // See the License for the specific language governing permissions and // limitations under the License. +use fastrace::Span; use fastrace::collector::Config; use fastrace::collector::ConsoleReporter; -use fastrace::prelude::*; -use log::info; +use fastrace::collector::SpanContext; +use fastrace::local::LocalSpan; use logforth::append; use logforth::diagnostic; use logforth::layout; -/// An example of automatically logging function arguments and return values. #[logcall::logcall("debug")] -#[trace] +#[fastrace::trace] fn plus(a: u64, b: u64) -> Result { Ok(a + b) } @@ -51,11 +51,11 @@ fn do_main() { let root = Span::root("root", parent); let _span_guard = root.set_local_parent(); - info!("event in root span"); + log::info!("event in root span"); let _local_span_guard = LocalSpan::enter_with_local_parent("child"); - info!("event in child span"); + log::info!("event in child span"); plus(1, 2).unwrap(); } diff --git a/examples/opentelemetry-reporter/Cargo.toml b/examples/opentelemetry-reporter/Cargo.toml new file mode 100644 index 00000000..68bf1407 --- /dev/null +++ b/examples/opentelemetry-reporter/Cargo.toml @@ -0,0 +1,18 @@ +[package] +name = "opentelemetry-reporter" + +edition.workspace = true +publish.workspace = true +version.workspace = true + +[dependencies] +fastrace = { workspace = true, features = ["enable"] } +fastrace-opentelemetry = { workspace = true } +opentelemetry = { workspace = true } +opentelemetry-otlp = { workspace = true } +opentelemetry_sdk = { workspace = true } +tokio = { workspace = true } + +[[bin]] +name = "opentelemetry-reporter" +path = "main.rs" diff --git a/examples/asynchronous.rs b/examples/opentelemetry-reporter/main.rs similarity index 52% rename from examples/asynchronous.rs rename to examples/opentelemetry-reporter/main.rs index 7b038da3..3192bf4b 100644 --- a/examples/asynchronous.rs +++ b/examples/opentelemetry-reporter/main.rs @@ -12,15 +12,13 @@ // See the License for the specific language governing permissions and // limitations under the License. -// This file is derived from [1] under the original license header: -// Copyright 2020 TiKV Project Authors. Licensed under Apache-2.0. -// [1]: https://github.com/tikv/minitrace-rust/blob/v0.6.4/minitrace/examples/asynchronous.rs - use std::borrow::Cow; +use fastrace::Span; use fastrace::collector::Config; -use fastrace::collector::Reporter; -use fastrace::prelude::*; +use fastrace::collector::SpanContext; +use fastrace::future::FutureExt; +use fastrace::local::LocalSpan; use opentelemetry_otlp::WithExportConfig; fn parallel_job() -> Vec> { @@ -39,7 +37,7 @@ async fn iter_job(iter: u64) { other_job().await; } -#[trace(enter_on_poll = true)] +#[fastrace::trace(enter_on_poll = true)] async fn other_job() { for i in 0..20 { if i == 10 { @@ -51,7 +49,28 @@ async fn other_job() { #[tokio::main] async fn main() { - fastrace::set_reporter(ReportAll::create(), Config::default()); + let reporter = fastrace_opentelemetry::OpenTelemetryReporter::new( + opentelemetry_otlp::SpanExporter::builder() + .with_tonic() + .with_endpoint("http://127.0.0.1:4317".to_string()) + .with_protocol(opentelemetry_otlp::Protocol::Grpc) + .with_timeout(opentelemetry_otlp::OTEL_EXPORTER_OTLP_TIMEOUT_DEFAULT) + .build() + .unwrap(), + Cow::Owned( + opentelemetry_sdk::Resource::builder() + .with_attributes([opentelemetry::KeyValue::new( + "service.name", + "asynchronous(opentelemetry)", + )]) + .build(), + ), + opentelemetry::InstrumentationScope::builder("example-crate") + .with_version(env!("CARGO_PKG_VERSION")) + .build(), + ); + + fastrace::set_reporter(reporter, Config::default()); { let parent = SpanContext::random(); @@ -77,40 +96,3 @@ async fn main() { fastrace::flush(); } - -pub struct ReportAll { - opentelemetry: fastrace_opentelemetry::OpenTelemetryReporter, -} - -impl ReportAll { - pub fn create() -> ReportAll { - ReportAll { - opentelemetry: fastrace_opentelemetry::OpenTelemetryReporter::new( - opentelemetry_otlp::SpanExporter::builder() - .with_tonic() - .with_endpoint("http://127.0.0.1:4317".to_string()) - .with_protocol(opentelemetry_otlp::Protocol::Grpc) - .with_timeout(opentelemetry_otlp::OTEL_EXPORTER_OTLP_TIMEOUT_DEFAULT) - .build() - .expect("initialize oltp exporter"), - Cow::Owned( - opentelemetry_sdk::Resource::builder() - .with_attributes([opentelemetry::KeyValue::new( - "service.name", - "asynchronous(opentelemetry)", - )]) - .build(), - ), - opentelemetry::InstrumentationScope::builder("example-crate") - .with_version(env!("CARGO_PKG_VERSION")) - .build(), - ), - } - } -} - -impl Reporter for ReportAll { - fn report(&mut self, spans: Vec) { - self.opentelemetry.report(spans); - } -} diff --git a/examples/sampling/Cargo.toml b/examples/sampling/Cargo.toml new file mode 100644 index 00000000..628c99c6 --- /dev/null +++ b/examples/sampling/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "sampling" + +edition.workspace = true +publish.workspace = true +version.workspace = true + +[dependencies] +fastrace = { workspace = true, features = ["enable"] } + +[[bin]] +name = "sampling" +path = "main.rs" diff --git a/examples/sampling.rs b/examples/sampling/main.rs similarity index 95% rename from examples/sampling.rs rename to examples/sampling/main.rs index 230c1f70..c30d984c 100644 --- a/examples/sampling.rs +++ b/examples/sampling/main.rs @@ -14,9 +14,10 @@ use std::time::Duration; +use fastrace::Span; use fastrace::collector::Config; use fastrace::collector::ConsoleReporter; -use fastrace::prelude::*; +use fastrace::collector::SpanContext; fn main() { fastrace::set_reporter(ConsoleReporter, Config::default()); @@ -53,7 +54,7 @@ fn heavy_task() { } } -#[trace] +#[fastrace::trace] fn expensive_task(time: Duration) { std::thread::sleep(time); } diff --git a/examples/synchronous.rs b/examples/synchronous.rs deleted file mode 100644 index b0a4f49a..00000000 --- a/examples/synchronous.rs +++ /dev/null @@ -1,93 +0,0 @@ -// Copyright 2024 FastLabs Developers -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// This file is derived from [1] under the original license header: -// Copyright 2020 TiKV Project Authors. Licensed under Apache-2.0. -// [1]: https://github.com/tikv/minitrace-rust/blob/v0.6.4/minitrace/examples/synchronous.rs - -use std::borrow::Cow; -use std::time::Duration; - -use fastrace::collector::Config; -use fastrace::collector::Reporter; -use fastrace::prelude::*; -use opentelemetry_otlp::WithExportConfig; - -fn func1(i: u64) { - let _guard = LocalSpan::enter_with_local_parent("func1"); - std::thread::sleep(Duration::from_millis(i)); - func2(i); -} - -#[trace] -fn func2(i: u64) { - std::thread::sleep(Duration::from_millis(i)); -} - -#[tokio::main] -async fn main() { - fastrace::set_reporter(ReportAll::create(), Config::default()); - - { - let parent = SpanContext::random(); - let root = Span::root("root", parent); - - let _g = root.set_local_parent(); - let _span = LocalSpan::enter_with_local_parent("a span") - .with_property(|| ("a property", "a value")); - - for i in 1..=10 { - func1(i); - } - } - - fastrace::flush(); -} - -pub struct ReportAll { - opentelemetry: fastrace_opentelemetry::OpenTelemetryReporter, -} - -impl ReportAll { - pub fn create() -> ReportAll { - ReportAll { - opentelemetry: fastrace_opentelemetry::OpenTelemetryReporter::new( - opentelemetry_otlp::SpanExporter::builder() - .with_tonic() - .with_endpoint("http://127.0.0.1:4317".to_string()) - .with_protocol(opentelemetry_otlp::Protocol::Grpc) - .with_timeout(opentelemetry_otlp::OTEL_EXPORTER_OTLP_TIMEOUT_DEFAULT) - .build() - .expect("initialize oltp exporter"), - Cow::Owned( - opentelemetry_sdk::Resource::builder() - .with_attributes([opentelemetry::KeyValue::new( - "service.name", - "synchronous(opentelemetry)", - )]) - .build(), - ), - opentelemetry::InstrumentationScope::builder("example-crate") - .with_version(env!("CARGO_PKG_VERSION")) - .build(), - ), - } - } -} - -impl Reporter for ReportAll { - fn report(&mut self, spans: Vec) { - self.opentelemetry.report(spans); - } -} diff --git a/examples/test-harness-integration/Cargo.toml b/examples/test-harness-integration/Cargo.toml new file mode 100644 index 00000000..ba935e46 --- /dev/null +++ b/examples/test-harness-integration/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "test-harness-integration" + +edition.workspace = true +publish.workspace = true +version.workspace = true + +[dependencies] +anyhow = { workspace = true } +fastrace = { workspace = true, features = ["enable"] } +test-harness = { workspace = true } +tokio = { workspace = true } + +[[bin]] +name = "test-harness-integration" +path = "main.rs" diff --git a/examples/harness.rs b/examples/test-harness-integration/main.rs similarity index 90% rename from examples/harness.rs rename to examples/test-harness-integration/main.rs index 7d4829ae..a65244e7 100644 --- a/examples/harness.rs +++ b/examples/test-harness-integration/main.rs @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -//! This example shows how to write a test harness to set up fastrace. +fn main() {} #[test_harness::test(harness = test_util::setup_fastrace)] #[fastrace::trace] @@ -30,12 +30,16 @@ async fn test_async() -> anyhow::Result<()> { #[cfg(test)] mod test_util { + use fastrace::Span; use fastrace::collector::Config; use fastrace::collector::ConsoleReporter; - use fastrace::prelude::*; + use fastrace::collector::SpanContext; + use fastrace::future::FutureExt; pub fn setup_fastrace(test: F) - where F: FnOnce() -> anyhow::Result<()> + 'static { + where + F: FnOnce() -> anyhow::Result<()> + 'static, + { fastrace::set_reporter(ConsoleReporter, Config::default()); { let root = Span::root(closure_name::(), SpanContext::random()); @@ -48,7 +52,7 @@ mod test_util { pub fn setup_fastrace_async(test: F) where F: FnOnce() -> Fut + 'static, - Fut: std::future::Future> + Send + 'static, + Fut: Future> + Send + 'static, { fastrace::set_reporter(ConsoleReporter, Config::default()); let rt = tokio::runtime::Builder::new_multi_thread() @@ -69,5 +73,3 @@ mod test_util { .unwrap() } } - -fn main() {} diff --git a/fastrace-futures/LICENSE b/fastrace-futures/LICENSE deleted file mode 120000 index ea5b6064..00000000 --- a/fastrace-futures/LICENSE +++ /dev/null @@ -1 +0,0 @@ -../LICENSE \ No newline at end of file diff --git a/fastrace-macro/LICENSE b/fastrace-macro/LICENSE deleted file mode 120000 index ea5b6064..00000000 --- a/fastrace-macro/LICENSE +++ /dev/null @@ -1 +0,0 @@ -../LICENSE \ No newline at end of file diff --git a/fastrace-opentelemetry/LICENSE b/fastrace-opentelemetry/LICENSE deleted file mode 120000 index ea5b6064..00000000 --- a/fastrace-opentelemetry/LICENSE +++ /dev/null @@ -1 +0,0 @@ -../LICENSE \ No newline at end of file diff --git a/fastrace/Cargo.toml b/fastrace/Cargo.toml deleted file mode 100644 index 6267b827..00000000 --- a/fastrace/Cargo.toml +++ /dev/null @@ -1,67 +0,0 @@ -[package] -name = "fastrace" -version = "0.7.18" - -categories = ["development-tools::debugging"] -description = "A high-performance timeline tracing library for Rust" -documentation = "https://docs.rs/fastrace" -keywords = ["tracing", "span", "opentelemetry"] -readme = "../README.md" - -edition.workspace = true -license.workspace = true -repository.workspace = true -rust-version.workspace = true - -[features] -enable = ["fastrace-macro/enable"] - -[dependencies] -fastant = "0.1" -fastrace-macro = { workspace = true } -parking_lot = "0.12" -pin-project = { version = "1.1.8" } -rand = "0.10.0" -rtrb = "0.3" -serde = { workspace = true } - -[dev-dependencies] -async-trait = "0.1" -crossbeam = "0.8" -divan = "0.1" -fastrace = { path = ".", features = ["enable"] } -fastrace-opentelemetry = { workspace = true } -flume = "0.12.0" -futures-timer = "3" -insta = "1.43.1" -mockall = "0.14.0" -opentelemetry = { workspace = true } -opentelemetry-otlp = { workspace = true } -opentelemetry_sdk = { workspace = true } -pollster = { version = "0.4.0" } -rand = "0.10.0" -serial_test = "3.1" -tokio = { workspace = true } -tracing = { version = "0.1" } -tracing-opentelemetry = { version = "0.33.0" } -tracing-subscriber = { version = "0.3.19" } - -[[bench]] -harness = false -name = "trace" - -[[bench]] -harness = false -name = "compare" - -[[bench]] -harness = false -name = "spsc" - -[[bench]] -harness = false -name = "id" - -[[bench]] -harness = false -name = "vec" diff --git a/fastrace/LICENSE b/fastrace/LICENSE deleted file mode 120000 index ea5b6064..00000000 --- a/fastrace/LICENSE +++ /dev/null @@ -1 +0,0 @@ -../LICENSE \ No newline at end of file diff --git a/rustfmt.toml b/rustfmt.toml index f23dccec..a1a83fd0 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -1,12 +1,5 @@ comment_width = 120 -edition = "2021" format_code_in_doc_comments = true group_imports = "StdExternalCrate" imports_granularity = "Item" -normalize_comments = true -overflow_delimited_expr = true -reorder_imports = true -style_edition = "2024" -trailing_comma = "Vertical" -where_single_line = true wrap_comments = true diff --git a/taplo.toml b/taplo.toml index 583da20d..c9286933 100644 --- a/taplo.toml +++ b/taplo.toml @@ -1,3 +1,4 @@ +exclude = ["target/**"] include = ["Cargo.toml", "**/*.toml"] [formatting] diff --git a/tests-build/Cargo.toml b/tests-build/Cargo.toml new file mode 100644 index 00000000..892ade2c --- /dev/null +++ b/tests-build/Cargo.toml @@ -0,0 +1,20 @@ +[package] +name = "tests-build" +publish = false +version = "0.0.0" + +edition.workspace = true +rust-version.workspace = true + +[package.metadata.release] +release = false + +[dev-dependencies] +async-stream = { workspace = true } +async-trait = { workspace = true } +fastrace = { workspace = true, features = ["enable"] } +futures = { workspace = true } +log = { workspace = true } +logcall = { workspace = true } +tokio = { workspace = true } +trybuild = { workspace = true } diff --git a/tests/macros/tests/ui.rs b/tests-build/tests/ui.rs similarity index 100% rename from tests/macros/tests/ui.rs rename to tests-build/tests/ui.rs diff --git a/tests/macros/tests/ui/err/has-duplicated-arguments.rs b/tests-build/tests/ui/err/has-duplicated-arguments.rs similarity index 100% rename from tests/macros/tests/ui/err/has-duplicated-arguments.rs rename to tests-build/tests/ui/err/has-duplicated-arguments.rs diff --git a/tests/macros/tests/ui/err/has-duplicated-arguments.stderr b/tests-build/tests/ui/err/has-duplicated-arguments.stderr similarity index 100% rename from tests/macros/tests/ui/err/has-duplicated-arguments.stderr rename to tests-build/tests/ui/err/has-duplicated-arguments.stderr diff --git a/tests/macros/tests/ui/err/has-duplicated-properties.rs b/tests-build/tests/ui/err/has-duplicated-properties.rs similarity index 100% rename from tests/macros/tests/ui/err/has-duplicated-properties.rs rename to tests-build/tests/ui/err/has-duplicated-properties.rs diff --git a/tests/macros/tests/ui/err/has-duplicated-properties.stderr b/tests-build/tests/ui/err/has-duplicated-properties.stderr similarity index 100% rename from tests/macros/tests/ui/err/has-duplicated-properties.stderr rename to tests-build/tests/ui/err/has-duplicated-properties.stderr diff --git a/tests/macros/tests/ui/err/has-empty-name.rs b/tests-build/tests/ui/err/has-empty-name.rs similarity index 100% rename from tests/macros/tests/ui/err/has-empty-name.rs rename to tests-build/tests/ui/err/has-empty-name.rs diff --git a/tests/macros/tests/ui/err/has-empty-name.stderr b/tests-build/tests/ui/err/has-empty-name.stderr similarity index 100% rename from tests/macros/tests/ui/err/has-empty-name.stderr rename to tests-build/tests/ui/err/has-empty-name.stderr diff --git a/tests/macros/tests/ui/err/has-enter-on-poll-and-sync.rs b/tests-build/tests/ui/err/has-enter-on-poll-and-sync.rs similarity index 100% rename from tests/macros/tests/ui/err/has-enter-on-poll-and-sync.rs rename to tests-build/tests/ui/err/has-enter-on-poll-and-sync.rs diff --git a/tests/macros/tests/ui/err/has-enter-on-poll-and-sync.stderr b/tests-build/tests/ui/err/has-enter-on-poll-and-sync.stderr similarity index 100% rename from tests/macros/tests/ui/err/has-enter-on-poll-and-sync.stderr rename to tests-build/tests/ui/err/has-enter-on-poll-and-sync.stderr diff --git a/tests/macros/tests/ui/err/has-expr-argument.rs b/tests-build/tests/ui/err/has-expr-argument.rs similarity index 100% rename from tests/macros/tests/ui/err/has-expr-argument.rs rename to tests-build/tests/ui/err/has-expr-argument.rs diff --git a/tests/macros/tests/ui/err/has-expr-argument.stderr b/tests-build/tests/ui/err/has-expr-argument.stderr similarity index 100% rename from tests/macros/tests/ui/err/has-expr-argument.stderr rename to tests-build/tests/ui/err/has-expr-argument.stderr diff --git a/tests/macros/tests/ui/err/has-ident-arguments.rs b/tests-build/tests/ui/err/has-ident-arguments.rs similarity index 100% rename from tests/macros/tests/ui/err/has-ident-arguments.rs rename to tests-build/tests/ui/err/has-ident-arguments.rs diff --git a/tests/macros/tests/ui/err/has-ident-arguments.stderr b/tests-build/tests/ui/err/has-ident-arguments.stderr similarity index 100% rename from tests/macros/tests/ui/err/has-ident-arguments.stderr rename to tests-build/tests/ui/err/has-ident-arguments.stderr diff --git a/tests/macros/tests/ui/err/has-name-and-short-name.rs b/tests-build/tests/ui/err/has-name-and-short-name.rs similarity index 100% rename from tests/macros/tests/ui/err/has-name-and-short-name.rs rename to tests-build/tests/ui/err/has-name-and-short-name.rs diff --git a/tests/macros/tests/ui/err/has-name-and-short-name.stderr b/tests-build/tests/ui/err/has-name-and-short-name.stderr similarity index 100% rename from tests/macros/tests/ui/err/has-name-and-short-name.stderr rename to tests-build/tests/ui/err/has-name-and-short-name.stderr diff --git a/tests/macros/tests/ui/err/has-properties-and-enter-on-poll.rs b/tests-build/tests/ui/err/has-properties-and-enter-on-poll.rs similarity index 100% rename from tests/macros/tests/ui/err/has-properties-and-enter-on-poll.rs rename to tests-build/tests/ui/err/has-properties-and-enter-on-poll.rs diff --git a/tests/macros/tests/ui/err/has-properties-and-enter-on-poll.stderr b/tests-build/tests/ui/err/has-properties-and-enter-on-poll.stderr similarity index 100% rename from tests/macros/tests/ui/err/has-properties-and-enter-on-poll.stderr rename to tests-build/tests/ui/err/has-properties-and-enter-on-poll.stderr diff --git a/tests/macros/tests/ui/err/has-unknown-argument.rs b/tests-build/tests/ui/err/has-unknown-argument.rs similarity index 100% rename from tests/macros/tests/ui/err/has-unknown-argument.rs rename to tests-build/tests/ui/err/has-unknown-argument.rs diff --git a/tests/macros/tests/ui/err/has-unknown-argument.stderr b/tests-build/tests/ui/err/has-unknown-argument.stderr similarity index 100% rename from tests/macros/tests/ui/err/has-unknown-argument.stderr rename to tests-build/tests/ui/err/has-unknown-argument.stderr diff --git a/tests/macros/tests/ui/err/item-is-not-a-function.rs b/tests-build/tests/ui/err/item-is-not-a-function.rs similarity index 100% rename from tests/macros/tests/ui/err/item-is-not-a-function.rs rename to tests-build/tests/ui/err/item-is-not-a-function.rs diff --git a/tests/macros/tests/ui/err/item-is-not-a-function.stderr b/tests-build/tests/ui/err/item-is-not-a-function.stderr similarity index 100% rename from tests/macros/tests/ui/err/item-is-not-a-function.stderr rename to tests-build/tests/ui/err/item-is-not-a-function.stderr diff --git a/tests/macros/tests/ui/err/name-is-not-an-assignment-expression.rs b/tests-build/tests/ui/err/name-is-not-an-assignment-expression.rs similarity index 100% rename from tests/macros/tests/ui/err/name-is-not-an-assignment-expression.rs rename to tests-build/tests/ui/err/name-is-not-an-assignment-expression.rs diff --git a/tests/macros/tests/ui/err/name-is-not-an-assignment-expression.stderr b/tests-build/tests/ui/err/name-is-not-an-assignment-expression.stderr similarity index 100% rename from tests/macros/tests/ui/err/name-is-not-an-assignment-expression.stderr rename to tests-build/tests/ui/err/name-is-not-an-assignment-expression.stderr diff --git a/tests/macros/tests/ui/err/name-is-not-string.rs b/tests-build/tests/ui/err/name-is-not-string.rs similarity index 100% rename from tests/macros/tests/ui/err/name-is-not-string.rs rename to tests-build/tests/ui/err/name-is-not-string.rs diff --git a/tests/macros/tests/ui/err/name-is-not-string.stderr b/tests-build/tests/ui/err/name-is-not-string.stderr similarity index 100% rename from tests/macros/tests/ui/err/name-is-not-string.stderr rename to tests-build/tests/ui/err/name-is-not-string.stderr diff --git a/tests/macros/tests/ui/err/properties-missing-braces.rs b/tests-build/tests/ui/err/properties-missing-braces.rs similarity index 100% rename from tests/macros/tests/ui/err/properties-missing-braces.rs rename to tests-build/tests/ui/err/properties-missing-braces.rs diff --git a/tests/macros/tests/ui/err/properties-missing-braces.stderr b/tests-build/tests/ui/err/properties-missing-braces.stderr similarity index 100% rename from tests/macros/tests/ui/err/properties-missing-braces.stderr rename to tests-build/tests/ui/err/properties-missing-braces.stderr diff --git a/tests/macros/tests/ui/err/properties-non-string.rs b/tests-build/tests/ui/err/properties-non-string.rs similarity index 100% rename from tests/macros/tests/ui/err/properties-non-string.rs rename to tests-build/tests/ui/err/properties-non-string.rs diff --git a/tests/macros/tests/ui/err/properties-non-string.stderr b/tests-build/tests/ui/err/properties-non-string.stderr similarity index 100% rename from tests/macros/tests/ui/err/properties-non-string.stderr rename to tests-build/tests/ui/err/properties-non-string.stderr diff --git a/tests/macros/tests/ui/err/properties-partial-escape.rs b/tests-build/tests/ui/err/properties-partial-escape.rs similarity index 100% rename from tests/macros/tests/ui/err/properties-partial-escape.rs rename to tests-build/tests/ui/err/properties-partial-escape.rs diff --git a/tests/macros/tests/ui/err/properties-partial-escape.stderr b/tests-build/tests/ui/err/properties-partial-escape.stderr similarity index 100% rename from tests/macros/tests/ui/err/properties-partial-escape.stderr rename to tests-build/tests/ui/err/properties-partial-escape.stderr diff --git a/tests/macros/tests/ui/err/properties-value-non-string.rs b/tests-build/tests/ui/err/properties-value-non-string.rs similarity index 100% rename from tests/macros/tests/ui/err/properties-value-non-string.rs rename to tests-build/tests/ui/err/properties-value-non-string.rs diff --git a/tests/macros/tests/ui/err/properties-value-non-string.stderr b/tests-build/tests/ui/err/properties-value-non-string.stderr similarity index 100% rename from tests/macros/tests/ui/err/properties-value-non-string.stderr rename to tests-build/tests/ui/err/properties-value-non-string.stderr diff --git a/tests/macros/tests/ui/err/short-name-is-not-bool.rs b/tests-build/tests/ui/err/short-name-is-not-bool.rs similarity index 100% rename from tests/macros/tests/ui/err/short-name-is-not-bool.rs rename to tests-build/tests/ui/err/short-name-is-not-bool.rs diff --git a/tests/macros/tests/ui/err/short-name-is-not-bool.stderr b/tests-build/tests/ui/err/short-name-is-not-bool.stderr similarity index 100% rename from tests/macros/tests/ui/err/short-name-is-not-bool.stderr rename to tests-build/tests/ui/err/short-name-is-not-bool.stderr diff --git a/tests/macros/tests/ui/err/trace-interleaved.rs b/tests-build/tests/ui/err/trace-interleaved.rs similarity index 100% rename from tests/macros/tests/ui/err/trace-interleaved.rs rename to tests-build/tests/ui/err/trace-interleaved.rs diff --git a/tests/macros/tests/ui/err/trace-interleaved.stderr b/tests-build/tests/ui/err/trace-interleaved.stderr similarity index 100% rename from tests/macros/tests/ui/err/trace-interleaved.stderr rename to tests-build/tests/ui/err/trace-interleaved.stderr diff --git a/tests/macros/tests/ui/ok/async-in-trait.rs b/tests-build/tests/ui/ok/async-in-trait.rs similarity index 100% rename from tests/macros/tests/ui/ok/async-in-trait.rs rename to tests-build/tests/ui/ok/async-in-trait.rs diff --git a/tests/macros/tests/ui/ok/async-trait-dyn-future.rs b/tests-build/tests/ui/ok/async-trait-dyn-future.rs similarity index 100% rename from tests/macros/tests/ui/ok/async-trait-dyn-future.rs rename to tests-build/tests/ui/ok/async-trait-dyn-future.rs diff --git a/tests/macros/tests/ui/ok/async-trait.rs b/tests-build/tests/ui/ok/async-trait.rs similarity index 100% rename from tests/macros/tests/ui/ok/async-trait.rs rename to tests-build/tests/ui/ok/async-trait.rs diff --git a/tests/macros/tests/ui/ok/dyn-future.rs b/tests-build/tests/ui/ok/dyn-future.rs similarity index 100% rename from tests/macros/tests/ui/ok/dyn-future.rs rename to tests-build/tests/ui/ok/dyn-future.rs diff --git a/tests/macros/tests/ui/ok/has-crate-path.rs b/tests-build/tests/ui/ok/has-crate-path.rs similarity index 100% rename from tests/macros/tests/ui/ok/has-crate-path.rs rename to tests-build/tests/ui/ok/has-crate-path.rs diff --git a/tests/macros/tests/ui/ok/has-enter-on-poll.rs b/tests-build/tests/ui/ok/has-enter-on-poll.rs similarity index 100% rename from tests/macros/tests/ui/ok/has-enter-on-poll.rs rename to tests-build/tests/ui/ok/has-enter-on-poll.rs diff --git a/tests/macros/tests/ui/ok/has-generic-signatures.rs b/tests-build/tests/ui/ok/has-generic-signatures.rs similarity index 100% rename from tests/macros/tests/ui/ok/has-generic-signatures.rs rename to tests-build/tests/ui/ok/has-generic-signatures.rs diff --git a/tests/macros/tests/ui/ok/has-methods.rs b/tests-build/tests/ui/ok/has-methods.rs similarity index 100% rename from tests/macros/tests/ui/ok/has-methods.rs rename to tests-build/tests/ui/ok/has-methods.rs diff --git a/tests/macros/tests/ui/ok/has-name-and-short-name.rs b/tests-build/tests/ui/ok/has-name-and-short-name.rs similarity index 100% rename from tests/macros/tests/ui/ok/has-name-and-short-name.rs rename to tests-build/tests/ui/ok/has-name-and-short-name.rs diff --git a/tests/macros/tests/ui/ok/has-name-async-mut.rs b/tests-build/tests/ui/ok/has-name-async-mut.rs similarity index 100% rename from tests/macros/tests/ui/ok/has-name-async-mut.rs rename to tests-build/tests/ui/ok/has-name-async-mut.rs diff --git a/tests/macros/tests/ui/ok/has-name-async.rs b/tests-build/tests/ui/ok/has-name-async.rs similarity index 100% rename from tests/macros/tests/ui/ok/has-name-async.rs rename to tests-build/tests/ui/ok/has-name-async.rs diff --git a/tests/macros/tests/ui/ok/has-name-mut.rs b/tests-build/tests/ui/ok/has-name-mut.rs similarity index 100% rename from tests/macros/tests/ui/ok/has-name-mut.rs rename to tests-build/tests/ui/ok/has-name-mut.rs diff --git a/tests/macros/tests/ui/ok/has-name.rs b/tests-build/tests/ui/ok/has-name.rs similarity index 100% rename from tests/macros/tests/ui/ok/has-name.rs rename to tests-build/tests/ui/ok/has-name.rs diff --git a/tests/macros/tests/ui/ok/has-no-arguments.rs b/tests-build/tests/ui/ok/has-no-arguments.rs similarity index 100% rename from tests/macros/tests/ui/ok/has-no-arguments.rs rename to tests-build/tests/ui/ok/has-no-arguments.rs diff --git a/tests/macros/tests/ui/ok/has-properties.rs b/tests-build/tests/ui/ok/has-properties.rs similarity index 100% rename from tests/macros/tests/ui/ok/has-properties.rs rename to tests-build/tests/ui/ok/has-properties.rs diff --git a/tests/macros/tests/ui/ok/has-short-name.rs b/tests-build/tests/ui/ok/has-short-name.rs similarity index 100% rename from tests/macros/tests/ui/ok/has-short-name.rs rename to tests-build/tests/ui/ok/has-short-name.rs diff --git a/tests/macros/tests/ui/ok/has-sync-properties.rs b/tests-build/tests/ui/ok/has-sync-properties.rs similarity index 100% rename from tests/macros/tests/ui/ok/has-sync-properties.rs rename to tests-build/tests/ui/ok/has-sync-properties.rs diff --git a/tests/macros/tests/ui/ok/has-unsafe-extern.rs b/tests-build/tests/ui/ok/has-unsafe-extern.rs similarity index 100% rename from tests/macros/tests/ui/ok/has-unsafe-extern.rs rename to tests-build/tests/ui/ok/has-unsafe-extern.rs diff --git a/tests/macros/tests/ui/ok/impl-stream.rs b/tests-build/tests/ui/ok/impl-stream.rs similarity index 100% rename from tests/macros/tests/ui/ok/impl-stream.rs rename to tests-build/tests/ui/ok/impl-stream.rs diff --git a/tests-integration/Cargo.toml b/tests-integration/Cargo.toml new file mode 100644 index 00000000..532c21d7 --- /dev/null +++ b/tests-integration/Cargo.toml @@ -0,0 +1,20 @@ +[package] +name = "tests-integration" +publish = false +version = "0.0.0" + +edition.workspace = true +rust-version.workspace = true + +[package.metadata.release] +release = false + +[dev-dependencies] +async-trait = { workspace = true } +crossbeam = { workspace = true } +fastrace = { workspace = true, features = ["enable"] } +futures-timer = { workspace = true } +insta = { workspace = true } +pollster = { workspace = true } +serial_test = { workspace = true } +tokio = { workspace = true } diff --git a/fastrace/tests/lib.rs b/tests-integration/tests/tests.rs similarity index 99% rename from fastrace/tests/lib.rs rename to tests-integration/tests/tests.rs index 2164c071..5b3b4567 100644 --- a/fastrace/tests/lib.rs +++ b/tests-integration/tests/tests.rs @@ -429,13 +429,14 @@ fn macro_example() { fastrace::flush(); let graph = tree_str_from_span_records(collected_spans.lock().clone()); - insta::assert_snapshot!(graph,@r###" + insta::assert_snapshot!(graph,@" + root [] do_something_async_short_name [] do_something_short_name [] - lib::macro_example::{{closure}}::do_something [] - lib::macro_example::{{closure}}::do_something_async::{{closure}} [] - "###); + tests::macro_example::{{closure}}::do_something [] + tests::macro_example::{{closure}}::do_something_async::{{closure}} [] + "); } #[test] diff --git a/tests/macros/Cargo.toml b/tests/macros/Cargo.toml deleted file mode 100644 index c9096dd7..00000000 --- a/tests/macros/Cargo.toml +++ /dev/null @@ -1,24 +0,0 @@ -[package] -name = "test-macros-ui" -publish = false -version = "0.0.0" - -edition.workspace = true -license.workspace = true -repository.workspace = true -rust-version.workspace = true - -[package.metadata.release] -release = false - -[dev-dependencies] -async-stream = { version = "0.3" } -fastrace = { workspace = true, features = ["enable"] } -futures = { version = "0.3" } -log = { workspace = true } -logcall = { version = "0.2" } -tokio = { workspace = true } -trybuild = { version = "1.0" } - -# The procedural macro `trace` only supports async-trait higher than or equal to 0.1.52 -async-trait = { version = "0.1.52" } diff --git a/tests/statically-disable/Cargo.toml b/tests/statically-disable/Cargo.toml deleted file mode 100644 index 2bd56232..00000000 --- a/tests/statically-disable/Cargo.toml +++ /dev/null @@ -1,15 +0,0 @@ -[package] -name = "test-statically-disable" -publish = false -version = "0.0.0" - -edition.workspace = true -license.workspace = true -repository.workspace = true -rust-version.workspace = true - -[package.metadata.release] -release = false - -[dependencies] -fastrace = { workspace = true } # do not turn on the "enable" feature