Skip to content

feat(log): add zap.Slog accessor for slog-compatible consumers#34

Merged
rodrigodh merged 2 commits into
mainfrom
hotfix/observability-slog-accessor
Jul 22, 2026
Merged

feat(log): add zap.Slog accessor for slog-compatible consumers#34
rodrigodh merged 2 commits into
mainfrom
hotfix/observability-slog-accessor

Conversation

@rodrigodh

Copy link
Copy Markdown
Contributor

Description

Adds zap.Slog(log.Logger) *slog.Logger — a bridge from the zap-backed logger to a stdlib *slog.Logger, via go.uber.org/zap/exp/zapslog.

Why: lib-service-discovery#24 decoupled that library's public logging API from lib-observability — it now accepts a version-agnostic, slog-shaped libsd.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's pkg/observability/service_discovery_logger.go). With this accessor they just call:

libsd.WithLogger(czap.Slog(logger))

…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: adds go.uber.org/zap/exp dependency

Breaking Changes

None. The log.Logger interface is unchanged — Slog is a free function in the zap package, so no existing implementer (including external test fakes/mocks) breaks. This is a minor bump, not a major.

Testing

  • go build ./...
  • go vet ./... clean
  • go test -tags=unit ./... — 846 passing
  • golangci-lint run ./zap/... — 0 issues
  • New zap/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.
  • Validated end-to-end against plugin-access-manager (local replace): dropping the shim for czap.Slog(logger) compiles and the discovery functional test passes through libsd.WithLogger.

Related

X-Lerian-Ref: 0x1

@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 5780e011-bfaf-4dcc-b3a6-c87f8d46f078

📥 Commits

Reviewing files that changed from the base of the PR and between d2c67b3 and bb98495.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (3)
  • go.mod
  • zap/slog.go
  • zap/slog_test.go

📝 Walkthrough

Walkthrough

Adds Slog, adapting logpkg.Logger to *slog.Logger. Concrete zap loggers reuse their zap core, while other and nil inputs use a discarding handler. Tests cover output propagation and safe fallback behavior; module dependencies are updated.

Changes

Slog adapter

Layer / File(s) Summary
Slog adapter implementation
go.mod, zap/slog.go
Updates the zap and gRPC dependencies and implements Slog with shared zap-core output or an io.Discard fallback.
Adapter behavior tests
zap/slog_test.go
Tests zap output fields, non-zap logger fallback behavior, and nil concrete logger safety.

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
Loading

Possibly related PRs

✨ Finishing Touches
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch hotfix/observability-slog-accessor

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.mod

Traceback (most recent call last):
File "/usr/local/bin/checkov", line 2, in
from checkov.main import Checkov
ModuleNotFoundError: No module named 'checkov'


Comment @coderabbitai help to get the list of available commands.

@lerian-studio lerian-studio added tests Unit, integration and end-to-end tests zap Zap logger integration deps Go module dependencies (usually opened by Dependabot) labels Jul 22, 2026
@lerian-studio

lerian-studio commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

🔍 PR Validation Summary

✅ PR Mergeable — no blocking failures

Check Status Blocking
Source Branch ✅ success yes
PR Title ✅ success yes
PR Description ✅ success yes
PR Size ✅ success no
Auto Labels ✅ success no
PR Metadata ✅ success no

🔍 View workflow run

@lerian-studio

lerian-studio commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

🔒 Security Scan Results — lib-observability

✅ PR Mergeable — no blocking findings

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.


🔍 View full scan logs

@lerian-studio

Copy link
Copy Markdown
Contributor

📊 Unit Test Coverage Report: lib-observability

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 9fe105a and 382143c.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (3)
  • go.mod
  • zap/slog.go
  • zap/slog_test.go

Comment thread go.mod Outdated
@rodrigodh
rodrigodh force-pushed the hotfix/observability-slog-accessor branch from 382143c to d2c67b3 Compare July 22, 2026 19:51
coderabbitai[bot]
coderabbitai Bot previously approved these changes Jul 22, 2026
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
@rodrigodh
rodrigodh merged commit ce81aa9 into main Jul 22, 2026
21 checks passed
@fredcamaral
fredcamaral deleted the hotfix/observability-slog-accessor branch July 22, 2026 20:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

deps Go module dependencies (usually opened by Dependabot) size/S PR changes 50–199 lines tests Unit, integration and end-to-end tests zap Zap logger integration

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants