Skip to content

feat(middleware): migrate lib-commons from v3 to v4#78

Merged
fredcamaral merged 3 commits intodevelopfrom
feat/migrate-libcommons-v4
Mar 10, 2026
Merged

feat(middleware): migrate lib-commons from v3 to v4#78
fredcamaral merged 3 commits intodevelopfrom
feat/migrate-libcommons-v4

Conversation

@fredcamaral
Copy link
Member

@fredcamaral fredcamaral commented Mar 10, 2026

Summary

  • Upgrades lib-commons from v3.0.0-beta.8 to the stable v4.0.0 release
  • Adapts all middleware call sites to the breaking API changes introduced in v4
  • Updates transitive dependencies: OTel 1.40.0 → 1.42.0, gRPC 1.79.1 → 1.79.2

Changes

chore(deps) — go.mod / go.sum

  • Replace lib-commons/v3 with lib-commons/v4 v4.0.0
  • Remove Masterminds/squirrel and lann/* (no longer indirect deps)
  • Add new v4 transitives: go-playground/validator, shopspring/decimal, gabriel-vasile/mimetype, golang.org/x/crypto

feat(middleware) — middleware.go / middlewareGRPC.go / middleware_test.go

  • Span args: pointer → value (HandleSpanError, SetSpanAttributesFromValue)
  • ExtractHTTPContext and InjectHTTPContext signatures reversed (ctx first)
  • SetSpanAttributesFromStructSetSpanAttributesFromValue
  • NoneLoggerlog.NewNop()
  • Added logErrorf / logInfof helpers for nil-safe logger calls
  • Added initializeDefaultLogger to replace zap.InitializeLoggerWithError()
  • Updated testLogger stub to implement the new v4 log.Logger interface

Test plan

  • go build ./... passes with lib-commons v4
  • go test ./auth/middleware/... passes
  • Verify OTel spans and logger output still work end-to-end in a consuming service

Replace lib-commons/v3 with v4.0.0 stable release. Updates transitive dependencies including OTel from 1.40.0 to 1.42.0, grpc from 1.79.1 to 1.79.2, and adds new transitive deps required by v4 (go-playground/validator, shopspring/decimal, gabriel-vasile/mimetype). Removes Masterminds/squirrel and lann/* which are no longer indirect requirements.

X-Lerian-Ref: 0x1
Adapt all middleware call sites to the breaking changes introduced in lib-commons v4:

- opentelemetry: span args changed from pointer to value (HandleSpanError, SetSpanAttributesFromValue)
- opentelemetry: ExtractHTTPContext and InjectHTTPContext signatures reversed (ctx first)
- SetSpanAttributesFromStruct replaced by SetSpanAttributesFromValue
- NoneLogger replaced by log.NewNop()
- Add logErrorf/logInfof helpers for nil-safe logger calls
- Add initializeDefaultLogger to replace zap.InitializeLoggerWithError()
- Update testLogger to implement the new v4 log.Logger interface (Log/With/WithGroup/Enabled/Sync)

X-Lerian-Ref: 0x1
@coderabbitai
Copy link

coderabbitai bot commented Mar 10, 2026

Walkthrough

This pull request updates the middleware package to use lib-commons v4 and upgrades several module dependencies (Go 1.25.7, OpenTelemetry v1.42.0, gRPC v1.79.2, and others). It adds logging helpers (logErrorf, logInfof) and initializeDefaultLogger to centralize logger creation and usage, replaces direct logger calls with the new helpers, and adjusts HTTP context/tracing helpers. gRPC telemetry calls were updated (span error handling and attribute setting). Tests were updated to implement the v4 logging interface. No exported APIs were changed.

🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The PR title accurately reflects the primary change: migrating lib-commons from v3 to v4 across all middleware files and dependencies.
Description check ✅ Passed The pull request description comprehensively covers the purpose, changes, and test plan, matching the repository template requirements.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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

Copy link

@gandalf-at-lerian gandalf-at-lerian left a comment

Choose a reason for hiding this comment

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

LGTM ✅

Reviewed the migration — clean and well-structured:

Import paths: v2 → v4 correctly updated across all files.

Breaking API adaptations:

  • HandleSpanError / SetSpanAttributesFromValue: pointer → value — ✅
  • NewTrackingFromContext replacing separate NewTracerFromContext + NewHeaderIDFromContext — ✅
  • Logger: zap.InitializeLogger()zap.New(zap.Config{}) with proper error handling + fallback to log.NewNop() — ✅
  • logErrorf / logInfof nil-safe helpers — good defensive pattern

New additions:

  • NewGRPCAuthStreamPolicy + wrappedServerStream — mirrors the unary interceptor, MT tenant claim propagation via metadata. Clean.
  • extractTenantClaims using ParseUnverified — makes sense for internal service-to-service propagation where the token was already validated upstream.

Tests: 436 lines of new tests covering subject construction, missing claims, server failures, invalid JSON, invalid tokens. Good coverage.

One minor note (non-blocking): the initializeDefaultLogger reads ENV_NAME and OTEL_LIBRARY_NAME from env vars directly. Works fine for now, but if lib-auth ever needs to support multiple instances with different configs in the same process, this would need to become configurable. Not a concern today.

Copy link

@coderabbitai coderabbitai bot left a comment

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 the current code and only fix it if needed.

Inline comments:
In `@auth/middleware/middleware.go`:
- Around line 110-115: When initializeDefaultLogger() returns an error, the code
assigns l = log.NewNop() then calls logErrorf with that Nop logger so the
failure is never emitted; instead, emit the error to a real sink (e.g., standard
library log to stderr or a temporary logger) before replacing l with
log.NewNop(). Concretely: capture err from initializeDefaultLogger(), call the
standard library log.Printf or another concrete logger to report "failed to
initialize logger, using NopLogger: %v" including err, and only after that
assign l = log.NewNop() and continue using l and logErrorf as needed. Ensure you
reference initializeDefaultLogger, l, log.NewNop, and logErrorf when making the
change.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 9402ab0e-3059-483a-bfee-54fa76e5b085

📥 Commits

Reviewing files that changed from the base of the PR and between 5b60e5f and 2e12d9b.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (4)
  • auth/middleware/middleware.go
  • auth/middleware/middlewareGRPC.go
  • auth/middleware/middleware_test.go
  • go.mod

If the default logger initialization fails, the previous code attempts
to log this error using the uninitialized logger instance itself. This
causes a nil pointer dereference and panics the application.

This commit replaces the faulty call with `stdlog.Printf`. Using the
standard library logger ensures the initialization error is reported
safely without crashing. The application then gracefully falls back
to using a no-op logger.
@fredcamaral fredcamaral merged commit edb0fec into develop Mar 10, 2026
9 checks passed
@fredcamaral fredcamaral deleted the feat/migrate-libcommons-v4 branch March 10, 2026 19:37
@lerian-studio-midaz-push-bot
Copy link

🎉 This PR is included in version 2.5.0-beta.7 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@lerian-studio-midaz-push-bot
Copy link

🎉 This PR is included in version 2.5.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants