Skip to content

refactor(middleware): migrate observability to lib-observability + 2.8.0-beta.1#99

Merged
fredcamaral merged 9 commits into
mainfrom
develop
May 18, 2026
Merged

refactor(middleware): migrate observability to lib-observability + 2.8.0-beta.1#99
fredcamaral merged 9 commits into
mainfrom
develop

Conversation

@fredcamaral

Copy link
Copy Markdown
Member

Summary

  • Migrates auth/middleware observability from in-tree wiring to the shared lib-observability package (HTTP + gRPC middlewares).
  • Bumps version to 2.8.0-beta.1 (CHANGELOG updated).
  • Refreshes go.mod / go.sum to align with the new dependency surface.

Test plan

  • CI: go build ./... green
  • CI: go test ./... green (including auth/middleware/middleware_test.go)
  • Downstream consumer smoke-test against 2.8.0-beta.1 tag before promoting to stable
  • Confirm traces/metrics emitted by the new middleware match the prior shape (no regression in span names or attribute keys)

fredcamaral and others added 2 commits May 18, 2026 16:56
Replace logging and tracing imports from lib-commons with the dedicated
lib-observability module in auth middlewares. This decouples the
observability responsibilities from the general commons library to
improve modularity and maintainability. Update Go version to 1.26.3 and
upgrade dependencies, including grpc, opentelemetry, and lib-commons,
to support the migration and keep the modules up to date.
## [2.8.0-beta.1](v2.7.0...v2.8.0-beta.1) (2026-05-18)
@coderabbitai

coderabbitai Bot commented May 18, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 43379f89-4aa6-42fb-99fe-d5d8a02f5d0e

📥 Commits

Reviewing files that changed from the base of the PR and between e1a25d9 and 89440c1.

📒 Files selected for processing (1)
  • auth/middleware/middleware_test.go

Walkthrough

This PR migrates observability instrumentation from lib-commons' OpenTelemetry helpers to lib-observability's tracing API across HTTP and gRPC middleware, updates test imports, bumps Go and selected dependencies, adjusts CI to Go 1.26 and gosec installation, and prepends a 2.8.0-beta.4 entry to CHANGELOG.md.

Changes

Observability Library Migration

Layer / File(s) Summary
HTTP middleware observability migration
auth/middleware/middleware.go
Import plumbing updated to lib-observability. In Authorize, checkAuthorization, and GetApplicationToken: context extraction, tracking/tracer creation, span error handling, span attribute setting (using a tracePayload that omits clientSecret), and HTTP header context injection migrated from opentelemetry.* to tracing.* equivalents.
gRPC middleware observability migration
auth/middleware/middlewareGRPC.go
Unary interceptor imports and observability calls updated: use observability.NewTrackingFromContext, record span errors with tracing.HandleSpanError, and set app.request.payload via tracing.SetSpanAttributesFromValue.
Tests, deps, CI, and changelog updates
auth/middleware/middleware_test.go, go.mod, .github/workflows/go-combined-analysis.yml, CHANGELOG.md
Test logger import switched to lib-observability/log and added TestGetApplicationToken_DoesNotTraceClientSecret. Go toolchain bumped to 1.26.3 with selected dependency updates. CI updated to use Go 1.26 and install gosec via go install ...@latest. CHANGELOG prepended with 2.8.0-beta.4.

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

@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 `@auth/middleware/middleware.go`:
- Around line 424-427: The tracing call SetSpanAttributesFromValue is currently
sending the entire requestBody (used as "app.request.payload") which may include
OAuth credentials like clientSecret; before calling
tracing.SetSpanAttributesFromValue(span, "app.request.payload", requestBody,
nil) sanitize the payload by cloning or copying requestBody and
removing/redacting any sensitive keys (e.g., "clientSecret", "client_secret",
"password", "token") or replace their values with a fixed placeholder, then pass
the sanitized object to tracing.SetSpanAttributesFromValue; ensure this change
is applied where span and requestBody are used so no secret fields are sent to
telemetry.
🪄 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: 641c9aab-9990-4fb9-870a-1e96f38851b8

📥 Commits

Reviewing files that changed from the base of the PR and between 7ced5f6 and 58df7d5.

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

Comment thread auth/middleware/middleware.go Outdated
go.mod targets Go 1.26.3 after the lib-observability migration. The
pinned golangci-lint v2.4.0 was built with Go 1.25 and refuses to lint
a 1.26-targeted module. The gosec Docker action ships Go 1.26.2 with
GOTOOLCHAIN=local, so it also can't satisfy the module floor.

Float golangci-lint to latest, bump the action's internal go_version
to 1.26, and replace the gosec Docker action with a host-side
go install so the setup-go pin actually controls gosec's runtime.
@lerian-studio-midaz-push-bot

Copy link
Copy Markdown

🎉 This PR is included in version 2.8.0-beta.2 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@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 @.github/workflows/go-combined-analysis.yml:
- Line 56: Replace the unconstrained golangci_lint_version value of "latest"
with a specific pinned release (e.g., "v1.59.0") and likewise pin gosec by
adding or replacing gosec_version with an explicit version (e.g., "v2.14.0");
update any workflow steps or inputs that reference golangci_lint_version and
gosec_version so they consume these pinned variables to ensure reproducible
CI/security scans (look for the golangci_lint_version variable and any
gosec-related inputs in the workflow and set concrete semantic-version tags
instead of "latest").
🪄 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: 53411899-b79f-4379-be7a-7c58f6b9b98b

📥 Commits

Reviewing files that changed from the base of the PR and between 58df7d5 and fa8e79b.

📒 Files selected for processing (2)
  • .github/workflows/go-combined-analysis.yml
  • CHANGELOG.md

Comment thread .github/workflows/go-combined-analysis.yml
…b-observability

Replace remaining four call sites still using the deprecated
commons.NewTrackingFromContext with the lib-observability equivalent.
Tail of b32322c, which migrated the bulk of the observability layer
but missed these middleware call sites and triggered staticcheck
SA1019 findings on PR #99.
@lerian-studio-midaz-push-bot

Copy link
Copy Markdown

🎉 This PR is included in version 2.8.0-beta.3 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@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

♻️ Duplicate comments (1)
auth/middleware/middleware.go (1)

419-426: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Redact OAuth secret from telemetry payload.

Line 425 sends requestBody to span attributes, and requestBody includes clientSecret (Line 422). This can leak credentials into tracing backends.

🔒 Proposed fix
 	requestBody := map[string]string{
 		"grantType":    "client_credentials",
 		"clientId":     clientID,
 		"clientSecret": clientSecret,
 	}
 
-	err := tracing.SetSpanAttributesFromValue(span, "app.request.payload", requestBody, nil)
+	tracePayload := map[string]string{
+		"grantType": "client_credentials",
+		"clientId":  clientID,
+	}
+
+	err := tracing.SetSpanAttributesFromValue(span, "app.request.payload", tracePayload, nil)
 	if err != nil {
 		tracing.HandleSpanError(span, "Failed to convert request body to JSON string", err)
 
 		return "", fmt.Errorf("failed to convert request body to JSON string: %w", err)
 	}
#!/bin/bash
set -euo pipefail

# Verify no sensitive credential keys are attached to tracing payload attributes.
rg -n -C4 'SetSpanAttributesFromValue\(.+app\.request\.payload' auth/middleware/middleware.go auth/middleware/middlewareGRPC.go
rg -n -C4 '"clientSecret"|"client_secret"|"password"|"secret"|"accessToken"|"refreshToken"' auth/middleware/middleware.go auth/middleware/middlewareGRPC.go
🤖 Prompt for 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.

In `@auth/middleware/middleware.go` around lines 419 - 426, The tracing payload
currently includes sensitive credentials: the map requestBody (used in
tracing.SetSpanAttributesFromValue with span) contains clientSecret; change the
code to exclude or redact the secret before attaching to tracing (e.g., create a
copy of requestBody or a sanitized map and either remove the "clientSecret" key
or replace its value with a mask like "[REDACTED]"), then pass that sanitized
map to tracing.SetSpanAttributesFromValue(span, "app.request.payload",
sanitizedRequestBody, nil); also audit any other uses of
tracing.SetSpanAttributesFromValue in middlewareGRPC.go to ensure no secret keys
(client_secret, password, accessToken, refreshToken) are sent.
🤖 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 `@CHANGELOG.md`:
- Around line 1-6: CHANGELOG shows empty entries for releases 2.8.0-beta.1,
2.8.0-beta.2 and 2.8.0-beta.3; regenerate or restore the missing changelog
content by re-running your changelog generation (semantic-release /
conventional-changelog) so the commits `refactor(middleware): migrate
observability to lib-observability package`, `ci: bump go-version to 1.26 and
golangci-lint to latest`, and `refactor(middleware): complete
NewTrackingFromContext migration to lib-observability` are included under the
respective 2.8.0-beta.* headings, and verify .releaserc.yml still includes the
'refactor' and 'ci' types and that the changelog plugin executed successfully
(inspect the release automation logs and re-run the release step if necessary).

---

Duplicate comments:
In `@auth/middleware/middleware.go`:
- Around line 419-426: The tracing payload currently includes sensitive
credentials: the map requestBody (used in tracing.SetSpanAttributesFromValue
with span) contains clientSecret; change the code to exclude or redact the
secret before attaching to tracing (e.g., create a copy of requestBody or a
sanitized map and either remove the "clientSecret" key or replace its value with
a mask like "[REDACTED]"), then pass that sanitized map to
tracing.SetSpanAttributesFromValue(span, "app.request.payload",
sanitizedRequestBody, nil); also audit any other uses of
tracing.SetSpanAttributesFromValue in middlewareGRPC.go to ensure no secret keys
(client_secret, password, accessToken, refreshToken) are sent.
🪄 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: 43d2ac82-4a9b-4b77-b093-0809a5f42066

📥 Commits

Reviewing files that changed from the base of the PR and between fa8e79b and e6c89c4.

📒 Files selected for processing (3)
  • CHANGELOG.md
  • auth/middleware/middleware.go
  • auth/middleware/middlewareGRPC.go

Comment thread CHANGELOG.md
GetApplicationToken was passing the OAuth client_credentials request body —
including clientSecret — to tracing.SetSpanAttributesFromValue, leaking the
long-lived service credential into every consumer's observability pipeline
(OTel collector, Datadog, Jaeger, etc.).

Introduce a separate tracePayload map at the call site that mirrors the
wire payload but omits clientSecret. The HTTP request body (json.Marshal of
the unchanged requestBody) is unaffected, so authentication behavior is
identical. Inline comment warns against collapsing the two maps in any
future DRY-up.
## [2.8.0-beta.4](v2.8.0-beta.3...v2.8.0-beta.4) (2026-05-18)

### Bug Fixes

* **security:** redact clientSecret from tracing span payload ([fb15a94](fb15a94))
@lerian-studio-midaz-push-bot

Copy link
Copy Markdown

🎉 This PR is included in version 2.8.0-beta.4 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@fredcamaral

Copy link
Copy Markdown
Member Author

CodeRabbit Autofix Review Complete

Reviewed 3 CodeRabbit feedback items.

Applied (1):

  • 🔴 Avoid sending clientSecret into tracing attributesauth/middleware/middleware.go:425. Constructed a tracePayload map that omits clientSecret; wire payload (requestBodyjson.Marshal) is unchanged. Same file's second SetSpanAttributesFromValue at line 322 was confirmed benign ({sub, resource, action}) and left untouched.
  • Commit: fb15a94
  • File modified: auth/middleware/middleware.go

Deferred (2):

  • 🟡 Pin golangci-lint and gosec versions (.github/workflows/go-combined-analysis.yml:56) — the previous pin (v2.4.0) is precisely what broke CI on this PR when go.mod moved to Go 1.26.3. Floating to latest was a deliberate trade. The proposed ${{ vars.GOLANGCI_LINT_VERSION }} indirection requires org-level GitHub variables that don't yet exist; auto-applying would resolve to empty and break CI. Reproducibility belongs in a coordinated org-wide change, not this PR.
  • 🟡 Empty 2.8.0-beta.{1,2,3} CHANGELOG entries (CHANGELOG.md:1-6) — the empty entries were generated by the semantic-release run, not lost from a hand edit. Root cause is in release automation config (.releaserc.yml template or commit-type filter), not in CHANGELOG.md itself. Hand-editing here will be overwritten on the next bot run. Fix lives in a separate change to release automation.

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

♻️ Duplicate comments (1)
CHANGELOG.md (1)

8-13: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Populate the empty beta release sections (2.8.0-beta.3/.2/.1).

These headings are still empty, so the changelog does not document what changed in those beta cuts. Please regenerate/restore those entries so each beta release has its corresponding notes.

🤖 Prompt for 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.

In `@CHANGELOG.md` around lines 8 - 13, The three beta release headings in
CHANGELOG.md (2.8.0-beta.3, 2.8.0-beta.2, 2.8.0-beta.1) are empty; regenerate or
restore their release notes so each heading lists the actual changes — for each
heading (2.8.0-beta.3 / 2.8.0-beta.2 / 2.8.0-beta.1) restore the corresponding
release notes by re-running your changelog generator (or copying the released
notes/PR summaries and commit links from the repository or release pages) and
paste them under the appropriate heading, including short descriptions,
PR/commit references and dates so each beta entry documents its changes.
🤖 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.

Duplicate comments:
In `@CHANGELOG.md`:
- Around line 8-13: The three beta release headings in CHANGELOG.md
(2.8.0-beta.3, 2.8.0-beta.2, 2.8.0-beta.1) are empty; regenerate or restore
their release notes so each heading lists the actual changes — for each heading
(2.8.0-beta.3 / 2.8.0-beta.2 / 2.8.0-beta.1) restore the corresponding release
notes by re-running your changelog generator (or copying the released notes/PR
summaries and commit links from the repository or release pages) and paste them
under the appropriate heading, including short descriptions, PR/commit
references and dates so each beta entry documents its changes.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: fbeb7b6b-d417-4195-8ae3-7f30a470b9a2

📥 Commits

Reviewing files that changed from the base of the PR and between e6c89c4 and e1a25d9.

📒 Files selected for processing (2)
  • CHANGELOG.md
  • auth/middleware/middleware.go

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed the observability migration and the CodeRabbit follow-up.

No blocking findings from my side. I verified the PR at e1a25d9 with:

  • go test ./...
  • go build ./...
  • GitHub workflow Go Combined Analysis is green on the head commit

One release note before stable: NewAuthClient now takes *github.com/LerianStudio/lib-observability/log.Logger, so downstream consumers passing a custom logger from lib-commons/commons/log need to migrate imports. That is fine for this beta, but the smoke test should explicitly cover that path before promoting.

@fredcamaral

Copy link
Copy Markdown
Member Author

@CodeRabbit approve

@coderabbitai

coderabbitai Bot commented May 18, 2026

Copy link
Copy Markdown
✅ Actions performed

Comments resolved and changes approved.

Add TestGetApplicationToken_DoesNotTraceClientSecret to ensure that
the client secret is not included in OpenTelemetry span attributes.
This prevents sensitive credentials from leaking into observability
tools during application token generation.
@fredcamaral
fredcamaral merged commit 04ce71b into main May 18, 2026
3 of 4 checks passed
@lerian-studio-midaz-push-bot

Copy link
Copy Markdown

🎉 This PR is included in version 2.8.0-beta.5 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@lerian-studio-midaz-push-bot

Copy link
Copy Markdown

🎉 This PR is included in version 2.8.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.

4 participants