@@ -25,6 +25,16 @@ setupWaitUntil()
2525
2626let nextHandler : WorkerRequestHandler , nextConfig : NextConfigComplete
2727
28+ function expandHeaders ( prefix : string , headers : Headers ) {
29+ return [ ...headers . entries ( ) ] . reduce (
30+ ( acc , [ key , value ] ) => {
31+ acc [ `${ prefix } .${ key } ` ] = value
32+ return acc
33+ } ,
34+ { } as Record < string , string > ,
35+ )
36+ }
37+
2838/**
2939 * When Next.js proxies requests externally, it writes the response back as-is.
3040 * In some cases, this includes Transfer-Encoding: chunked.
@@ -112,14 +122,14 @@ export default async (
112122 }
113123
114124 const nextCache = response . headers . get ( 'x-nextjs-cache' )
115- const isServedFromCache = nextCache === 'HIT' || nextCache === 'STALE'
125+ const isServedFromNextCache = nextCache === 'HIT' || nextCache === 'STALE'
116126
117127 topLevelSpan . setAttributes ( {
118128 'x-nextjs-cache' : nextCache ?? undefined ,
119- isServedFromCache ,
129+ isServedFromNextCache ,
120130 } )
121131
122- if ( isServedFromCache ) {
132+ if ( isServedFromNextCache ) {
123133 await adjustDateHeader ( {
124134 headers : response . headers ,
125135 request,
@@ -159,6 +169,20 @@ export default async (
159169 await waitForBackgroundWork ( )
160170 }
161171
172+ topLevelSpan . setAttributes ( {
173+ isBackgroundRevalidation : requestContext . isBackgroundRevalidation ,
174+ ...expandHeaders ( 'request.headers' , request . headers ) ,
175+ ...expandHeaders ( 'response.headers' , response . headers ) ,
176+ } )
177+
178+ // requestContext.logger
179+ // .withFields({
180+ // isBackgroundRevalidation: requestContext.isBackgroundRevalidation,
181+ // ...expandHeaders('request.headers', request.headers),
182+ // ...expandHeaders('response.headers', response.headers),
183+ // })
184+ // .debug('[NetlifyNextRuntime] Response cache headers')
185+
162186 return new Response ( response . body ?. pipeThrough ( keepOpenUntilNextFullyRendered ) , response )
163187 } )
164188}
0 commit comments