Skip to content

Commit

Permalink
[DEV-5671] Add new params to logger
Browse files Browse the repository at this point in the history
* Add Path and keys

* update linter
  • Loading branch information
piotrowski authored Jun 7, 2024
1 parent 322ae01 commit 5262169
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 9 deletions.
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ linters:
- gofmt
- gocritic
- dupl
- ifshort
- importas
- makezero
- nestif
Expand Down
2 changes: 2 additions & 0 deletions key/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ const (
Latency = "latency"
Method = "method"
URI = "uri"
Path = "path"
External = "external"
Status = "status"
UserAgent = "user_agent"
APIVersion = "api_version"
Expand Down
11 changes: 3 additions & 8 deletions zap/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,17 @@ func (w *Logger) EchoMiddleware(l logi.WLogger) echo.MiddlewareFunc {

fields := []any{
"remote_ip", c.RealIP(),
key.External, false,
key.Email, email,
key.CompanyKey, companyKey,
key.Latency, time.Since(start).Milliseconds(),
key.Method, req.Method,
key.URI, req.RequestURI,
key.Path, req.URL.Path,
key.Status, res.Status,
key.UserAgent, req.UserAgent(),
key.APIVersion, res.Header().Get("API-Version"),
}

// Backward compatibility. Remove after no more `deprecated-version-used`
if ver := req.Header.Get("Extension-Version"); ver != "" {
fields = append(fields, key.ExtensionVersion, ver)
} else if ver := req.Header.Get("X-API-Version"); ver != "" {
fields = append(fields, key.ExtensionVersion, ver)
fields = append(fields, "deprecated_version_header_used", "true")
key.ExtensionVersion, res.Header().Get("Extension-Version"),
}

if correlationID, isOk := req.Context().Value(key.CtxCorrelationID).(string); isOk && correlationID != "" {
Expand Down

0 comments on commit 5262169

Please sign in to comment.