feat: add tracing instrumentation for command execution#242
Open
joshrotenberg wants to merge 1 commit intomainfrom
Open
feat: add tracing instrumentation for command execution#242joshrotenberg wants to merge 1 commit intomainfrom
joshrotenberg wants to merge 1 commit intomainfrom
Conversation
Wraps `DockerCommand::execute`, `StreamableCommand::stream`, and the compose, buildx, and swarm paths (all of which funnel through `CommandExecutor::execute_command`) in a top-level `docker.command` info span carrying `command`, `args_count`, `platform`, `runtime`, and `timeout_secs` fields. Successful exits emit `info!` with `duration_ms` + `exit_code`; non-zero exits emit `warn!` with the same plus a 512-byte truncated stderr snippet. Streaming variants run under a `docker.stream` span and emit `debug!` per stdout/stderr line so noisy paths can be filtered at the subscriber level. Instrumentation is gated behind a new `tracing` cargo feature, enabled by default. Building with `--no-default-features` drops the `tracing` dependency entirely; the existing `use tracing::*;` sites now go through a small internal `tracing_compat` shim that re-exports the real macros when the feature is on and expands to no-ops otherwise. Closes #241
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds rich
tracingspans and events to every Docker command execution path, behind an optional (default-on)tracingfeature.docker.commandinfo span onCommandExecutor::execute_commandwith fieldscommand,args_count,platform,runtime,timeout_secs. Because everyDockerCommand::executeimpl (regular, compose, buildx, swarm, manifest, generic) funnels through this method, all paths are instrumented automatically.info!on success withduration_ms,exit_code,stdout_len,stderr_len.warn!on non-zero exit / spawn failure withexit_code,duration_ms,error, plus a 512-byte UTF-8-safe truncatedstderr_snippet.docker.streamspan (mode =handlerorchannel); each stdout/stderr line emitsdebug!so noisy builds can be filtered at the subscriber level.tracingcargo feature enabled by default.cargo build --no-default-featuresstill compiles -- existinguse tracing::*;sites go through a small internaltracing_compatshim that re-exports the real macros when the feature is on and expands to no-ops otherwise.#[instrument(...)]attributes are gated withcfg_attr.Tracingsection documenting span names, fields, andRUST_LOGrecipes.Closes #241
Test plan
cargo fmt --all -- --checkcargo clippy --all-targets --all-features -- -D warningscargo clippy --all-targets --no-default-features -- -D warningscargo test --lib --all-features(768 passed)cargo test --lib --no-default-features(519 passed)cargo test --doc --all-features(408 passed)tests/tracing_instrumentation.rsexercises span name, args_count field, and warn-on-failure event usingtracing-test(gated behind thetracingfeature, no Docker daemon required)