You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Provide visibility into cache behavior for fetch requests through OpenTelemetry spans
Enable developers to monitor and debug caching performance in production environments
Add standardized cache-related attributes that align with OpenTelemetry conventions
Improve observability of Next.js's advanced caching mechanisms
Non-Goals
Modify the core caching logic or behavior of Next.js
Add performance overhead to fetch operations
Change existing OpenTelemetry span structure or break backward compatibility
Implement cache metrics beyond what's needed for span attributes
Background
Next.js provides advanced caching capabilities, including fetch requests caching.
Currently, Next.js generates OpenTelemetry spans for fetch requests (AppRender.fetch) but these spans lack visibility into whether requests were served from cache or fetched from origin. This makes it difficult for developers to:
Debug caching issues in production
Monitor cache hit rates
Understand performance characteristics of their applications
Validate that caching is working as expected
Proposal
Add three new attributes to fetch spans in packages/next/src/server/lib/patch-fetch.ts:
next.cache.status
Indicates the cache outcome for the request:
hit - Request was served from cache
miss - Request was not found in cache and fetched from origin
skip - Caching was disabled for this request
hmr - Request was served from HMR cache during development
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Goals
Non-Goals
Background
Next.js provides advanced caching capabilities, including fetch requests caching.
Currently, Next.js generates OpenTelemetry spans for fetch requests (
AppRender.fetch
) but these spans lack visibility into whether requests were served from cache or fetched from origin. This makes it difficult for developers to:Proposal
Add three new attributes to fetch spans in
packages/next/src/server/lib/patch-fetch.ts
:next.cache.status
Indicates the cache outcome for the request:
hit
- Request was served from cachemiss
- Request was not found in cache and fetched from originskip
- Caching was disabled for this requesthmr
- Request was served from HMR cache during developmentnext.cache.reason
Provides context for the caching behavior:
fetchCache = force-cache
- Explicit cache configurationrevalidate: 60
- Time-based revalidationnext.cache.revalidate
The revalidate value used for the request:
undefined
if no revalidate value was setImplementation Details
span.setAttributes()
This enhancement provides essential observability into Next.js's caching behavior without changing core functionality or adding significant overhead.
Beta Was this translation helpful? Give feedback.
All reactions