Skip to content

Commit 73f1729

Browse files
committed
chore(instrumentation): Improve trace events with fields
1 parent f38ee2b commit 73f1729

File tree

8 files changed

+44
-30
lines changed

8 files changed

+44
-30
lines changed

rust/stackable-cockpit/src/platform/operator/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ impl OperatorSpec {
191191
namespace: &str,
192192
chart_source: &ChartSourceType,
193193
) -> Result<(), helm::Error> {
194-
info!("Installing operator {}", self);
194+
info!(operator = %self, "Installing operator");
195195

196196
let version = self.version.as_ref().map(|v| v.to_string());
197197
let helm_name = self.helm_name();

rust/stackable-cockpit/src/platform/release/spec.rs

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -70,26 +70,34 @@ impl ReleaseSpec {
7070
let namespace = namespace.to_string();
7171
futures::stream::iter(self.filter_products(include_products, exclude_products))
7272
.map(|(product_name, product)| {
73+
let task_span =
74+
tracing::debug_span!("install_operator", product_name = tracing::field::Empty);
75+
7376
let namespace = namespace.clone();
7477
let chart_source = chart_source.clone();
7578
// Helm installs currently `block_in_place`, so we need to spawn each job onto a separate task to
7679
// get useful parallelism.
77-
tokio::spawn(async move {
78-
info!("Installing {product_name}-operator");
79-
80-
// Create operator spec
81-
let operator = OperatorSpec::new(&product_name, Some(product.version.clone()))
82-
.context(OperatorSpecParseSnafu)?;
83-
84-
// Install operator
85-
operator
86-
.install(&namespace, &chart_source)
87-
.context(HelmInstallSnafu)?;
88-
89-
info!("Installed {product_name}-operator");
90-
91-
Ok(())
92-
})
80+
tokio::spawn(
81+
async move {
82+
Span::current().record("product_name", &product_name);
83+
info!("Installing {product_name}-operator");
84+
85+
// Create operator spec
86+
let operator =
87+
OperatorSpec::new(&product_name, Some(product.version.clone()))
88+
.context(OperatorSpecParseSnafu)?;
89+
90+
// Install operator
91+
operator
92+
.install(&namespace, &chart_source)
93+
.context(HelmInstallSnafu)?;
94+
95+
info!("Installed {product_name}-operator");
96+
97+
Ok(())
98+
}
99+
.instrument(task_span),
100+
)
93101
})
94102
.buffer_unordered(10)
95103
.map(|res| res.context(BackgroundTaskSnafu)?)

rust/stackable-cockpit/src/platform/stack/spec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ impl StackSpec {
206206
_product_namespace: &str, // TODO (@NickLarsenNZ): remove this field
207207
chart_source: &ChartSourceType,
208208
) -> Result<(), Error> {
209-
info!("Trying to install release {}", self.release);
209+
info!(self.release, "Trying to install release");
210210

211211
// Get the release by name
212212
let release = release_list

rust/stackablectl/src/cli/mod.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ impl Cli {
152152

153153
pub fn cache_settings(&self) -> Result<Settings, CacheSettingsError> {
154154
if self.no_cache {
155+
tracing::debug!("Cache disabled");
155156
Ok(Settings::disabled())
156157
} else {
157158
let project_dir = ProjectDirs::from(
@@ -161,7 +162,12 @@ impl Cli {
161162
)
162163
.ok_or(CacheSettingsError::UserDir)?;
163164

164-
Ok(Settings::disk(project_dir.cache_dir()))
165+
let cache_dir = project_dir.cache_dir();
166+
tracing::debug!(
167+
cache_dir = %cache_dir.to_string_lossy(),
168+
"Setting cache directory"
169+
);
170+
Ok(Settings::disk(cache_dir))
165171
}
166172
}
167173

rust/stackablectl/src/cmds/demo.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ async fn describe_cmd(
265265
cli: &Cli,
266266
list: demo::List,
267267
) -> Result<String, CmdError> {
268-
info!("Describing demo {}", args.demo_name);
268+
info!(demo_name = %args.demo_name, "Describing demo");
269269

270270
let demo = list.get(&args.demo_name).ok_or(CmdError::NoSuchDemo {
271271
name: args.demo_name.clone(),
@@ -327,7 +327,7 @@ async fn install_cmd(
327327
transfer_client: &xfer::Client,
328328
release_branch: &str,
329329
) -> Result<String, CmdError> {
330-
info!(%release_branch, "Installing demo {}", args.demo_name);
330+
info!(demo_name = %args.demo_name, "Installing demo");
331331

332332
// Init result output and progress output
333333
let mut output = cli.result();

rust/stackablectl/src/cmds/operator.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ async fn list_cmd(args: &OperatorListArgs, cli: &Cli) -> Result<String, CmdError
246246

247247
#[instrument(skip_all)]
248248
async fn describe_cmd(args: &OperatorDescribeArgs, cli: &Cli) -> Result<String, CmdError> {
249-
debug!("Describing operator {}", args.operator_name);
249+
debug!(operator_name = %args.operator_name, "Describing operator");
250250

251251
// Build map which maps artifacts to a chart source
252252
let source_index_files =
@@ -328,6 +328,8 @@ async fn install_cmd(args: &OperatorInstallArgs, cli: &Cli) -> Result<String, Cm
328328
)
329329
.context(HelmSnafu)?;
330330

331+
// TODO (@NickLarsenNZ): Send this to the progress handler instead of using println
332+
// info!(%operator, "Installed operator");
331333
println!("Installed {} operator", operator);
332334
}
333335

@@ -383,7 +385,7 @@ fn uninstall_cmd(args: &OperatorUninstallArgs, cli: &Cli) -> Result<String, CmdE
383385

384386
#[instrument(skip_all)]
385387
fn installed_cmd(args: &OperatorInstalledArgs, cli: &Cli) -> Result<String, CmdError> {
386-
debug!("Listing installed operators");
388+
info!("Listing installed operators");
387389

388390
type ReleaseList = IndexMap<String, Release>;
389391

@@ -523,10 +525,7 @@ fn build_versions_list_for_operator<T>(
523525
where
524526
T: AsRef<str> + std::fmt::Display + std::fmt::Debug,
525527
{
526-
debug!(
527-
"Build versions list for operator {}",
528-
operator_name.as_ref()
529-
);
528+
debug!("Build versions list for operator");
530529

531530
let mut versions_list = OperatorVersionList(HashMap::new());
532531
let operator_name = operator_name.as_ref();

rust/stackablectl/src/cmds/release.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ async fn describe_cmd(
211211
cli: &Cli,
212212
release_list: release::ReleaseList,
213213
) -> Result<String, CmdError> {
214-
info!("Describing release");
214+
info!(release = %args.release, "Describing release");
215215

216216
let release = release_list.get(&args.release);
217217

@@ -272,6 +272,7 @@ async fn install_cmd(
272272
cli: &Cli,
273273
release_list: release::ReleaseList,
274274
) -> Result<String, CmdError> {
275+
info!(release = %args.release, "Installing release");
275276
match release_list.get(&args.release) {
276277
Some(release) => {
277278
let mut output = cli.result();

rust/stackablectl/src/cmds/stack.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ fn describe_cmd(
249249
cli: &Cli,
250250
stack_list: stack::StackList,
251251
) -> Result<String, CmdError> {
252-
info!("Describing stack {}", args.stack_name);
252+
info!(stack_name = %args.stack_name, "Describing stack");
253253

254254
match stack_list.get(&args.stack_name) {
255255
Some(stack) => match args.output_type {
@@ -312,7 +312,7 @@ async fn install_cmd(
312312
stack_list: stack::StackList,
313313
transfer_client: &xfer::Client,
314314
) -> Result<String, CmdError> {
315-
info!("Installing stack {}", args.stack_name);
315+
info!(stack_name = %args.stack_name, "Installing stack");
316316

317317
let files = cli.get_release_files().context(PathOrUrlParseSnafu)?;
318318
let release_list = release::ReleaseList::build(&files, transfer_client)

0 commit comments

Comments
 (0)