Skip to content

Commit

Permalink
Merge branch 'v0.1.x' into fix-logging-with-interest-cache
Browse files Browse the repository at this point in the history
  • Loading branch information
hawkw committed Jun 22, 2022
2 parents deadf66 + f7966bd commit fa45696
Show file tree
Hide file tree
Showing 26 changed files with 595 additions and 233 deletions.
59 changes: 49 additions & 10 deletions .github/workflows/check_msrv.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,37 +27,76 @@ env:
RUSTUP_MAX_RETRIES: 10
# Don't emit giant backtraces in the CI logs.
RUST_BACKTRACE: short
MSRV: 1.49.0
# TODO: remove this once tracing's MSRV is bumped.
APPENDER_MSRV: 1.53.0

jobs:
check-msrv:
# Run `cargo check` on our minimum supported Rust version (1.49.0).
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@main
- uses: actions-rs/toolchain@v1
- uses: actions/checkout@master
- name: "install Rust ${{ env.MSRV }}"
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ env.MSRV }}
profile: minimal
- name: "install Rust nightly"
uses: actions-rs/toolchain@v1
with:
toolchain: 1.49.0
toolchain: nightly
profile: minimal
override: true
- name: Select minimal versions
uses: actions-rs/cargo@v1
with:
command: update
args: -Z minimal-versions
toolchain: nightly
- name: Check
uses: actions-rs/cargo@v1
with:
command: check
args: --all --exclude=tracing-appender
# skip the following crates:
# - tracing-appender, as it has its own MSRV.
# TODO(eliza): remove this when appender is on the same MSRV as
# everything else
# - the examples, as they are not published & we don't care about
# MSRV support for them.
# - tracing-futures, as it depends on ancient tokio versions.
# TODO(eliza): remove this when the ancient tokio deps are dropped
args: >-
--workspace --all-features --locked
--exclude=tracing-appender
--exclude=tracing-examples
--exclude=tracing-futures
toolchain: ${{ env.MSRV }}

# TODO: remove this once tracing's MSRV is bumped.
check-msrv-appender:
# Run `cargo check` on our minimum supported Rust version (1.53.0).
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@main
- uses: actions-rs/toolchain@v1
- uses: actions/checkout@master
- name: "install Rust ${{ env.APPENDER_MSRV }}"
uses: actions-rs/toolchain@v1
with:
toolchain: 1.53.0
toolchain: ${{ env.APPENDER_MSRV }}
profile: minimal
override: true
- name: "install Rust nightly"
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
profile: minimal
- name: Select minimal versions
uses: actions-rs/cargo@v1
with:
command: update
args: -Z minimal-versions
toolchain: nightly
- name: Check
uses: actions-rs/cargo@v1
with:
command: check
args: --lib=tracing-appender
args: --all-features --locked -p tracing-appender
toolchain: ${{ env.APPENDER_MSRV }}
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ are not maintained by the `tokio` project. These include:
- [`tracing-forest`] provides a subscriber that preserves contextual coherence by
grouping together logs from the same spans during writing.
- [`tracing-loki`] provides a layer for shipping logs to [Grafana Loki].
- [`tracing-logfmt`] provides a layer that formats events and spans into the logfmt format.

(if you're the maintainer of a `tracing` ecosystem crate not in this list,
please let us know!)
Expand Down Expand Up @@ -439,6 +440,7 @@ please let us know!)
[`tracing-forest`]: https://crates.io/crates/tracing-forest
[`tracing-loki`]: https://crates.io/crates/tracing-loki
[Grafana Loki]: https://grafana.com/oss/loki/
[`tracing-logfmt`]: https://crates.io/crates/tracing-logfmt

**Note:** that some of the ecosystem crates are currently unreleased and
undergoing active development. They may be less stable than `tracing` and
Expand Down
75 changes: 56 additions & 19 deletions bin/publish
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env bash
set -e
USAGE="Publish a new release of a tokio crate
USAGE:
Expand All @@ -10,11 +9,15 @@ OPTIONS:
-d, --dry-run Perform a dry run (do not publish or tag the release)
-h, --help Show this help text and exit"

set -euo pipefail

cd "$(dirname "$0")"/..

DRY_RUN=""
VERBOSE=""

err() {
echo -e "\e[31m\e[1merror:\e[0m $@" 1>&2;
echo -e "\e[31m\e[1merror:\e[0m" "$@" 1>&2;
}

status() {
Expand All @@ -31,20 +34,40 @@ verify() {
exit 1
fi

if ! cargo list | grep -q "hack"; then
status "Installing" "cargo-hack"
cargo install cargo-hack
if ! cargo --list | grep -q "hack"; then
err "missing cargo-hack executable"
read -r -p "install it? [Y/n] " INPUT

case "$INPUT" in
[yY][eE][sS]|[yY])
status "Installing" "cargo-hack"
cargo install cargo-hack
;;
[nN][oO]|[nN])
echo "okay, exiting"
exit 1
;;
*)
err "invalid input $INPUT"
exit 1
;;
esac
fi

status "Checking" "if $CRATE builds across feature combinations"

CARGO_HACK=(cargo hack check $VERBOSE --feature-powerset --no-dev-deps)
CARGO_HACK=(cargo hack check --feature-powerset --no-dev-deps)

if [[ "$VERBOSE" ]]; then
CARGO_HACK+=("$VERBOSE")
fi

case "$CRATE" in
tracing-subscriber)
# for tracing-subscriber, don't test a complete powerset because
# there are lots of feature flags
INCLUDE_FEATURES=(fmt ansi json registry env-filter)
${CARGO_HACK[@]} --include-features "${INCLUDE_FEATURES[*]}"
"${CARGO_HACK[@]}" --include-features "${INCLUDE_FEATURES[*]}"
CARGO_HACK_STATUS="$?"
;;
tracing)
Expand All @@ -58,17 +81,17 @@ verify() {
release_max_level_info release_max_level_debug
release_max_level_trace
)
${CARGO_HACK[@]} --exclude-features "${EXCLUDE_FEATURES[*]}"
"${CARGO_HACK[@]}" --exclude-features "${EXCLUDE_FEATURES[*]}"
CARGO_HACK_STATUS="$?"
;;
*)
${CARGO_HACK[@]}
"${CARGO_HACK[@]}"
CARGO_HACK_STATUS="$?"
;;
esac

if "$CARGO_HACK_STATUS" ; then
err "$CRATE did not build with all feature combinations!"
if [[ "$CARGO_HACK_STATUS" != "0" ]] ; then
err "$CRATE did not build with all feature combinations (cargo hack exited with $CARGO_HACK_STATUS)!"
exit 1
fi

Expand All @@ -81,11 +104,25 @@ verify() {

release() {
status "Releasing" "$CRATE v$VERSION"
cargo package $VERBOSE
cargo publish $VERBOSE $DRY_RUN
local CARGO_PACKAGE=(cargo package)
local CARGO_PUBLISH=(cargo publish)

if [[ "$VERBOSE" ]]; then
CARGO_PACKAGE+=("$VERBOSE")
CARGO_PUBLISH+=("$VERBOSE")
fi

if [[ "$DRY_RUN" ]]; then
CARGO_PUBLISH+=("$DRY_RUN")
fi

"${CARGO_PACKAGE[@]}"
"${CARGO_PUBLISH[@]}"

cargo publish "$VERBOSE" "$DRY_RUN"

status "Tagging" "$TAG"
if [ -n "$DRY_RUN" ]; then
if [[ "$DRY_RUN" ]]; then
echo "# git tag $TAG && git push --tags"
else
git tag "$TAG" && git push --tags
Expand All @@ -111,9 +148,9 @@ case "$1" in
exit 1
;;
*) # crate or version
if [ -z "$CRATE" ]; then
if [[ -z "${CRATE+crate}" ]]; then
CRATE="$1"
elif [ -z "$VERSION" ]; then
elif [[ -z "${VERSION+version}" ]]; then
VERSION="$1"
else
err "unknown positional argument \"$1\""
Expand All @@ -126,19 +163,19 @@ esac
done
# set -- "${POSITIONAL[@]}"

if [ -z "$VERSION" ]; then
if [[ -z "${VERSION+version}" ]]; then
err "no version specified!"
HELP=1
fi

if [ -n "$CRATE" ]; then
if [[ "${CRATE+crate}" ]]; then
TAG="$CRATE-$VERSION"
else
err "no crate specified!"
HELP=1
fi

if [ -n "$HELP" ]; then
if [[ "${HELP+help}" ]]; then
echo "$USAGE"
exit 1
fi
Expand Down
5 changes: 4 additions & 1 deletion examples/examples/opentelemetry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,11 @@ fn main() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {

warn!("About to exit!");
trace!("status: {}", work_result);
}
} // Once this scope is closed, all spans inside are closed as well

// Shut down the current tracer provider. This will invoke the shutdown
// method on all span processors. span processors should export remaining
// spans before return.
global::shutdown_tracer_provider();

Ok(())
Expand Down
13 changes: 13 additions & 0 deletions tracing-attributes/tests/fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ fn fn_clashy_expr_field2(s: &str) {
let _ = s;
}

#[instrument(fields(s = &s))]
fn fn_string(s: String) {
let _ = s;
}

#[derive(Debug)]
struct HasField {
my_field: &'static str,
Expand Down Expand Up @@ -134,6 +139,14 @@ fn empty_field() {
});
}

#[test]
fn string_field() {
let span = span::mock().with_field(mock("s").with_value(&"hello world").only());
run_test(span, || {
fn_string(String::from("hello world"));
});
}

fn run_test<F: FnOnce() -> T, T>(span: NewSpan, fun: F) {
let (subscriber, handle) = subscriber::mock()
.new_span(span)
Expand Down
13 changes: 3 additions & 10 deletions tracing-core/src/callsite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ use crate::stdlib::{
};
use crate::{
dispatcher::Dispatch,
lazy::Lazy,
metadata::{LevelFilter, Metadata},
subscriber::Interest,
};
Expand Down Expand Up @@ -253,14 +254,7 @@ static CALLSITES: Callsites = Callsites {

static DISPATCHERS: Dispatchers = Dispatchers::new();

#[cfg(feature = "std")]
static LOCKED_CALLSITES: once_cell::sync::Lazy<Mutex<Vec<&'static dyn Callsite>>> =
once_cell::sync::Lazy::new(Default::default);

#[cfg(not(feature = "std"))]
crate::lazy_static! {
static ref LOCKED_CALLSITES: Mutex<Vec<&'static dyn Callsite>> = Mutex::new(Vec::new());
}
static LOCKED_CALLSITES: Lazy<Mutex<Vec<&'static dyn Callsite>>> = Lazy::new(Default::default);

struct Callsites {
list_head: AtomicPtr<DefaultCallsite>,
Expand Down Expand Up @@ -514,8 +508,7 @@ mod private {

#[cfg(feature = "std")]
mod dispatchers {
use crate::dispatcher;
use once_cell::sync::Lazy;
use crate::{dispatcher, lazy::Lazy};
use std::sync::{
atomic::{AtomicBool, Ordering},
RwLock, RwLockReadGuard, RwLockWriteGuard,
Expand Down
4 changes: 3 additions & 1 deletion tracing-core/src/dispatcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,9 @@ impl Dispatch {
/// [`event`]: super::subscriber::Subscriber::event
#[inline]
pub fn event(&self, event: &Event<'_>) {
self.subscriber.event(event)
if self.subscriber.event_enabled(event) {
self.subscriber.event(event);
}
}

/// Records that a span has been can_enter.
Expand Down
Loading

0 comments on commit fa45696

Please sign in to comment.