Skip to content

fix(auth): route "Using keyring backend" log through tracing#767

Open
accounts-hash wants to merge 2 commits intogoogleworkspace:mainfrom
accounts-hash:fix/keyring-backend-via-tracing
Open

fix(auth): route "Using keyring backend" log through tracing#767
accounts-hash wants to merge 2 commits intogoogleworkspace:mainfrom
accounts-hash:fix/keyring-backend-via-tracing

Conversation

@accounts-hash
Copy link
Copy Markdown

Problem

credential_store.rs::get_or_create_key writes the keyring-backend selection
line via raw eprintln!, bypassing the tracing infrastructure the crate
already builds:

// crates/google-workspace-cli/src/credential_store.rs:360 (main)
// Item 5: log which backend was selected
eprintln!("Using keyring backend: {}", backend.as_str());

Two visible consequences:

  1. The documented GOOGLE_WORKSPACE_CLI_LOG env var cannot suppress it.
    gws --help advertises GOOGLE_WORKSPACE_CLI_LOG Log level for stderr (e.g., gws=debug),
    but gws=off, gws=warn, and gws=error all leave the banner on stderr.
  2. Pipelines that merge stdout + stderr break. Any consumer that captures
    both streams (tee 2>&1, CI log captures, AI-agent tool harnesses that store
    merged output to a file) ends up with a non-JSON line prepended to otherwise
    pure-JSON stdout, breaking downstream parsers like | jq and
    python3 -c 'json.load(sys.stdin)'. This was the immediate trigger for the
    PR — an agent harness merged streams into a tool-result file, and the next
    step's cat … | jq choked on the leading banner.

Reproducer

$ GOOGLE_WORKSPACE_CLI_LOG=gws=off gws calendar events list \
    --params '{"calendarId":"primary","maxResults":1}' 2>&1 1>/dev/null
Using keyring backend: file        # expected: nothing on stderr
$ gws calendar events list --params '{"calendarId":"primary","maxResults":1}' 2>&1 \
    | python3 -c 'import sys,json; json.load(sys.stdin)'
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Fix

Replace the eprintln! with tracing::info! using the structured-fields style
already used in executor.rs:468-477 (tracing::warn! / tracing::debug! with
field = value, "Message"):

-    // Item 5: log which backend was selected
-    eprintln!("Using keyring backend: {}", backend.as_str());
+    // Item 5: log which backend was selected (audit trail; controlled by GOOGLE_WORKSPACE_CLI_LOG)
+    tracing::info!(backend = backend.as_str(), "Using keyring backend");

Why this is the right shape

  • Preserves maintainer intent. The comment ("Item 5: log which backend was
    selected") indicates the line is intentional audit telemetry. Routing it
    through tracing keeps it audit-grade and adds it to the JSON log file
    pipeline that GOOGLE_WORKSPACE_CLI_LOG_FILE already builds.
  • Backwards compatible. Default tracing subscriber level is INFO, so the
    message remains visible by default. Only users who actively opt out
    (GOOGLE_WORKSPACE_CLI_LOG=gws=warn) see a behavior change — and that change
    is exactly what gws --help already promises.
  • Matches existing crate style. No new imports (the file is consistent with
    fully-qualified tracing::* calls used elsewhere). Structured backend = ...
    field is queryable in JSON logs, mirroring executor.rs.
  • Minimal diff. 2 lines changed, no API changes, no test changes needed.

Verification

  • tracing = "0.1" is already a workspace dep
    (crates/google-workspace-cli/Cargo.toml:64).
  • The macro call shape is identical to existing usages in
    executor.rs:468-477. CI (.github/workflows/ci.yml) will compile-check the
    Rust paths filter on this PR.
  • No new imports required; tracing is invoked fully-qualified, matching the
    file's existing convention.

Happy to amend with additional tests or a release-notes entry if useful.

Made with Cursor

Replace raw eprintln! with tracing::info! so the audit-log line respects
GOOGLE_WORKSPACE_CLI_LOG and reaches the JSON log pipeline configured by
GOOGLE_WORKSPACE_CLI_LOG_FILE.

Before, the line bypassed the tracing infrastructure the crate already
builds, with two consequences:

1. GOOGLE_WORKSPACE_CLI_LOG cannot suppress it. Setting `gws=off`,
   `gws=warn`, or `gws=error` all leave the banner on stderr.
2. Pipelines that merge stdout + stderr (agent tool harnesses, `tee 2>&1`,
   CI log captures) end up with a non-JSON line prepended to otherwise
   pure-JSON stdout, breaking downstream parsers.

The replacement matches the structured-fields style already used in
executor.rs (e.g. tracing::warn! / tracing::debug! with
`field = value, "Message"`). Default tracing level is INFO so the line
remains visible by default; users who want clean output can now set
GOOGLE_WORKSPACE_CLI_LOG=gws=warn as the help text advertises.

Agent: cursor-agent
Model: claude-opus-4-7
Co-Authored-By: Claude <noreply@anthropic.com>
Made-with: Cursor
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 28, 2026

🦋 Changeset detected

Latest commit: eec74d6

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@googleworkspace/cli Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request improves the logging behavior of the credential store by migrating a hardcoded stderr message to the application's structured tracing system. This change ensures that audit telemetry is properly configurable via environment variables and prevents unexpected output from breaking automated pipelines that rely on clean stream processing.

Highlights

  • Logging Infrastructure: Replaced raw eprintln! with tracing::info! to integrate keyring backend selection into the existing tracing ecosystem.
  • Log Suppression: Enables the use of GOOGLE_WORKSPACE_CLI_LOG to suppress the keyring backend banner, resolving issues where it could not be hidden.
  • Pipeline Compatibility: Prevents the keyring banner from polluting stdout/stderr streams, ensuring downstream JSON parsers like jq function correctly.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Generative AI Prohibited Use Policy, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@google-cla
Copy link
Copy Markdown

google-cla Bot commented Apr 28, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request replaces a standard error print statement with structured logging using tracing::info! in the get_or_create_key function. This change allows for better log management and audit trailing, controlled by the GOOGLE_WORKSPACE_CLI_LOG environment variable. I have no feedback to provide.

Agent: cursor-agent
Model: claude-opus-4-7
Co-Authored-By: Claude <noreply@anthropic.com>
Made-with: Cursor
@googleworkspace-bot
Copy link
Copy Markdown
Collaborator

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request migrates the "Using keyring backend" log message from a raw eprintln! to tracing::info!. This change allows the log output to be managed via the GOOGLE_WORKSPACE_CLI_LOG environment variable and ensures it is captured by the configured JSON log pipeline. I have no feedback to provide.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants