Skip to content

Two UDP core DEBUG lines record the log target as a field instead of setting it #3060

Description

@josecelano-bot

Related to #2387

Goal

The two DEBUG lines that announce the UDP core statistics events (UdpAnnounce, UdpScrape) are logged under the UDP TRACKER log target, like every other UDP core log line, so per-target log filtering and the target of structured logs are correct.

Background

Found while working on #3031 (EPIC #2387); it was not part of that issue.

What happens, step by step. packages/udp-core/src/services/announce.rs:178 and packages/udp-core/src/services/scrape.rs:140 are written as:

tracing::debug!(target = crate::UDP_TRACKER_LOG_TARGET, "Sending UdpAnnounce event: {event:?}");

In tracing, target = value (an equals sign) is an ordinary field named target; the log target is set only with target: value (a colon). So:

  1. send_event publishes a statistics event and logs the DEBUG line.
  2. tracing records the target as the default, the module path (torrust_tracker_udp_core::services::announce).
  3. The intended value UDP TRACKER is recorded as a stray field target="UDP TRACKER" at the end of the line.

Expectation violated. Every other call site in the repository sets the target with the colon form: 111 call sites use target: ..._LOG_TARGET, including the other UDP_TRACKER_LOG_TARGET users in packages/udp-core (banning.rs, statistics/event/listener.rs). The constant is exported precisely so UDP core lines share one target.

Impact. Only DEBUG output is affected, and nothing is functionally wrong. A consumer that selects log lines by target (a grep for UDP TRACKER, the target key of the JSON log style, a log shipper's filter) misses these two lines, and for the JSON style the record carries a wrong target plus a stray target field. The EPIC #2387 logging conventions rely on named targets.

Verified scope (2026-11-25, torrust/develop at the merge of #3053). git grep -nE '\(\s*target\s*=' -- '*.rs' and a multi-line variant find exactly these two sites; no other tracing macro, span! or event! in packages or src has the mistake. The grep is the check for AC3.

Scope

In Scope

  • Change the two call sites to target: crate::UDP_TRACKER_LOG_TARGET.
  • Two maintained regression tests (announce and scrape) asserting the captured line carries the UDP TRACKER target.
  • A guard against the mistake coming back (see Design Decision).

Out of Scope

Design Decision

The fix is the two-character change from = to :. Whether to also add a lint to catch the mistake is open for the maintainer: clippy does not flag it (the macro accepts the field form as valid). Proposed default: no new lint; the two regression tests and the git grep in AC3 are enough for two sites. A repository-wide guard (for example a git grep step in linter) can be a separate issue if wanted.

Architectural Decisions

Design and Ownership Review

Not applicable.

Bug-Fix Process

Follows .claude/skills/fix-bug/SKILL.md:

  • Analysis: the field-versus-target macro syntax in the two call sites (above).
  • Reproduction: V1, done on 2026-11-25: a temporary test captured the real DEBUG line of both services. Outcome: Reproduced.
  • Regression-test boundary: see below.
  • Red test: recorded before the fix.
  • Fix: = to : at both sites.
  • Green and recheck: regression tests green, then V1 rerun after the last production change.

Regression Test Strategy

  • Boundary: a unit test in each of announce.rs and scrape.rs (the existing #[cfg(test)] modules, next to it_should_publish_..._event). It builds the service with a mock event sender, calls handle_announce / handle_scrape inside torrust_tracker_test_helpers::logging::capture_logs_while (the scoped, thread-local capture helper added by Bug: statistics listeners log a WARN for every event when usage statistics are disabled #3031; the handoff called it capture_logs_in_scope, on develop it is capture_logs_while), on a current_thread runtime because the subscriber is thread-local, and asserts the captured line contains UDP TRACKER: Sending UdpAnnounce event (resp. UdpScrape) and does not contain the module-path prefix. The fmt subscriber prints <target>: <message>, so the assertion is on the target itself.
  • Why this boundary: it is the smallest deterministic test that exercises the causal macro call; the symptom is only visible in the emitted record.
  • Evidence: red and green output in manual-verification-evidence.md.

Implementation Plan

Status values: TODO, IN_PROGRESS, BLOCKED, DONE.

ID Status Task Notes / Expected Output
T1 DONE Reproduce on both services and record it V1 recorded in manual-verification-evidence.md
T2 TODO Add the announce and scrape regression tests and observe them red Red run recorded on the unfixed code, both tests failing
T3 TODO Change = to : at both call sites Regression tests green
T4 TODO Rerun V1 after the last production change; run linter all Evidence names the commit by Conventional Commit subject

Commit Points

Task Coherent change set Commit policy
T2 The two regression tests plus their red evidence Commit after focused validation and required review.
T3 The two-site production fix Commit after focused validation and required review.
T4 Final evidence and spec progress Commit after focused validation and required review.

Record a justified no-change decision in the task's evidence without creating an empty commit. For test-producing work, use the write-unit-test skill and complete an explicit design review after each passing test increment, before maintainer review and commit, using the mandatory prose-first Arrange-Act-Assert comparison. Use a Conventional Commit message with the narrow affected scope, and sign every commit with GPG.

Activity

  1. self-assigned this
    on Nov 25, 2026
  2. added theissue type on Nov 25, 2026
  3. added 13 commits that reference this issue on Nov 25, 2026
  4. 7 remaining items

  5. added 8 commits that reference this issue on Nov 26, 2026
  6. added 3 commits that reference this issue on Nov 26, 2026
  7. added a commit that references this issue on Nov 26, 2026
  8. added 2 commits that reference this issue on Nov 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions