diff --git a/accesslog/schema/access_log_record.go b/accesslog/schema/access_log_record.go index 07db8607..7d38556c 100644 --- a/accesslog/schema/access_log_record.go +++ b/accesslog/schema/access_log_record.go @@ -7,6 +7,7 @@ import ( "fmt" "io" "net/http" + "net/url" "strconv" "strings" "time" @@ -101,6 +102,7 @@ type AccessLogRecord struct { HeadersOverride http.Header StatusCode int RouteEndpoint *route.Endpoint + RouteServiceUrl *url.URL RoundtripStartedAt time.Time FirstByteAt time.Time RoundtripFinishedAt time.Time @@ -152,7 +154,7 @@ func (r *AccessLogRecord) getRecord(performTruncate bool) []byte { } func (r *AccessLogRecord) makeRecord(performTruncate bool) []byte { - var appID, destIPandPort, appIndex, instanceId string + var appID, destIPandPort, appIndex, instanceId, routeServiceUrl string if r.RouteEndpoint != nil { appID = r.RouteEndpoint.ApplicationId @@ -161,6 +163,10 @@ func (r *AccessLogRecord) makeRecord(performTruncate bool) []byte { instanceId = r.RouteEndpoint.PrivateInstanceId } + if r.RouteServiceUrl != nil { + routeServiceUrl = truncateToSize(r.RouteServiceUrl.String(), "route-service-url", LARGE_BYTES_LIMIT) + } + headers := r.Request.Header if r.HeadersOverride != nil { headers = r.HeadersOverride @@ -224,6 +230,9 @@ func (r *AccessLogRecord) makeRecord(performTruncate bool) []byte { b.WriteString(`instance_id:`) b.WriteDashOrStringValue(instanceId) + b.WriteString(`route_service_url:`) + b.WriteDashOrStringValue(routeServiceUrl) + b.AppendSpaces(false) b.WriteString(`x_cf_routererror:`) b.WriteDashOrStringValue(r.RouterError) diff --git a/handlers/access_log.go b/handlers/access_log.go index 77c22576..b8b4faeb 100644 --- a/handlers/access_log.go +++ b/handlers/access_log.go @@ -61,6 +61,7 @@ func (a *accessLog) ServeHTTP(rw http.ResponseWriter, r *http.Request, next http alr.AppRequestFinishedAt = reqInfo.AppRequestFinishedAt alr.HeadersOverride = reqInfo.BackendReqHeaders alr.RouteEndpoint = reqInfo.RouteEndpoint + alr.RouteServiceUrl = reqInfo.RouteServiceURL alr.RequestBytesReceived = requestBodyCounter.GetCount() alr.BodyBytesSent = proxyWriter.Size() alr.StatusCode = proxyWriter.Status() diff --git a/handlers/requestinfo.go b/handlers/requestinfo.go index b62a386f..95f61f7d 100644 --- a/handlers/requestinfo.go +++ b/handlers/requestinfo.go @@ -18,7 +18,7 @@ type key string const RequestInfoCtxKey key = "RequestInfo" // RequestInfo stores all metadata about the request and is used to pass -// informaton between handlers +// information between handlers type RequestInfo struct { StartedAt, StoppedAt time.Time AppRequestStartedAt, AppRequestFinishedAt time.Time