Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

backport 9 commits from master #2174

Merged
merged 9 commits into from
Jun 22, 2022
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
4 changes: 3 additions & 1 deletion tracing-core/src/dispatcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,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
26 changes: 23 additions & 3 deletions tracing-core/src/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
//! will contain any fields attached to each event.
//!
//! `tracing` represents values as either one of a set of Rust primitives
//! (`i64`, `u64`, `f64`, `bool`, and `&str`) or using a `fmt::Display` or
//! `fmt::Debug` implementation. `Subscriber`s are provided these primitive
//! value types as `dyn Value` trait objects.
//! (`i64`, `u64`, `f64`, `i128`, `u128`, `bool`, and `&str`) or using a
//! `fmt::Display` or `fmt::Debug` implementation. `Subscriber`s are provided
//! these primitive value types as `dyn Value` trait objects.
//!
//! These trait objects can be formatted using `fmt::Debug`, but may also be
//! recorded as typed data by calling the [`Value::record`] method on these
Expand Down Expand Up @@ -116,6 +116,7 @@ use crate::stdlib::{
hash::{Hash, Hasher},
num,
ops::Range,
string::String,
};

use self::private::ValidLen;
Expand Down Expand Up @@ -277,6 +278,16 @@ pub trait Visit {
self.record_debug(field, &value)
}

/// Visit a signed 128-bit integer value.
fn record_i128(&mut self, field: &Field, value: i128) {
self.record_debug(field, &value)
}

/// Visit an unsigned 128-bit integer value.
fn record_u128(&mut self, field: &Field, value: u128) {
self.record_debug(field, &value)
}

/// Visit a boolean value.
fn record_bool(&mut self, field: &Field, value: bool) {
self.record_debug(field, &value)
Expand Down Expand Up @@ -489,6 +500,8 @@ impl_values! {
record_u64(usize, u32, u16, u8 as u64),
record_i64(i64),
record_i64(isize, i32, i16, i8 as i64),
record_u128(u128),
record_i128(i128),
record_bool(bool),
record_f64(f64, f32 as f64)
}
Expand Down Expand Up @@ -596,6 +609,13 @@ where
}
}

impl crate::sealed::Sealed for String {}
impl Value for String {
fn record(&self, key: &Field, visitor: &mut dyn Visit) {
visitor.record_str(key, self.as_str())
}
}

impl fmt::Debug for dyn Value {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// We are only going to be recording the field value, so we don't
Expand Down