Skip to content

Commit 2e742c9

Browse files
authored
Merge pull request #541 from SteveL-MSFT/trace-envvar
Add `pass-through` trace format to `dsc` so that child-processes get traced appropriately by top process
2 parents f047b42 + f573900 commit 2e742c9

15 files changed

+148
-37
lines changed

dsc/Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dsc/assertion.dsc.resource.json

+8-10
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
"get": {
88
"executable": "dsc",
99
"args": [
10+
"--trace-format",
11+
"pass-through",
1012
"config",
1113
"--as-group",
1214
"test",
@@ -17,6 +19,8 @@
1719
"set": {
1820
"executable": "dsc",
1921
"args": [
22+
"--trace-format",
23+
"pass-through",
2024
"config",
2125
"--as-group",
2226
"test"
@@ -28,6 +32,8 @@
2832
"test": {
2933
"executable": "dsc",
3034
"args": [
35+
"--trace-format",
36+
"pass-through",
3137
"config",
3238
"--as-group",
3339
"test",
@@ -45,19 +51,11 @@
4551
"5": "Resource instance failed schema validation",
4652
"6": "Command cancelled"
4753
},
48-
"schema": {
49-
"command": {
50-
"executable": "dsc",
51-
"args": [
52-
"schema",
53-
"--type",
54-
"configuration"
55-
]
56-
}
57-
},
5854
"validate": {
5955
"executable": "dsc",
6056
"args": [
57+
"--trace-format",
58+
"pass-through",
6159
"config",
6260
"validate"
6361
],

dsc/group.dsc.resource.json

+8
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
"get": {
88
"executable": "dsc",
99
"args": [
10+
"--trace-format",
11+
"pass-through",
1012
"config",
1113
"--as-group",
1214
"get"
@@ -16,6 +18,8 @@
1618
"set": {
1719
"executable": "dsc",
1820
"args": [
21+
"--trace-format",
22+
"pass-through",
1923
"config",
2024
"--as-group",
2125
"set"
@@ -27,6 +31,8 @@
2731
"test": {
2832
"executable": "dsc",
2933
"args": [
34+
"--trace-format",
35+
"pass-through",
3036
"config",
3137
"--as-group",
3238
"test"
@@ -46,6 +52,8 @@
4652
"validate": {
4753
"executable": "dsc",
4854
"args": [
55+
"--trace-format",
56+
"pass-through",
4957
"config",
5058
"validate"
5159
],

dsc/include.dsc.resource.json

+8
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
"get": {
88
"executable": "dsc",
99
"args": [
10+
"--trace-format",
11+
"pass-through",
1012
"config",
1113
"--as-include",
1214
"--as-group",
@@ -17,6 +19,8 @@
1719
"set": {
1820
"executable": "dsc",
1921
"args": [
22+
"--trace-format",
23+
"pass-through",
2024
"config",
2125
"--as-include",
2226
"--as-group",
@@ -29,6 +33,8 @@
2933
"test": {
3034
"executable": "dsc",
3135
"args": [
36+
"--trace-format",
37+
"pass-through",
3238
"config",
3339
"--as-include",
3440
"--as-group",
@@ -48,6 +54,8 @@
4854
"validate": {
4955
"executable": "dsc",
5056
"args": [
57+
"--trace-format",
58+
"pass-through",
5159
"config",
5260
"--as-include",
5361
"validate"

dsc/parallel.dsc.resource.json

+8
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
"get": {
88
"executable": "dsc",
99
"args": [
10+
"--trace-format",
11+
"pass-through",
1012
"config",
1113
"--parallel",
1214
"--as-group",
@@ -17,6 +19,8 @@
1719
"set": {
1820
"executable": "dsc",
1921
"args": [
22+
"--trace-format",
23+
"pass-through",
2024
"config",
2125
"--parallel",
2226
"--as-group",
@@ -29,6 +33,8 @@
2933
"test": {
3034
"executable": "dsc",
3135
"args": [
36+
"--trace-format",
37+
"pass-through",
3238
"config",
3339
"--parallel",
3440
"--as-group",
@@ -49,6 +55,8 @@
4955
"validate": {
5056
"executable": "dsc",
5157
"args": [
58+
"--trace-format",
59+
"pass-through",
5260
"config",
5361
"validate"
5462
],

dsc/src/args.rs

+3-9
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
use clap::{Parser, Subcommand, ValueEnum};
55
use clap_complete::Shell;
6+
use dsc_lib::dscresources::command_resource::TraceLevel;
67

78
#[derive(Debug, Clone, PartialEq, Eq, ValueEnum)]
89
pub enum OutputFormat {
@@ -16,15 +17,8 @@ pub enum TraceFormat {
1617
Default,
1718
Plaintext,
1819
Json,
19-
}
20-
21-
#[derive(Debug, Clone, PartialEq, Eq, ValueEnum)]
22-
pub enum TraceLevel {
23-
Error,
24-
Warn,
25-
Info,
26-
Debug,
27-
Trace
20+
#[clap(hide = true)]
21+
PassThrough,
2822
}
2923

3024
#[derive(Debug, Parser)]

dsc/src/tablewriter.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crossterm::terminal::{size};
1+
use crossterm::terminal::size;
22

33
pub struct Table {
44
header: Vec<String>,
@@ -8,13 +8,13 @@ pub struct Table {
88

99
impl Table {
1010
/// Create a new table.
11-
///
11+
///
1212
/// # Arguments
13-
///
13+
///
1414
/// * `header` - The header row
15-
///
15+
///
1616
/// # Returns
17-
///
17+
///
1818
/// * `Table` - The new table
1919
#[must_use]
2020
pub fn new(header: &[&str]) -> Table {
@@ -31,9 +31,9 @@ impl Table {
3131
}
3232

3333
/// Add a row to the table.
34-
///
34+
///
3535
/// # Arguments
36-
///
36+
///
3737
/// * `row` - The row to add
3838
pub fn add_row(&mut self, row: Vec<String>) {
3939
for (i, column) in row.iter().enumerate() {

dsc/src/util.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

4-
use crate::args::{DscType, OutputFormat, TraceFormat, TraceLevel};
5-
4+
use crate::args::{DscType, OutputFormat, TraceFormat};
65
use atty::Stream;
76
use crate::resolve::Include;
87
use dsc_lib::{
@@ -16,6 +15,7 @@ use dsc_lib::{
1615
},
1716
dscerror::DscError,
1817
dscresources::{
18+
command_resource::TraceLevel,
1919
dscresource::DscResource, invoke_result::{
2020
GetResult,
2121
SetResult,
@@ -323,15 +323,15 @@ pub fn enable_tracing(trace_level: &Option<TraceLevel>, trace_format: &TraceForm
323323
.with_line_number(with_source)
324324
.boxed()
325325
},
326-
TraceFormat::Json => {
326+
TraceFormat::Json | TraceFormat::PassThrough => {
327327
layer
328328
.with_ansi(false)
329329
.with_level(true)
330330
.with_target(with_source)
331331
.with_line_number(with_source)
332332
.json()
333333
.boxed()
334-
}
334+
},
335335
};
336336

337337
let subscriber = tracing_subscriber::Registry::default().with(fmt).with(filter).with(indicatif_layer);

dsc/tests/dsc_tracing.tests.ps1

+12
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,16 @@ Describe 'tracing tests' {
8585
$out = (dsc -l $level config get -d $configYaml 2> $null) | ConvertFrom-Json
8686
$out.results[0].result.actualState.level | Should -BeExactly $level
8787
}
88+
89+
It 'Pass-through tracing should only emit JSON for child processes' {
90+
$logPath = "$TestDrive/dsc_trace.log"
91+
$out = dsc -l info -f pass-through config get -p ../examples/groups.dsc.yaml 2> $logPath
92+
foreach ($line in (Get-Content $logPath)) {
93+
$line | Should -Not -BeNullOrEmpty
94+
$json = $line | ConvertFrom-Json
95+
$json.timestamp | Should -Not -BeNullOrEmpty
96+
$json.level | Should -BeIn 'ERROR', 'WARN', 'INFO', 'DEBUG', 'TRACE'
97+
}
98+
$out | Should -BeNullOrEmpty
99+
}
88100
}

dsc_lib/Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dsc_lib/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ edition = "2021"
66
[dependencies]
77
base64 = "0.22.1"
88
chrono = "0.4.26"
9+
clap = { version = "4.4", features = ["derive"] }
910
derive_builder ="0.20.0"
1011
indicatif = "0.17.0"
1112
jsonschema = "0.18.0"

0 commit comments

Comments
 (0)