Skip to content

Commit 8dcacd7

Browse files
committed
feat: add structured logging instrumentation for command-level operations
- Add tracing attributes feature to Cargo.toml dependency - Add #[instrument] to ProvisionCommand::execute() with provision_command span - Add #[instrument] to ConfigureCommand::execute() with configure_command span - Add #[instrument] to TestCommand::execute() with test_command span - Update structured logging implementation plan to reflect Phase 1 completion This implements Phase 1 of the structured logging plan, creating hierarchical spans for all command-level operations with consistent naming and field conventions.
1 parent 2d03fe3 commit 8dcacd7

File tree

5 files changed

+35
-17
lines changed

5 files changed

+35
-17
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,5 @@ tempfile = "3.0"
3636
tera = "1.0"
3737
thiserror = "1.0"
3838
torrust-linting = { path = "packages/linting" }
39-
tracing = "0.1"
39+
tracing = { version = "0.1", features = [ "attributes" ] }
4040
tracing-subscriber = "0.3"

docs/structured-logging-implementation-plan.md

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,40 +28,40 @@ Level 1: Commands (Top-level orchestration)
2828

2929
### Phase 1: Commands (Level 1) - Foundation
3030

31-
**Status**: 🔴 **Not Started**
31+
**Status**: **Completed**
3232
**Priority**: High
3333
**Estimated Effort**: 2-3 days
3434

3535
#### Tasks
3636

37-
- [ ] **1.1** Add `#[instrument]` to `ProvisionCommand::execute()`
37+
- [x] **1.1** Add `#[instrument]` to `ProvisionCommand::execute()`
3838

3939
- File: `src/commands/provision.rs`
4040
- Span name: `provision_command`
4141
- Fields: `command_type="provision"`
4242

43-
- [ ] **1.2** Add `#[instrument]` to `ConfigureCommand::execute()`
43+
- [x] **1.2** Add `#[instrument]` to `ConfigureCommand::execute()`
4444

4545
- File: `src/commands/configure.rs`
4646
- Span name: `configure_command`
4747
- Fields: `command_type="configure"`
4848

49-
- [ ] **1.3** Add `#[instrument]` to `TestCommand::execute()`
49+
- [x] **1.3** Add `#[instrument]` to `TestCommand::execute()`
5050

5151
- File: `src/commands/test.rs`
5252
- Span name: `test_command`
5353
- Fields: `command_type="test"`
5454

55-
- [ ] **1.4** Verify dependencies and features
55+
- [x] **1.4** Verify dependencies and features
5656
- Ensure `tracing = { features = ["attributes"] }` in `Cargo.toml`
5757
- Test span creation and nesting
5858

5959
#### Acceptance Criteria
6060

61-
- All command-level operations are wrapped in spans
62-
- Spans include relevant contextual fields
63-
- Log output shows hierarchical structure at command level
64-
- E2E tests pass with new spans
61+
- All command-level operations are wrapped in spans
62+
- Spans include relevant contextual fields
63+
- Log output shows hierarchical structure at command level
64+
- E2E tests pass with new spans
6565

6666
#### Files to Modify
6767

@@ -274,15 +274,15 @@ Level 1: Commands (Top-level orchestration)
274274
### Overall Progress
275275

276276
- **Total Tasks**: 25
277-
- **Completed**: 0 (0%)
277+
- **Completed**: 4 (16%)
278278
- **In Progress**: 0 (0%)
279-
- **Not Started**: 25 (100%)
279+
- **Not Started**: 21 (84%)
280280

281281
### Phase Progress
282282

283283
| Phase | Status | Tasks Complete | Progress |
284284
| ----------------------- | -------------- | -------------- | -------- |
285-
| Phase 1: Commands | 🔴 Not Started | 0/4 | 0% |
285+
| Phase 1: Commands | � Completed | 4/4 | 100% |
286286
| Phase 2: Steps | 🔴 Not Started | 0/11 | 0% |
287287
| Phase 3: Remote Actions | 🔴 Not Started | 0/4 | 0% |
288288
| Phase 4: Optimization | 🔴 Not Started | 0/6 | 0% |
@@ -384,8 +384,15 @@ tracing = { version = "0.1", features = ["attributes"] }
384384

385385
---
386386

387-
**Next Steps**: Begin Phase 1 implementation with `ProvisionCommand` instrumentation.
387+
**Next Steps**: Begin Phase 2 implementation with Step-level instrumentation, starting with Infrastructure Steps.
388388

389389
**Dependencies**: None - can start immediately with existing tracing setup.
390390

391391
**Risk Assessment**: Low - Non-breaking changes, backward compatible, can be implemented incrementally.
392+
393+
**Phase 1 Completion Notes**:
394+
395+
- ✅ All command-level operations now have tracing spans
396+
- ✅ Spans use consistent naming convention and fields
397+
- ✅ All tests pass and linting checks succeed
398+
- ✅ Ready to proceed to Phase 2 (Steps instrumentation)

src/commands/configure.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::sync::Arc;
22

3-
use tracing::info;
3+
use tracing::{info, instrument};
44

55
use crate::command::CommandError;
66
use crate::command_wrappers::ansible::AnsibleClient;
@@ -38,6 +38,11 @@ impl ConfigureCommand {
3838
/// Returns an error if any step in the configuration workflow fails:
3939
/// * Docker installation fails
4040
/// * Docker Compose installation fails
41+
#[instrument(
42+
name = "configure_command",
43+
skip_all,
44+
fields(command_type = "configure")
45+
)]
4146
pub fn execute(&self) -> Result<(), ConfigureCommandError> {
4247
info!(
4348
command = "configure",

src/commands/provision.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::net::IpAddr;
22
use std::sync::Arc;
33

4-
use tracing::info;
4+
use tracing::{info, instrument};
55

66
use crate::ansible::AnsibleTemplateRenderer;
77
use crate::command::CommandError;
@@ -105,6 +105,11 @@ impl ProvisionCommand {
105105
/// * Unable to retrieve instance information
106106
/// * SSH connectivity cannot be established
107107
/// * Cloud-init does not complete successfully
108+
#[instrument(
109+
name = "provision_command",
110+
skip_all,
111+
fields(command_type = "provision")
112+
)]
108113
pub async fn execute(&self) -> Result<IpAddr, ProvisionCommandError> {
109114
info!(
110115
command = "provision",

src/commands/test.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use std::net::IpAddr;
2-
use tracing::{error, info};
2+
use tracing::{error, info, instrument};
33

44
use crate::command::CommandError;
55
use crate::command_wrappers::ssh::credentials::SshCredentials;
@@ -50,6 +50,7 @@ impl TestCommand {
5050
/// * Cloud-init completion validation fails
5151
/// * Docker installation validation fails
5252
/// * Docker Compose installation validation fails
53+
#[instrument(name = "test_command", skip_all, fields(command_type = "test"))]
5354
pub async fn execute(&self) -> Result<(), TestCommandError> {
5455
info!(
5556
command = "test",

0 commit comments

Comments
 (0)