Skip to content

Fix: Telemetry INFO logging to print only once per process#6083

Open
rsareddy0329 wants to merge 6 commits into
aws:masterfrom
rsareddy0329:master-mtrl-vpc-cmk-support
Open

Fix: Telemetry INFO logging to print only once per process#6083
rsareddy0329 wants to merge 6 commits into
aws:masterfrom
rsareddy0329:master-mtrl-vpc-cmk-support

Conversation

@rsareddy0329

Copy link
Copy Markdown
Contributor

Issue #, if available:

Description of changes:

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

jam-jee added a commit that referenced this pull request Jul 23, 2026
The review job runs under pull_request_target (trusted context with the
Bedrock role + secrets). It was checking out the fork's head SHA, which
actions/checkout now refuses ('pwn request' guard) — so the workflow failed on
every fork PR (~90% of PRs), e.g. run 29965762436 on #6083.

Rework to the safe diff-only pattern (mirrors aws/*-agentcore pr-security-review):
- Check out the BASE repo, never fork head code — untrusted PR code is never
  executed in the privileged job.
- Fetch the PR diff via the API into /tmp/pr.diff as read-only ground truth.
- Remove Bash from allowedTools; Claude reads the diff + uses Read/Grep/Glob
  against the trusted base tree for context. Skip cleanly on empty diffs.

Does NOT use allow-unsafe-pr-checkout, which would expose secrets to fork code.
@github-actions

github-actions Bot commented Jul 23, 2026

Copy link
Copy Markdown

Claude finished @rsareddy0329's task in 59s —— View job


Code Review — Telemetry INFO logging once per process

  • Read PR diff and changed files
  • Analyze correctness, tests, and behavior changes
  • Post review

The change is small, correct, and well-targeted. Moving the logger.info(TELEMETRY_OPT_OUT_MESSAGING) call behind a module-level _telemetry_msg_shown guard achieves the stated goal — the opt-out message prints at most once per process instead of on every decorated call.

Things I like

  • The message is now also gated on not telemetry_opt_out_flag, so users who have already opted out no longer get told how to opt out. That's a sensible improvement over the previous unconditional log, though it's a real behavior change worth being aware of (opted-out users will no longer see the notice at all).
  • Tests cover both the "shown exactly once across multiple calls" and "not shown when opted out" paths, and correctly reset the module global before/after to avoid cross-test leakage.

Minor considerations (non-blocking)

  1. Thread-safety of the check-then-set (telemetry_logging.py:303-305). The if not _telemetry_msg_shown: ... _telemetry_msg_shown = True sequence is not atomic. In a multi-threaded process where several threads hit a decorated call concurrently before the flag is set, the message could print more than once. For a one-time INFO notice this is low-stakes and I wouldn't block on it, but it's worth a mention.

  2. Test isolation depends on global reset. Because _telemetry_msg_shown is module-level state, the new tests rely on manually resetting it. Existing tests that call mock_create_model() with opt-out False will flip the flag to True as a side effect. The new tests handle this by resetting at the start, so ordering is safe today — just noting the shared mutable global is a mild fragility if more tests are added later. A setUp/tearDown reset (or a fixture) would make this robust regardless of test order.

Neither point is a blocker. The core fix is correct and the tests validate the intended behavior. LGTM. 👍

@github-actions

github-actions Bot commented Jul 23, 2026

Copy link
Copy Markdown

Claude finished @rsareddy0329's task in 1m 38s —— View job


Code Review — Telemetry opt-out message once per process

  • Read PR diff and changed files
  • Analyze correctness, tests, and behavior changes
  • Post review

The core idea — gating TELEMETRY_OPT_OUT_MESSAGING behind a module-level _telemetry_msg_shown flag so it prints at most once per process, and not at all for opted-out users — is sound. However, this revision introduced a test/implementation mismatch that will make the new test fail, plus a behavior change worth calling out.

🔴 Blocking: new test asserts on the wrong logger method

The implementation now emits the message via logger.warning (telemetry_logging.py:304):

if not telemetry_opt_out_flag and not _telemetry_msg_shown:
    logger.warning(TELEMETRY_OPT_OUT_MESSAGING)
    _telemetry_msg_shown = True

But test_telemetry_opt_out_message_shown_only_once patches and asserts against logger.info (test_telemetry_logging.py:657-666):

with patch.object(telemetry_module.logger, "info") as mock_logger_info:
    mock_local_client.mock_create_model()
    ...
    info_calls = [call for call in mock_logger_info.call_args_list
                  if "telemetry" in str(call).lower() and "opt out" in str(call).lower()]
    self.assertEqual(len(info_calls), 1, ...)  # will get 0, not 1

Since the message no longer goes through logger.info, mock_logger_info captures zero matching calls, so assertEqual(len(info_calls), 1) fails. The message-text filter ("opt out") also won't match — TELEMETRY_OPT_OUT_MESSAGING uses "opt out of telemetry", so "telemetry" and "opt out" happens to match by coincidence, but the assertion still fails on count.

Note the sibling test test_telemetry_opt_out_message_not_shown_when_opted_out passes only vacuously — it patches logger.info and asserts len == 0, which is trivially true now that nothing is logged via info. It doesn't actually verify the opted-out path.

Fix: patch logger.warning in both tests (or revert the log level back to info to match the PR's stated intent — see below).

🟡 Behavior change: INFO → WARNING

The PR title says "INFO logging," but the level was changed to WARNING. A routine telemetry opt-out notice at WARNING level is fairly loud — it will surface in setups that filter to WARNING+ and may read as something being wrong. If the intent is just an informational notice, logger.info is more appropriate. If WARNING is deliberate, please update the PR title/description to reflect it.

🟢 Minor (non-blocking)

  • Thread-safety: the check-then-set on _telemetry_msg_shown (lines 303–305) isn't atomic, so under concurrent first calls the message could print more than once. Low-stakes for a one-time notice; not worth a lock.
  • Shared global in tests: both tests reset _telemetry_msg_shown manually before/after. A setUp/tearDown (or fixture) reset would make this robust regardless of test ordering as more tests are added.

Summary: fix the logger.infologger.warning mismatch in the tests (and confirm the intended log level) before merging. The rest is optional polish.

Note: the inline-comment tool wasn't available in this environment, so findings are consolidated here with file/line references.


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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant