feat(log): add zap.Slog accessor for slog-compatible consumers#34
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (3)
📝 WalkthroughWalkthroughAdds ChangesSlog adapter
Sequence Diagram(s)sequenceDiagram
participant Caller
participant Slog
participant ZapCore
Caller->>Slog: Convert logpkg.Logger
Slog->>ZapCore: Reuse concrete Logger core
ZapCore-->>Caller: Emit slog entry
Possibly related PRs
✨ Finishing Touches✨ Simplify code
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 Checkov (3.3.8)go.modTraceback (most recent call last): Comment |
🔍 PR Validation Summary✅ PR Mergeable — no blocking failures
|
🔒 Security Scan Results —
|
| Stage | Status | Blocking? |
|---|---|---|
| Filesystem Scan | ✅ Clean | — |
| Docker Image Scan | ➖ Skipped | — |
| Docker Hub Health Score | ➖ Skipped | — |
| Pre-release Version Check | ✅ Clean | — |
Trivy
Filesystem Scan
✅ No vulnerabilities or secrets found.
Pre-release Version Check
✅ No unstable version pins found.
📊 Unit Test Coverage Report:
|
| Metric | Value |
|---|---|
| Overall Coverage | 85.7% ✅ PASS |
| Threshold | 80% |
Coverage by Package
| Package | Coverage |
|---|---|
github.com/LerianStudio/lib-observability/v2/assert |
97.9% |
github.com/LerianStudio/lib-observability/v2/constants |
83.3% |
github.com/LerianStudio/lib-observability/v2/log |
94.9% |
github.com/LerianStudio/lib-observability/v2/metrics |
91.4% |
github.com/LerianStudio/lib-observability/v2/middleware |
76.9% |
github.com/LerianStudio/lib-observability/v2/redaction |
95.8% |
github.com/LerianStudio/lib-observability/v2/runtime |
80.4% |
github.com/LerianStudio/lib-observability/v2/tracing |
84.8% |
github.com/LerianStudio/lib-observability/v2/zap |
96.1% |
github.com/LerianStudio/lib-observability/v2 |
91.5% |
Generated by Go PR Analysis workflow
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@go.mod`:
- Line 53: Move go.uber.org/zap/exp v0.3.0 from the indirect dependency block
into the direct require block and remove the // indirect annotation, preserving
the existing version.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 8505b1ea-92ee-4f1e-8d12-73f2a93dc016
⛔ Files ignored due to path filters (1)
go.sumis excluded by!**/*.sum
📒 Files selected for processing (3)
go.modzap/slog.gozap/slog_test.go
382143c to
d2c67b3
Compare
Adds zap.Slog(log.Logger) *slog.Logger, bridging the zap-backed logger to a stdlib *slog.Logger via zap/exp/zapslog. Consumers that must hand an slog-shaped logger to a third party — e.g. lib-service-discovery's libsd.WithLogger, whose public API was decoupled from lib-observability in lib-service-discovery#24 — can now pass zap.Slog(logger) instead of hand-rolling a per-service adapter, while keeping output flowing through the same zap core. Non-zap loggers (the nop logger, gomock doubles) fall back to a discarding handler rather than panicking. Purely additive: the log.Logger interface is unchanged, so no existing implementer breaks and no major bump is required. Pulls in go.uber.org/zap/exp. X-Lerian-Ref: 0x1
Clears GHSA-hrxh-6v49-42gf (HIGH — gRPC-Go xDS RBAC and HTTP/2 vulnerabilities), flagged by the Trivy fs scan gate. The vulnerable v1.81.1 is a pre-existing direct dependency (used by middleware/), not introduced here; v1.82.1 is the fixed release. Build and full unit suite pass unchanged. X-Lerian-Ref: 0x1
d2c67b3 to
bb98495
Compare
Description
Adds
zap.Slog(log.Logger) *slog.Logger— a bridge from the zap-backed logger to a stdlib*slog.Logger, viago.uber.org/zap/exp/zapslog.Why:
lib-service-discovery#24decoupled that library's public logging API from lib-observability — it now accepts a version-agnostic, slog-shapedlibsd.Logger. Consumers on lib-observability (which is field-shaped,Log(ctx, level, msg, ...Field)) currently hand-roll a per-service adapter to satisfy that interface (e.g. plugin-access-manager'spkg/observability/service_discovery_logger.go). With this accessor they just call:…and the per-service shim disappears, while discovery logs keep flowing through the same zap core (unified output, not a parallel slog sink).
Non-zap implementations (the nop logger, gomock doubles) fall back to a discarding handler rather than panicking, mirroring the "unknown logger is silent" posture elsewhere.
Type of Change
feat: New feature or capability (additive)build: addsgo.uber.org/zap/expdependencyBreaking Changes
None. The
log.Loggerinterface is unchanged —Slogis a free function in thezappackage, so no existing implementer (including external test fakes/mocks) breaks. This is a minor bump, not a major.Testing
go build ./...go vet ./...cleango test -tags=unit ./...— 846 passinggolangci-lint run ./zap/...— 0 issueszap/slog_test.go: asserts a zap-backed logger writes through the shared core (message, level, and field observed), plus nop/nil fallbacks don't panic.replace): dropping the shim forczap.Slog(logger)compiles and the discovery functional test passes throughlibsd.WithLogger.Related
X-Lerian-Ref: 0x1