Skip to content

Commit c21720a

Browse files
authored
Add structured logging to src/assets middleware (#60981)
1 parent 2c81ab3 commit c21720a

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

src/assets/middleware/dynamic-assets.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import sharp from 'sharp'
66
import type { ExtendedRequest } from '@/types'
77
import { assetCacheControl, defaultCacheControl } from '@/frame/middleware/cache-control'
88
import { setFastlySurrogateKey, SURROGATE_ENUMS } from '@/frame/middleware/set-fastly-surrogate-key'
9+
import { createLogger } from '@/observability/logger'
10+
11+
const logger = createLogger(import.meta.url)
912

1013
/**
1114
* This is the indicator that is a virtual part of the URL.
@@ -83,6 +86,7 @@ export default async function dynamicAssets(
8386
if (req.path.endsWith('.webp')) {
8487
const { url, maxWidth, error } = deconstructImageURL(req.path)
8588
if (error) {
89+
logger.warn('Invalid dynamic asset URL', { path: req.path, error })
8690
return res.status(400).type('text/plain').send(error.toString())
8791
}
8892
try {
@@ -149,6 +153,7 @@ export default async function dynamicAssets(
149153
'code' in catchError &&
150154
(catchError as NodeJS.ErrnoException).code !== 'ENOENT'
151155
) {
156+
logger.error('Failed to process dynamic asset', { path: req.path, error: catchError })
152157
throw catchError
153158
}
154159
}

0 commit comments

Comments
 (0)