Skip to content

Conversation

@cnuss
Copy link

@cnuss cnuss commented Jan 8, 2026

Summary

This PR adds comprehensive HTTP debug logging for Docker API calls to aid in troubleshooting and debugging issues with the Docker client integration.

Changes

  • Debug Transport Layer: Implemented a new HTTP transport wrapper (wrappedTransport) that intercepts Docker API requests and responses
  • Configurable Logging Levels:
    • Info level (default): Standard logging, no Docker API call details
    • Debug level: Logs request method, endpoint, and response status
    • Trace level: Additionally logs full request and response bodies for detailed inspection
  • Modified getDockerClient: Updated to automatically apply the debug transport when log level is set to debug or higher
  • Updated CLI Help: Enhanced --log-level flag description to list all available log levels (panic, fatal, error, warn, info, debug, trace) and indicate that 'debug' and 'trace' levels enable Docker API logging
  • Comprehensive Test Coverage: Added extensive unit tests and integration tests for the new debug functionality

Example Output

Info Level (default)

INFO[0000] Starting cri-dockerd 0.3.0
INFO[0000] Connecting to docker on the Endpoint unix:///var/run/docker.sock

Debug Level

INFO[0000] Starting cri-dockerd 0.3.0
INFO[0000] Connecting to docker on the Endpoint unix:///var/run/docker.sock
DEBU[0001] (dockerapi) GET unix:///var/run/docker.sock/v1.43/version => 200 OK
DEBU[0001] (dockerapi) GET unix:///var/run/docker.sock/v1.43/info => 200 OK
DEBU[0002] (dockerapi) POST unix:///var/run/docker.sock/v1.43/containers/create => 201 Created
DEBU[0002] (dockerapi) POST unix:///var/run/docker.sock/v1.43/containers/abc123/start => 204 No Content

Trace Level

INFO[0000] Starting cri-dockerd 0.3.0
INFO[0000] Connecting to docker on the Endpoint unix:///var/run/docker.sock
TRAC[0001] (dockerapi) GET unix:///var/run/docker.sock/v1.43/version: (empty) => 200 OK {"Version":"24.0.7","ApiVersion":"1.43","MinAPIVersion":"1.12","GitCommit":"afdd53b"}
TRAC[0001] (dockerapi) GET unix:///var/run/docker.sock/v1.43/info: (empty) => 200 OK {"ID":"ABCD:1234","Containers":5,"Images":12,...}
TRAC[0002] (dockerapi) POST unix:///var/run/docker.sock/v1.43/containers/create: {"Image":"nginx","HostConfig":{"NetworkMode":"bridge"}} => 201 Created {"Id":"abc123def456","Warnings":[]}
TRAC[0002] (dockerapi) POST unix:///var/run/docker.sock/v1.43/containers/abc123/start: (empty) => 204 No Content (empty)

Files Changed

  • cmd/server.go: Updated --log-level flag help text to document available levels and Docker API logging behavior
  • libdocker/client.go: Modified to conditionally apply debug transport based on log level
  • libdocker/debug.go: New file implementing the HTTP debug transport wrapper
  • libdocker/debug_test.go: Comprehensive tests for debug transport functionality
  • libdocker/client_test.go: Tests for getDockerClient with debug transport integration

Benefits

  • Enables visibility into Docker API interactions without modifying application code
  • Helps diagnose issues with container runtime operations
  • Clear documentation in CLI help about available log levels and their effects
  • Progressive detail: debug for high-level flow, trace for deep inspection
  • Minimal performance overhead (only active when debug logging is enabled)
  • No impact on production deployments (disabled by default)

Fixes #532


🤖 Generated with Claude Code

@cnuss
Copy link
Author

cnuss commented Jan 13, 2026

@athongsamai @awmirantis @smerkviladze could you take a look at this or assign some reviewers that could?

thanks!

@cnuss
Copy link
Author

cnuss commented Jan 18, 2026

@chenyaooo i saw you recently dropped an update for this repo, could you 👀 this PR or ping someone who's able to?

thanks!

@cnuss
Copy link
Author

cnuss commented Jan 27, 2026

@athongsamai @awmirantis @smerkviladze @chenyaooo any of you there?

@athongsamai
Copy link
Contributor

@cnuss thanks for opening this PR.
Meanwhile we review your code change, could you make your commits the signed ones?
Refer to https://docs.github.com/en/authentication/managing-commit-signature-verification/signing-commits.
The unsigned commit will not be accepted for merging.

@cnuss
Copy link
Author

cnuss commented Jan 28, 2026

@athongsamai done! sorry i thought i had that turned on

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.

Debug Logging for API Requests to Docker Daemon

2 participants