@@ -428,15 +428,25 @@ func configureTransport(tr *http.Transport, cfg *Config) {
428428func newContext (cfg * Config , proxyType string , req * http.Request ) * SmokescreenContext {
429429 start := time .Now ()
430430
431- logger := cfg . Log . WithFields ( logrus.Fields {
431+ fields := logrus.Fields {
432432 LogFieldID : xid .New ().String (),
433433 LogFieldInRemoteAddr : req .RemoteAddr ,
434434 LogFieldProxyType : proxyType ,
435435 LogFieldRequestedHost : req .Host ,
436436 LogFieldStartTime : start .UTC (),
437437 LogFieldTraceID : req .Header .Get (traceHeader ),
438- })
438+ }
439439
440+ // Add TLS fields immediately if available
441+ if req .TLS != nil && len (req .TLS .PeerCertificates ) > 0 {
442+ fields [LogFieldInRemoteX509CN ] = req .TLS .PeerCertificates [0 ].Subject .CommonName
443+ var ouEntries = req .TLS .PeerCertificates [0 ].Subject .OrganizationalUnit
444+ if len (ouEntries ) > 0 {
445+ fields [LogFieldInRemoteX509OU ] = ouEntries [0 ]
446+ }
447+ }
448+
449+ logger := cfg .Log .WithFields (fields )
440450 return & SmokescreenContext {
441451 cfg : cfg ,
442452 Logger : logger ,
@@ -641,15 +651,6 @@ func logProxy(pctx *goproxy.ProxyCtx) {
641651func extractContextLogFields (pctx * goproxy.ProxyCtx , sctx * SmokescreenContext ) logrus.Fields {
642652 fields := logrus.Fields {}
643653
644- // attempt to retrieve information about the host originating the proxy request
645- if pctx .Req .TLS != nil && len (pctx .Req .TLS .PeerCertificates ) > 0 {
646- fields [LogFieldInRemoteX509CN ] = pctx .Req .TLS .PeerCertificates [0 ].Subject .CommonName
647- var ouEntries = pctx .Req .TLS .PeerCertificates [0 ].Subject .OrganizationalUnit
648- if len (ouEntries ) > 0 {
649- fields [LogFieldInRemoteX509OU ] = ouEntries [0 ]
650- }
651- }
652-
653654 // Retrieve information from the ACL decision
654655 decision := sctx .Decision
655656 if sctx .Decision != nil {
0 commit comments