Skip to content

Commit 9c0ab12

Browse files
authored
Trace stdout from test-proxy (#2274)
* Trace stdout from test-proxy This is a big refactor of the test-proxy wrapper that will precede other work. This will help diagnose issues that, in the past, you could only do if you started the test-proxy separately and remembered to pass `PROXY_MANUAL_START=true` when testing. * Trace stderr as ERROR level * Resolve PR feedback
1 parent dd56996 commit 9c0ab12

File tree

4 files changed

+203
-106
lines changed

4 files changed

+203
-106
lines changed

sdk/core/azure_core_test/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,26 @@ cargo test
105105
If you get errors, they could indicate regressions in your tests or perhaps variables or random data wasn't saved correctly.
106106
Review any data you generate or use not coming from the service.
107107

108+
## Troubleshooting
109+
110+
Like all Azure SDK client libraries, the `azure_core_test` crate writes information with the target rooted in the crate name
111+
followed by any modules in which the span was created e.g., `azure_core_test::proxy`.
112+
Because this crate is used to test Azure SDK client libraries and developers will most likely want to see fewer traces from this crate,
113+
the log levels used are a level lower than typical client libraries:
114+
115+
- `INFO` includes only important information e.g., the version of `test-proxy` and on what port it's listening.
116+
- `DEBUG` includes when a test recording or playback has started and stopped.
117+
- `TRACE` includes details like communications with the `test-proxy` itself.
118+
119+
The `azure_core_test` crate also traces useful information that the `test-proxy` process itself writes to `stdout` using the `test-proxy` target and the `TRACE` logging level.
120+
121+
You can configure tracing using the [`RUST_LOG`](https://docs.rs/env_logger) environment variable.
122+
For example, if you wanted to see debug information from all sources by default but see `test-proxy` messages written to `stdout` you'd run:
123+
124+
```bash
125+
RUST_LOG=debug,test-proxy=trace cargo test
126+
```
127+
108128
[PowerShell]: https://learn.microsoft.com/powershell/scripting/install/installing-powershell
109129
[Test Proxy]: https://github.com/Azure/azure-sdk-tools/blob/main/tools/test-proxy/Azure.Sdk.Tools.TestProxy/README.md
110130
[Test Resources]: https://github.com/Azure/azure-sdk-tools/blob/main/eng/common/TestResources/README.md

sdk/core/azure_core_test/examples/test_proxy.rs

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4-
use clap::Parser;
4+
use clap::{ArgAction, Parser};
55

66
#[cfg(not(target_arch = "wasm32"))]
77
#[tokio::main]
@@ -46,33 +46,48 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
4646
#[derive(Debug, Parser)]
4747
#[command(about = "Starts the Test-Proxy service", version)]
4848
struct Args {
49+
/// Bind to any available port.
50+
///
51+
/// If not set, only port `5000` will be tried.
52+
/// You can start the `test-proxy` service this way
53+
/// and pass `PROXY_MANUAL_START=true` when running `cargo test` to easily view trace information.
54+
#[arg(long)]
55+
auto: bool,
56+
4957
/// Allow insecure upstream SSL certs.
5058
#[arg(long)]
5159
insecure: bool,
5260

5361
/// Number of seconds to automatically shut down when no activity.
5462
#[arg(long, default_value_t = 300)]
55-
pub auto_shutdown_in_seconds: u32,
63+
auto_shutdown_in_seconds: u32,
5664

5765
/// Enable verbose logging.
58-
#[arg(short, long)]
59-
verbose: bool,
66+
///
67+
/// Trace level `INFO` is used by default.
68+
/// Pass `-v` to enable `DEBUG` level tracing,
69+
/// or `-vv` to enable `TRACE` level tracing.
70+
#[arg(short, long, action = ArgAction::Count)]
71+
verbose: u8,
6072
}
6173

6274
impl Args {
6375
#[cfg(not(target_arch = "wasm32"))]
6476
fn trace_level(&self) -> tracing::level_filters::LevelFilter {
65-
if self.verbose {
66-
return tracing::level_filters::LevelFilter::DEBUG;
77+
use tracing::level_filters::LevelFilter;
78+
match self.verbose {
79+
0 => LevelFilter::INFO,
80+
1 => LevelFilter::DEBUG,
81+
_ => LevelFilter::TRACE,
6782
}
68-
tracing::level_filters::LevelFilter::INFO
6983
}
7084
}
7185

7286
#[cfg(not(target_arch = "wasm32"))]
7387
impl From<Args> for azure_core_test::proxy::ProxyOptions {
7488
fn from(args: Args) -> Self {
7589
Self {
90+
auto: args.auto,
7691
insecure: args.insecure,
7792
auto_shutdown_in_seconds: args.auto_shutdown_in_seconds,
7893
}

0 commit comments

Comments
 (0)