Skip to content

Commit 49d5d57

Browse files
chore: segment new tracing setup behavior behind new feature flag
1 parent 1994ace commit 49d5d57

File tree

3 files changed

+49
-23
lines changed

3 files changed

+49
-23
lines changed

runtime/Cargo.toml

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -45,22 +45,11 @@ tokio = { workspace = true, features = ["full"] }
4545
tokio-util = { workspace = true }
4646
tokio-stream = { workspace = true }
4747
tonic = { workspace = true }
48-
tracing = { workspace = true, optional = true, features = ["attributes", "std"] }
48+
tracing = { workspace = true, features = ["attributes", "std"] }
4949
tracing-core = { version = "0.1", optional = true, default-features = false, features = ["std"] }
5050
tracing-log = { version = "0.2", optional = true, default-features = false, features = ["log-tracer", "std"] }
5151
tracing-opentelemetry = { version = "0.28.0", optional = true, default-features = false, features = ["metrics"] }
52-
tracing-subscriber = { workspace = true, optional = true, features = [
53-
"alloc",
54-
"env-filter",
55-
"fmt",
56-
"parking_lot",
57-
"registry",
58-
"smallvec",
59-
"std",
60-
"tracing",
61-
"tracing-log",
62-
"tracing-serde",
63-
] }
52+
tracing-subscriber = { workspace = true, optional = true, default-features = false }
6453

6554
[dev-dependencies]
6655
portpicker = { workspace = true }
@@ -73,14 +62,26 @@ default = ["setup-tracing"]
7362
api-client-tracing = ["shuttle-api-client/tracing"]
7463

7564
setup-tracing = [
65+
"tracing-subscriber/ansi",
66+
"tracing-subscriber/env-filter",
67+
"tracing-subscriber/fmt",
68+
"tracing-subscriber/smallvec",
69+
"tracing-subscriber/std",
70+
"tracing-subscriber/tracing-log",
71+
]
72+
setup-telemetry = [
73+
"setup-tracing",
7674
"dep:log",
7775
"dep:opentelemetry",
7876
"dep:opentelemetry-otlp",
7977
"dep:opentelemetry_sdk",
8078
"dep:opentelemetry-semantic-conventions",
81-
"dep:tracing",
8279
"dep:tracing-core",
8380
"dep:tracing-log",
8481
"dep:tracing-opentelemetry",
85-
"dep:tracing-subscriber",
82+
"tracing-subscriber/alloc",
83+
"tracing-subscriber/parking_lot",
84+
"tracing-subscriber/registry",
85+
"tracing-subscriber/tracing",
86+
"tracing-subscriber/tracing-serde",
8687
]

runtime/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ mod plugins;
1212
mod rt;
1313
mod start;
1414

15-
#[cfg(feature = "setup-tracing")]
15+
#[cfg(feature = "setup-telemetry")]
1616
mod trace;
1717

1818
// Public API

runtime/src/start.rs

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ impl Args {
5151
pub async fn start(
5252
loader: impl Loader + Send + 'static,
5353
runner: impl Runner + Send + 'static,
54-
#[cfg_attr(not(feature = "setup-tracing"), allow(unused_variables))] project_name: &'static str,
54+
#[cfg_attr(not(feature = "setup-telemetry"), allow(unused_variables))]
55+
project_name: &'static str,
56+
#[cfg_attr(not(feature = "setup-telemetry"), allow(unused_variables))]
5557
project_version: &'static str,
5658
) {
5759
// `--version` overrides any other arguments. Used by cargo-shuttle to check compatibility on local runs.
@@ -74,17 +76,40 @@ pub async fn start(
7476
};
7577

7678
// this is handled after arg parsing to not interfere with --version above
77-
#[cfg(feature = "setup-tracing")]
79+
#[cfg(all(feature = "setup-tracing", not(feature = "setup-telemetry")))]
80+
{
81+
use tracing_subscriber::{fmt, prelude::*, registry, EnvFilter};
82+
registry()
83+
.with(fmt::layer().without_time())
84+
.with(
85+
// let user override RUST_LOG in local run if they want to
86+
EnvFilter::try_from_default_env().unwrap_or_else(|_| {
87+
// otherwise use our default
88+
Into::into(format!(
89+
"{},{}=debug",
90+
if args.beta {
91+
"info"
92+
} else {
93+
"info,shuttle=trace"
94+
},
95+
project_name
96+
))
97+
}),
98+
)
99+
.init();
100+
}
101+
102+
#[cfg(feature = "setup-telemetry")]
78103
let _guard = crate::trace::init_tracing_subscriber(project_name, project_version);
79104

80-
#[cfg(feature = "setup-tracing")]
105+
#[cfg(any(feature = "setup-tracing", feature = "setup-telemetry"))]
81106
if args.beta {
82-
eprintln!(
83-
"INFO - Default tracing subscriber initialized (https://docs.shuttle.dev/docs/logs)"
107+
tracing::warn!(
108+
"Default tracing subscriber initialized (https://docs.shuttle.dev/docs/logs)"
84109
);
85110
} else {
86-
eprintln!(
87-
"INFO - Default tracing subscriber initialized (https://docs.shuttle.rs/configuration/logs)"
111+
tracing::warn!(
112+
"Default tracing subscriber initialized (https://docs.shuttle.rs/configuration/logs)"
88113
);
89114
}
90115

0 commit comments

Comments
 (0)