Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trace stdout from test-proxy #2274

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[toolchain]
channel = "1.80.0"
channel = "stable"
components = [
"rustc",
"rustfmt",
Expand Down
20 changes: 20 additions & 0 deletions sdk/core/azure_core_test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,26 @@ cargo test
If you get errors, they could indicate regressions in your tests or perhaps variables or random data wasn't saved correctly.
Review any data you generate or use not coming from the service.

## Troubleshooting

Like all Azure SDK client libraries, the `azure_core_test` crate writes information with the target rooted in the crate name
followed by any modules in which the span was created e.g., `azure_core_test::proxy`.
Because this crate is used to test Azure SDK client libraries and developers will most likely want to see fewer traces from this crate,
the log levels used are a level lower than typical client libraries:

- `INFO` includes only important information e.g., the version of `test-proxy` and on what port it's listening.
- `DEBUG` includes when a test recording or playback has started and stopped.
- `TRACE` includes details like communications with the `test-proxy` itself.

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.

You can configuring using the [`RUST_LOG`](https://docs.rs/env_logger) environment variable.
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:

```bash
RUST_LOG=debug,test-proxy=trace cargo test
```

[PowerShell]: https://learn.microsoft.com/powershell/scripting/install/installing-powershell
[Test Proxy]: https://github.com/Azure/azure-sdk-tools/blob/main/tools/test-proxy/Azure.Sdk.Tools.TestProxy/README.md
[Test Resources]: https://github.com/Azure/azure-sdk-tools/blob/main/eng/common/TestResources/README.md
29 changes: 22 additions & 7 deletions sdk/core/azure_core_test/examples/test_proxy.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

use clap::Parser;
use clap::{ArgAction, Parser};

#[cfg(not(target_arch = "wasm32"))]
#[tokio::main]
Expand Down Expand Up @@ -46,33 +46,48 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
#[derive(Debug, Parser)]
#[command(about = "Starts the Test-Proxy service", version)]
struct Args {
/// Bind to any available port.
///
/// If not set, only port `5000` will be tried.
/// You can start the `test-proxy` service this way
/// and pass `PROXY_MANUAL_START=true` when running `cargo test` to easily view trace information.
#[arg(long)]
auto: bool,

/// Allow insecure upstream SSL certs.
#[arg(long)]
insecure: bool,

/// Number of seconds to automatically shut down when no activity.
#[arg(long, default_value_t = 300)]
pub auto_shutdown_in_seconds: u32,
auto_shutdown_in_seconds: u32,

/// Enable verbose logging.
#[arg(short, long)]
verbose: bool,
///
/// Trace level `INFO` is used by default.
/// Pass `-v` to enable `DEBUG` level tracing,
/// or `-vv` to enable `TRACE` level tracing.
#[arg(short, long, action = ArgAction::Count)]
verbose: u8,
}

impl Args {
#[cfg(not(target_arch = "wasm32"))]
fn trace_level(&self) -> tracing::level_filters::LevelFilter {
if self.verbose {
return tracing::level_filters::LevelFilter::DEBUG;
use tracing::level_filters::LevelFilter;
match self.verbose {
0 => LevelFilter::INFO,
1 => LevelFilter::DEBUG,
_ => LevelFilter::TRACE,
}
tracing::level_filters::LevelFilter::INFO
}
}

#[cfg(not(target_arch = "wasm32"))]
impl From<Args> for azure_core_test::proxy::ProxyOptions {
fn from(args: Args) -> Self {
Self {
auto: args.auto,
insecure: args.insecure,
auto_shutdown_in_seconds: args.auto_shutdown_in_seconds,
}
Expand Down
Loading