Add detailed logging for image requests with cache status and timing
This commit is contained in:
@@ -78,7 +78,11 @@ func (s *Handlers) HandleImage() http.HandlerFunc {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get cache key for logging
|
||||||
|
cacheKey := imgcache.CacheKey(req)
|
||||||
|
|
||||||
// Get the image (from cache or fetch/process)
|
// Get the image (from cache or fetch/process)
|
||||||
|
startTime := time.Now()
|
||||||
resp, err := s.imgSvc.Get(ctx, req)
|
resp, err := s.imgSvc.Get(ctx, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.log.Error("failed to get image",
|
s.log.Error("failed to get image",
|
||||||
@@ -120,6 +124,17 @@ func (s *Handlers) HandleImage() http.HandlerFunc {
|
|||||||
w.Header().Set("ETag", resp.ETag)
|
w.Header().Set("ETag", resp.ETag)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Log cache status and timing
|
||||||
|
duration := time.Since(startTime)
|
||||||
|
s.log.Info("image served",
|
||||||
|
"cache_key", cacheKey,
|
||||||
|
"cache_status", resp.CacheStatus,
|
||||||
|
"duration_ms", duration.Milliseconds(),
|
||||||
|
"format", req.Format,
|
||||||
|
"served_bytes", resp.ContentLength,
|
||||||
|
"fetched_bytes", resp.FetchedBytes,
|
||||||
|
)
|
||||||
|
|
||||||
// Stream the response
|
// Stream the response
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
|
|
||||||
|
|||||||
@@ -90,6 +90,8 @@ type ImageResponse struct {
|
|||||||
LastModified time.Time
|
LastModified time.Time
|
||||||
// CacheStatus indicates HIT, MISS, or STALE
|
// CacheStatus indicates HIT, MISS, or STALE
|
||||||
CacheStatus CacheStatus
|
CacheStatus CacheStatus
|
||||||
|
// FetchedBytes is the number of bytes fetched from upstream (0 if cache hit)
|
||||||
|
FetchedBytes int64
|
||||||
}
|
}
|
||||||
|
|
||||||
// CacheStatus indicates whether the response was served from cache.
|
// CacheStatus indicates whether the response was served from cache.
|
||||||
|
|||||||
@@ -172,6 +172,7 @@ func (s *Service) fetchAndProcess(ctx context.Context, req *ImageRequest) (*Imag
|
|||||||
Content: io.NopCloser(bytes.NewReader(processedData)),
|
Content: io.NopCloser(bytes.NewReader(processedData)),
|
||||||
ContentLength: int64(len(processedData)),
|
ContentLength: int64(len(processedData)),
|
||||||
ContentType: processResult.ContentType,
|
ContentType: processResult.ContentType,
|
||||||
|
FetchedBytes: int64(len(sourceData)),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user