obs: http metrics histogram, client ip and error body logging#24
Draft
gandalf-at-lerian wants to merge 1 commit into
Draft
obs: http metrics histogram, client ip and error body logging#24gandalf-at-lerian wants to merge 1 commit into
gandalf-at-lerian wants to merge 1 commit into
Conversation
Adds two structured access-log fields to WithHTTPLogging: - http_client_ip: the client IP from c.IP(), which honors Fiber's configured proxy trust chain (EnableTrustedProxyCheck + ProxyHeader) for X-Forwarded-For so the value cannot be spoofed by untrusted peers. - http_error: the response body for error responses (status >= 400), passed through the same content-type-aware redaction pipeline used for request bodies and capped at 2 KiB on a UTF-8 boundary, so sensitive fields are never leaked into logs. Requested-by: @qnen
Contributor
📊 Unit Test Coverage Report:
|
| Metric | Value |
|---|---|
| Overall Coverage | 85.5% ✅ PASS |
| Threshold | 80% |
Coverage by Package
| Package | Coverage |
|---|---|
github.com/LerianStudio/lib-observability/assert |
97.9% |
github.com/LerianStudio/lib-observability/constants |
83.3% |
github.com/LerianStudio/lib-observability/log |
94.9% |
github.com/LerianStudio/lib-observability/metrics |
91.4% |
github.com/LerianStudio/lib-observability/middleware |
76.5% |
github.com/LerianStudio/lib-observability/redaction |
95.8% |
github.com/LerianStudio/lib-observability/runtime |
80.4% |
github.com/LerianStudio/lib-observability/tracing |
85.1% |
github.com/LerianStudio/lib-observability/zap |
96.0% |
github.com/LerianStudio/lib-observability |
91.5% |
Generated by Go PR Analysis workflow
Contributor
🔒 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.
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Comment |
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Contexto
Itens de risco médio/alto separados do PR #23 para revisão independente.
Itens nesta PR (draft)
http_client_ip(X-Forwarded-For com trust chain)Adiciona o campo estruturado
http_client_ipao access log usandoc.IP(). O Fiber só resolveX-Forwarded-ForquandoEnableTrustedProxyCheck+ProxyHeaderestão configurados, respeitando a trust chain de proxy — evita spoofing por peers não confiáveis. Parsear o header manualmente reintroduziria essa vulnerabilidade, então delegamos ao mecanismo já auditado do Fiber.http_error(body do erro com sanitização)Loga o body da resposta quando
status >= 400, no campohttp_error. O body passa pelo mesmo pipeline de redação por content-type usado nos request bodies (campos sensíveis viram[OBFUSCATED]) e é truncado em 2 KiB num boundary UTF-8. Respostas não-JSON viram[REDACTED].http.server.request.duration(histograma OTEL)Já presente em
develop(middleware/telemetry.go): instrumentoFloat64Histogramregistrado no meter, com buckets seguindo o advisory das HTTP semantic conventions, gravado viarecordHTTPServerDuration. Nenhuma mudança necessária — incluído aqui apenas para rastreabilidade do escopo solicitado.Verificação
go build ./...OKgo test -tags unit ./...OK (inclui novos testes de client IP, error body sanitizado e omissão em 2xx)golangci-lint run ./middleware/0 issuesRequested-by: @qnen