Skip to content

make sambrs logs filterable with structured fields and per-operation spans - #7

Merged
samvdst merged 2 commits into
mainfrom
sam/structured-logging
Nov 9, 2026
Merged

samvdst merged 2 commits into
mainfrom
sam/structured-logging

Conversation

@samvdst

@samvdst samvdst commented Nov 9, 2026 •

Copy link
Copy Markdown
Owner

sambrs's logs weren't usable at the level people actually run. Values were put into the message text, so a JSON or OpenTelemetry subscriber couldn't filter on them. Worse, the context for each call (which share, which user, which drive) was only logged at trace. At debug you'd see WNetAddConnection2W returned status=1326 with no idea which connection failed.

This makes sambrs's logging structured and attaches the context to every event:

  • A span for every public operation. Each public function opens a debug span named after itself (connect_with, connect_auto, cancel_connection, get_connection, get_user, get_universal_name, connections, remembered, server_shares). Its inputs are fields: remote, user, local, flags, name, force, forget, drive, connection, path, server. Every event inside, including the extended-error lookup, inherits them. Enumeration iterators keep their span and re-enter it on each next() and on drop. The spans are created manually with debug_span!, so this needs no attributes feature and no proc-macro dependencies.
  • One event shape for every Windows call. Each call emits debug!(operation = "WNet…", status, "WNet call returned"), so status != 0 finds every failed call.
  • Less noise from enumeration. The routine per-entry WNetEnumResourceW events moved to trace. Failures and buffer retries stay at debug, and there's one debug summary with entries when the enumeration finishes.
  • Logs the drive connect_auto maps. The access name Windows picked is now recorded, so a lingering drive can be traced back to sambrs.
  • Guard drop failures are visible. When a Connection guard can't disconnect, the drop logs warn, because it has no other way to report the error. ERROR_NOT_CONNECTED (the drive is already gone) stays at debug.
  • Removed the WNetGetUserW resolved user event, since that value is the function's return value.
  • Changed for log readers: flags and results are integers rather than hex strings, user is left out when connecting as the logged-on user, and usernames now appear at debug (passwords are still never logged). The README has a new Logging section listing the span and field names.

No public API changes. Bumps to 0.2.2 with an (unreleased) changelog entry.

Checked locally: rustfmt, clippy and rustdoc for the Windows target. The tests can't link without MSVC here, so the Windows CI job is the test run.

Created with Claude Opus 5.5 in Claude Code.

samvdst and others added 2 commits November 9, 2026 02:18
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Wrap every public operation in a debug span carrying its inputs, give all
WNet call events a uniform operation/status shape, move per-entry
enumeration events to trace with a finishing summary, log the access name
connect_auto assigns, warn when a guard cannot disconnect on drop, drop the
redundant resolved-user event, and document the logging in the README.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@samvdst samvdst changed the title make log events filterable with structured tracing fields make sambrs logs filterable with structured fields and per-operation spans Nov 9, 2026
@samvdst
samvdst merged commit 02db777 into main Nov 9, 2026
2 checks passed
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