Skip to content

Commit 9a19406

Browse files
Move logging fields from logProxy()
1 parent 30f37ab commit 9a19406

1 file changed

Lines changed: 10 additions & 9 deletions

File tree

pkg/smokescreen/smokescreen.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -617,20 +617,11 @@ func logProxy(pctx *goproxy.ProxyCtx) {
617617

618618
fields := logrus.Fields{}
619619
decision := sctx.Decision
620-
// If a lookup takes less than 1ms it will be rounded down to zero. This can separated from
621-
// actual failures where the default zero value will also have the error field set.
622-
fields[LogFieldDNSLookupTime] = sctx.lookupTime.Milliseconds()
623620

624621
if pctx.Resp != nil {
625622
fields[LogFieldContentLength] = pctx.Resp.ContentLength
626623
}
627624

628-
if sctx.Decision != nil {
629-
fields[LogFieldDecisionReason] = decision.Reason
630-
fields[LogFieldEnforceWouldDeny] = decision.enforceWouldDeny
631-
fields[LogFieldAllow] = decision.allow
632-
}
633-
634625
err := pctx.Error
635626
if err != nil {
636627
fields[LogFieldError] = err.Error()
@@ -656,7 +647,17 @@ func extractContextLogFields(pctx *goproxy.ProxyCtx, sctx *SmokescreenContext) l
656647
if sctx.Decision != nil {
657648
fields[LogFieldRole] = decision.Role
658649
fields[LogFieldProject] = decision.Project
650+
// Add decision-related fields that are available early
651+
fields[LogFieldDecisionReason] = decision.Reason
652+
fields[LogFieldEnforceWouldDeny] = decision.enforceWouldDeny
653+
fields[LogFieldAllow] = decision.allow
659654
}
655+
656+
// Add DNS lookup time (available after checkIfRequestShouldBeProxied)
657+
// If a lookup takes less than 1ms it will be rounded down to zero. This can be separated from
658+
// actual failures where the default zero value will also have the error field set.
659+
fields[LogFieldDNSLookupTime] = sctx.lookupTime.Milliseconds()
660+
660661
return fields
661662
}
662663

0 commit comments

Comments
 (0)