@netlify/plugin-nextjs 5.4.0-canary-perf-debug.0 → 5.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +62 -2
- package/dist/build/content/prerendered.js +36 -9
- package/dist/build/content/server.js +7 -49
- package/dist/build/content/static.js +9 -8
- package/dist/build/functions/server.js +4 -6
- package/dist/build/plugin-context.js +18 -0
- package/dist/build/templates/handler-monorepo.tmpl.js +5 -10
- package/dist/build/templates/handler.tmpl.js +4 -10
- package/dist/build/verification.js +43 -11
- package/dist/esm-chunks/{package-NQYUR3EH.js → package-C5ZXMRQF.js} +10 -10
- package/dist/index.js +7 -2
- package/dist/run/config.js +2 -4
- package/dist/run/handlers/cache.cjs +115 -26
- package/dist/run/handlers/request-context.cjs +80 -3
- package/dist/run/handlers/server.js +8 -25
- package/dist/run/handlers/tracer.cjs +1 -1
- package/dist/run/handlers/tracing.js +50 -73
- package/dist/run/headers.js +13 -20
- package/dist/run/next.cjs +1 -3
- package/dist/run/revalidate.js +12 -5
- package/edge-runtime/lib/next-request.ts +15 -22
- package/edge-runtime/lib/routing.ts +7 -7
- package/edge-runtime/lib/util.ts +0 -2
- package/edge-runtime/middleware.ts +4 -5
- package/package.json +4 -4
- package/dist/run/handlers/import-time-debug.cjs +0 -53
- package/dist/run/systemlog.cjs +0 -98
|
@@ -35,6 +35,8 @@ __export(cache_exports, {
|
|
|
35
35
|
});
|
|
36
36
|
module.exports = __toCommonJS(cache_exports);
|
|
37
37
|
var import_node_buffer = require("node:buffer");
|
|
38
|
+
var import_node_path = require("node:path");
|
|
39
|
+
var import_posix = require("node:path/posix");
|
|
38
40
|
|
|
39
41
|
// node_modules/@netlify/functions/dist/chunk-COIAWFHF.mjs
|
|
40
42
|
var import_process = require("process");
|
|
@@ -94,7 +96,6 @@ var pipeline = (0, import_util.promisify)(import_stream.pipeline);
|
|
|
94
96
|
// src/run/handlers/cache.cts
|
|
95
97
|
var import_constants = require("next/dist/lib/constants.js");
|
|
96
98
|
var import_regional_blob_store = require("../regional-blob-store.cjs");
|
|
97
|
-
var import_systemlog = require("../systemlog.cjs");
|
|
98
99
|
var import_request_context = require("./request-context.cjs");
|
|
99
100
|
var import_tracer = require("./tracer.cjs");
|
|
100
101
|
var NetlifyCacheHandler = class {
|
|
@@ -154,10 +155,58 @@ var NetlifyCacheHandler = class {
|
|
|
154
155
|
}
|
|
155
156
|
return restOfRouteValue;
|
|
156
157
|
}
|
|
158
|
+
captureCacheTags(cacheValue, key) {
|
|
159
|
+
if (!cacheValue) {
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
const requestContext = (0, import_request_context.getRequestContext)();
|
|
163
|
+
if (!requestContext) {
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
if (requestContext.responseCacheTags) {
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
if (cacheValue.kind === "PAGE" || cacheValue.kind === "APP_PAGE" || cacheValue.kind === "ROUTE") {
|
|
170
|
+
if (cacheValue.headers?.[import_constants.NEXT_CACHE_TAGS_HEADER]) {
|
|
171
|
+
const cacheTags = cacheValue.headers[import_constants.NEXT_CACHE_TAGS_HEADER].split(",");
|
|
172
|
+
requestContext.responseCacheTags = cacheTags;
|
|
173
|
+
} else if (cacheValue.kind === "PAGE" && typeof cacheValue.pageData === "object") {
|
|
174
|
+
const cacheTags = [`_N_T_${key === "/index" ? "/" : key}`];
|
|
175
|
+
requestContext.responseCacheTags = cacheTags;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
async injectEntryToPrerenderManifest(key, revalidate) {
|
|
180
|
+
if (this.options.serverDistDir && (typeof revalidate === "number" || revalidate === false)) {
|
|
181
|
+
try {
|
|
182
|
+
const { loadManifest } = await import("next/dist/server/load-manifest.js");
|
|
183
|
+
const prerenderManifest = loadManifest(
|
|
184
|
+
(0, import_node_path.join)(this.options.serverDistDir, "..", "prerender-manifest.json")
|
|
185
|
+
);
|
|
186
|
+
try {
|
|
187
|
+
const { normalizePagePath } = await import("next/dist/shared/lib/page-path/normalize-page-path.js");
|
|
188
|
+
prerenderManifest.routes[key] = {
|
|
189
|
+
experimentalPPR: void 0,
|
|
190
|
+
dataRoute: (0, import_posix.join)("/_next/data", `${normalizePagePath(key)}.json`),
|
|
191
|
+
srcRoute: null,
|
|
192
|
+
// FIXME: provide actual source route, however, when dynamically appending it doesn't really matter
|
|
193
|
+
initialRevalidateSeconds: revalidate,
|
|
194
|
+
// Pages routes do not have a prefetch data route.
|
|
195
|
+
prefetchDataRoute: void 0
|
|
196
|
+
};
|
|
197
|
+
} catch {
|
|
198
|
+
const { SharedRevalidateTimings } = await import("next/dist/server/lib/incremental-cache/shared-revalidate-timings.js");
|
|
199
|
+
const sharedRevalidateTimings = new SharedRevalidateTimings(prerenderManifest);
|
|
200
|
+
sharedRevalidateTimings.set(key, revalidate);
|
|
201
|
+
}
|
|
202
|
+
} catch {
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
157
206
|
async get(...args) {
|
|
158
207
|
return this.tracer.withActiveSpan("get cache key", async (span) => {
|
|
159
208
|
const [key, ctx = {}] = args;
|
|
160
|
-
|
|
209
|
+
(0, import_request_context.getLogger)().debug(`[NetlifyCacheHandler.get]: ${key}`);
|
|
161
210
|
const blobKey = await this.encodeBlobKey(key);
|
|
162
211
|
span.setAttributes({ key, blobKey });
|
|
163
212
|
const blob = await this.tracer.withActiveSpan("blobStore.get", async (blobGetSpan) => {
|
|
@@ -170,16 +219,13 @@ var NetlifyCacheHandler = class {
|
|
|
170
219
|
span.addEvent("Cache miss", { key, blobKey });
|
|
171
220
|
return null;
|
|
172
221
|
}
|
|
173
|
-
if (process.env.NETLIFY_NEXT_PERF_DEBUG) {
|
|
174
|
-
const blobSize = JSON.stringify(blob).length;
|
|
175
|
-
span.addEvent(`Blob size ${blobSize}`);
|
|
176
|
-
}
|
|
177
222
|
const staleByTags = await this.checkCacheEntryStaleByTags(blob, ctx.tags, ctx.softTags);
|
|
178
223
|
if (staleByTags) {
|
|
179
224
|
span.addEvent("Stale", { staleByTags });
|
|
180
225
|
return null;
|
|
181
226
|
}
|
|
182
227
|
this.captureResponseCacheLastModified(blob, key, span);
|
|
228
|
+
this.captureCacheTags(blob.value, key);
|
|
183
229
|
switch (blob.value?.kind) {
|
|
184
230
|
case "FETCH":
|
|
185
231
|
span.addEvent("FETCH", { lastModified: blob.lastModified, revalidate: ctx.revalidate });
|
|
@@ -198,33 +244,65 @@ var NetlifyCacheHandler = class {
|
|
|
198
244
|
}
|
|
199
245
|
};
|
|
200
246
|
}
|
|
201
|
-
case "PAGE":
|
|
247
|
+
case "PAGE": {
|
|
202
248
|
span.addEvent("PAGE", { lastModified: blob.lastModified });
|
|
249
|
+
const { revalidate, ...restOfPageValue } = blob.value;
|
|
250
|
+
await this.injectEntryToPrerenderManifest(key, revalidate);
|
|
203
251
|
return {
|
|
204
252
|
lastModified: blob.lastModified,
|
|
205
|
-
value:
|
|
253
|
+
value: restOfPageValue
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
case "APP_PAGE": {
|
|
257
|
+
span.addEvent("APP_PAGE", { lastModified: blob.lastModified });
|
|
258
|
+
const { revalidate, rscData, ...restOfPageValue } = blob.value;
|
|
259
|
+
await this.injectEntryToPrerenderManifest(key, revalidate);
|
|
260
|
+
return {
|
|
261
|
+
lastModified: blob.lastModified,
|
|
262
|
+
value: {
|
|
263
|
+
...restOfPageValue,
|
|
264
|
+
rscData: rscData ? import_node_buffer.Buffer.from(rscData, "base64") : void 0
|
|
265
|
+
}
|
|
206
266
|
};
|
|
267
|
+
}
|
|
207
268
|
default:
|
|
208
269
|
span.recordException(new Error(`Unknown cache entry kind: ${blob.value?.kind}`));
|
|
209
270
|
}
|
|
210
271
|
return null;
|
|
211
272
|
});
|
|
212
273
|
}
|
|
274
|
+
transformToStorableObject(data, context) {
|
|
275
|
+
if (data?.kind === "ROUTE") {
|
|
276
|
+
return {
|
|
277
|
+
...data,
|
|
278
|
+
revalidate: context.revalidate,
|
|
279
|
+
body: data.body.toString("base64")
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
if (data?.kind === "PAGE") {
|
|
283
|
+
return {
|
|
284
|
+
...data,
|
|
285
|
+
revalidate: context.revalidate
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
if (data?.kind === "APP_PAGE") {
|
|
289
|
+
return {
|
|
290
|
+
...data,
|
|
291
|
+
revalidate: context.revalidate,
|
|
292
|
+
rscData: data.rscData?.toString("base64")
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
return data;
|
|
296
|
+
}
|
|
213
297
|
async set(...args) {
|
|
214
298
|
return this.tracer.withActiveSpan("set cache key", async (span) => {
|
|
215
299
|
const [key, data, context] = args;
|
|
216
300
|
const blobKey = await this.encodeBlobKey(key);
|
|
217
301
|
const lastModified = Date.now();
|
|
218
302
|
span.setAttributes({ key, lastModified, blobKey });
|
|
219
|
-
|
|
220
|
-
const value = data
|
|
221
|
-
|
|
222
|
-
{
|
|
223
|
-
...data,
|
|
224
|
-
revalidate: context.revalidate,
|
|
225
|
-
body: data.body.toString("base64")
|
|
226
|
-
}
|
|
227
|
-
) : data;
|
|
303
|
+
(0, import_request_context.getLogger)().debug(`[NetlifyCacheHandler.set]: ${key}`);
|
|
304
|
+
const value = this.transformToStorableObject(data, context);
|
|
305
|
+
this.captureCacheTags(value, key);
|
|
228
306
|
await this.blobStore.setJSON(blobKey, {
|
|
229
307
|
lastModified,
|
|
230
308
|
value
|
|
@@ -233,17 +311,28 @@ var NetlifyCacheHandler = class {
|
|
|
233
311
|
const requestContext = (0, import_request_context.getRequestContext)();
|
|
234
312
|
if (requestContext?.didPagesRouterOnDemandRevalidate) {
|
|
235
313
|
const tag = `_N_T_${key === "/index" ? "/" : key}`;
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
314
|
+
(0, import_request_context.getLogger)().debug(`Purging CDN cache for: [${tag}]`);
|
|
315
|
+
requestContext.trackBackgroundWork(
|
|
316
|
+
purgeCache({ tags: [tag] }).catch((error) => {
|
|
317
|
+
(0, import_request_context.getLogger)().withError(error).error(`[NetlifyCacheHandler]: Purging the cache for tag ${tag} failed`);
|
|
318
|
+
})
|
|
319
|
+
);
|
|
240
320
|
}
|
|
241
321
|
}
|
|
242
322
|
});
|
|
243
323
|
}
|
|
244
324
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
245
325
|
async revalidateTag(tagOrTags, ...args) {
|
|
246
|
-
|
|
326
|
+
const revalidateTagPromise = this.doRevalidateTag(tagOrTags, ...args);
|
|
327
|
+
const requestContext = (0, import_request_context.getRequestContext)();
|
|
328
|
+
if (requestContext) {
|
|
329
|
+
requestContext.trackBackgroundWork(revalidateTagPromise);
|
|
330
|
+
}
|
|
331
|
+
return revalidateTagPromise;
|
|
332
|
+
}
|
|
333
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
334
|
+
async doRevalidateTag(tagOrTags, ...args) {
|
|
335
|
+
(0, import_request_context.getLogger)().withFields({ tagOrTags, args }).debug("NetlifyCacheHandler.revalidateTag");
|
|
247
336
|
const tags = Array.isArray(tagOrTags) ? tagOrTags : [tagOrTags];
|
|
248
337
|
const data = {
|
|
249
338
|
revalidatedAt: Date.now()
|
|
@@ -253,12 +342,12 @@ var NetlifyCacheHandler = class {
|
|
|
253
342
|
try {
|
|
254
343
|
await this.blobStore.setJSON(await this.encodeBlobKey(tag), data);
|
|
255
344
|
} catch (error) {
|
|
256
|
-
|
|
345
|
+
(0, import_request_context.getLogger)().withError(error).log(`Failed to update tag manifest for ${tag}`);
|
|
257
346
|
}
|
|
258
347
|
})
|
|
259
348
|
);
|
|
260
|
-
purgeCache({ tags }).catch((error) => {
|
|
261
|
-
|
|
349
|
+
await purgeCache({ tags }).catch((error) => {
|
|
350
|
+
(0, import_request_context.getLogger)().withError(error).error(`[NetlifyCacheHandler]: Purging the cache for tags ${tags.join(", ")} failed`);
|
|
262
351
|
});
|
|
263
352
|
}
|
|
264
353
|
resetRequestCache() {
|
|
@@ -271,7 +360,7 @@ var NetlifyCacheHandler = class {
|
|
|
271
360
|
let cacheTags = [];
|
|
272
361
|
if (cacheEntry.value?.kind === "FETCH") {
|
|
273
362
|
cacheTags = [...tags, ...softTags];
|
|
274
|
-
} else if (cacheEntry.value?.kind === "PAGE" || cacheEntry.value?.kind === "ROUTE") {
|
|
363
|
+
} else if (cacheEntry.value?.kind === "PAGE" || cacheEntry.value?.kind === "APP_PAGE" || cacheEntry.value?.kind === "ROUTE") {
|
|
275
364
|
cacheTags = cacheEntry.value.headers?.[import_constants.NEXT_CACHE_TAGS_HEADER]?.split(",") || [];
|
|
276
365
|
} else {
|
|
277
366
|
return false;
|
|
@@ -21,21 +21,94 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
21
21
|
var request_context_exports = {};
|
|
22
22
|
__export(request_context_exports, {
|
|
23
23
|
createRequestContext: () => createRequestContext,
|
|
24
|
+
getLogger: () => getLogger,
|
|
24
25
|
getRequestContext: () => getRequestContext,
|
|
25
26
|
runWithRequestContext: () => runWithRequestContext
|
|
26
27
|
});
|
|
27
28
|
module.exports = __toCommonJS(request_context_exports);
|
|
28
29
|
var import_node_async_hooks = require("node:async_hooks");
|
|
29
|
-
|
|
30
|
+
|
|
31
|
+
// node_modules/@netlify/functions/dist/chunk-HYMERDCV.mjs
|
|
32
|
+
var import_process = require("process");
|
|
33
|
+
var systemLogTag = "__nfSystemLog";
|
|
34
|
+
var serializeError = (error) => {
|
|
35
|
+
const cause = error?.cause instanceof Error ? serializeError(error.cause) : error.cause;
|
|
36
|
+
return {
|
|
37
|
+
error: error.message,
|
|
38
|
+
error_cause: cause,
|
|
39
|
+
error_stack: error.stack
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
var LogLevel = /* @__PURE__ */ ((LogLevel2) => {
|
|
43
|
+
LogLevel2[LogLevel2["Debug"] = 1] = "Debug";
|
|
44
|
+
LogLevel2[LogLevel2["Log"] = 2] = "Log";
|
|
45
|
+
LogLevel2[LogLevel2["Error"] = 3] = "Error";
|
|
46
|
+
return LogLevel2;
|
|
47
|
+
})(LogLevel || {});
|
|
48
|
+
var SystemLogger = class _SystemLogger {
|
|
49
|
+
fields;
|
|
50
|
+
logLevel;
|
|
51
|
+
constructor(fields = {}, logLevel = 2) {
|
|
52
|
+
this.fields = fields;
|
|
53
|
+
this.logLevel = logLevel;
|
|
54
|
+
}
|
|
55
|
+
doLog(logger, message) {
|
|
56
|
+
if (import_process.env.NETLIFY_DEV && !import_process.env.NETLIFY_ENABLE_SYSTEM_LOGGING) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
logger(systemLogTag, JSON.stringify({ msg: message, fields: this.fields }));
|
|
60
|
+
}
|
|
61
|
+
log(message) {
|
|
62
|
+
if (this.logLevel > 2) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
this.doLog(console.log, message);
|
|
66
|
+
}
|
|
67
|
+
debug(message) {
|
|
68
|
+
if (this.logLevel > 1) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
this.doLog(console.debug, message);
|
|
72
|
+
}
|
|
73
|
+
error(message) {
|
|
74
|
+
if (this.logLevel > 3) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
this.doLog(console.error, message);
|
|
78
|
+
}
|
|
79
|
+
withLogLevel(level) {
|
|
80
|
+
return new _SystemLogger(this.fields, level);
|
|
81
|
+
}
|
|
82
|
+
withFields(fields) {
|
|
83
|
+
return new _SystemLogger(
|
|
84
|
+
{
|
|
85
|
+
...this.fields,
|
|
86
|
+
...fields
|
|
87
|
+
},
|
|
88
|
+
this.logLevel
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
withError(error) {
|
|
92
|
+
const fields = error instanceof Error ? serializeError(error) : { error };
|
|
93
|
+
return this.withFields(fields);
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
var systemLogger = new SystemLogger();
|
|
97
|
+
|
|
98
|
+
// src/run/handlers/request-context.cts
|
|
99
|
+
function createRequestContext(request) {
|
|
30
100
|
const backgroundWorkPromises = [];
|
|
31
101
|
return {
|
|
32
|
-
debug,
|
|
102
|
+
captureServerTiming: request?.headers.has("x-next-debug-logging") ?? false,
|
|
33
103
|
trackBackgroundWork: (promise) => {
|
|
34
104
|
backgroundWorkPromises.push(promise);
|
|
35
105
|
},
|
|
36
106
|
get backgroundWorkPromise() {
|
|
37
107
|
return Promise.allSettled(backgroundWorkPromises);
|
|
38
|
-
}
|
|
108
|
+
},
|
|
109
|
+
logger: systemLogger.withLogLevel(
|
|
110
|
+
request?.headers.has("x-nf-debug-logging") || request?.headers.has("x-next-debug-logging") ? LogLevel.Debug : LogLevel.Log
|
|
111
|
+
)
|
|
39
112
|
};
|
|
40
113
|
}
|
|
41
114
|
var REQUEST_CONTEXT_GLOBAL_KEY = Symbol.for("nf-request-context-async-local-storage");
|
|
@@ -57,9 +130,13 @@ var getRequestContext = () => getRequestContextAsyncLocalStorage().getStore();
|
|
|
57
130
|
function runWithRequestContext(requestContext, fn) {
|
|
58
131
|
return getRequestContextAsyncLocalStorage().run(requestContext, fn);
|
|
59
132
|
}
|
|
133
|
+
function getLogger() {
|
|
134
|
+
return getRequestContext()?.logger ?? systemLogger;
|
|
135
|
+
}
|
|
60
136
|
// Annotate the CommonJS export names for ESM import in node:
|
|
61
137
|
0 && (module.exports = {
|
|
62
138
|
createRequestContext,
|
|
139
|
+
getLogger,
|
|
63
140
|
getRequestContext,
|
|
64
141
|
runWithRequestContext
|
|
65
142
|
});
|
|
@@ -3091,7 +3091,6 @@ function toComputeResponse(res) {
|
|
|
3091
3091
|
}
|
|
3092
3092
|
|
|
3093
3093
|
// src/run/handlers/server.ts
|
|
3094
|
-
import { getTagsManifest } from "../config.js";
|
|
3095
3094
|
import {
|
|
3096
3095
|
adjustDateHeader,
|
|
3097
3096
|
setCacheControlHeaders,
|
|
@@ -3100,13 +3099,11 @@ import {
|
|
|
3100
3099
|
setVaryHeaders
|
|
3101
3100
|
} from "../headers.js";
|
|
3102
3101
|
import { nextResponseProxy } from "../revalidate.js";
|
|
3103
|
-
import {
|
|
3104
|
-
import { createRequestContext, getRequestContext } from "./request-context.cjs";
|
|
3102
|
+
import { createRequestContext, getLogger, getRequestContext } from "./request-context.cjs";
|
|
3105
3103
|
import { getTracer } from "./tracer.cjs";
|
|
3106
3104
|
var nextImportPromise = import("../next.cjs");
|
|
3107
3105
|
var nextHandler;
|
|
3108
3106
|
var nextConfig;
|
|
3109
|
-
var tagsManifest;
|
|
3110
3107
|
var disableFaultyTransferEncodingHandling = (res) => {
|
|
3111
3108
|
const originalStoreHeader = res._storeHeader;
|
|
3112
3109
|
res._storeHeader = function _storeHeader(firstLine, headers) {
|
|
@@ -3122,22 +3119,11 @@ var disableFaultyTransferEncodingHandling = (res) => {
|
|
|
3122
3119
|
};
|
|
3123
3120
|
var server_default = async (request, context) => {
|
|
3124
3121
|
const tracer = getTracer();
|
|
3125
|
-
const withPerfDebugSpan = process.env.NETLIFY_NEXT_PERF_DEBUG ? tracer.withActiveSpan.bind(tracer) : (_name, fn) => fn();
|
|
3126
3122
|
if (!nextHandler) {
|
|
3127
|
-
await tracer.withActiveSpan("initialize next server", async (
|
|
3123
|
+
await tracer.withActiveSpan("initialize next server", async () => {
|
|
3128
3124
|
const { getRunConfig, setRunConfig } = await import("../config.js");
|
|
3129
3125
|
nextConfig = await getRunConfig();
|
|
3130
3126
|
setRunConfig(nextConfig);
|
|
3131
|
-
tagsManifest = await getTagsManifest();
|
|
3132
|
-
span.setAttributes(
|
|
3133
|
-
Object.entries(tagsManifest).reduce(
|
|
3134
|
-
(acc, [key, value]) => {
|
|
3135
|
-
acc[`tagsManifest.${key}`] = value;
|
|
3136
|
-
return acc;
|
|
3137
|
-
},
|
|
3138
|
-
{}
|
|
3139
|
-
)
|
|
3140
|
-
);
|
|
3141
3127
|
const { getMockedRequestHandlers } = await nextImportPromise;
|
|
3142
3128
|
const url = new URL(request.url);
|
|
3143
3129
|
[nextHandler] = await getMockedRequestHandlers({
|
|
@@ -3164,7 +3150,7 @@ var server_default = async (request, context) => {
|
|
|
3164
3150
|
const requestContext = getRequestContext() ?? createRequestContext();
|
|
3165
3151
|
const resProxy = nextResponseProxy(res, requestContext);
|
|
3166
3152
|
const nextHandlerPromise = nextHandler(req, resProxy).catch((error) => {
|
|
3167
|
-
|
|
3153
|
+
getLogger().withError(error).error("next handler error");
|
|
3168
3154
|
console.error(error);
|
|
3169
3155
|
resProxy.statusCode = 500;
|
|
3170
3156
|
span.setAttribute("http.status_code", 500);
|
|
@@ -3175,8 +3161,9 @@ var server_default = async (request, context) => {
|
|
|
3175
3161
|
span.setAttribute("responseCacheKey", requestContext.responseCacheKey);
|
|
3176
3162
|
}
|
|
3177
3163
|
await adjustDateHeader({ headers: response.headers, request, span, tracer, requestContext });
|
|
3178
|
-
|
|
3179
|
-
|
|
3164
|
+
const useDurableCache = context.flags.get("serverless_functions_nextjs_durable_cache_disable") !== true;
|
|
3165
|
+
setCacheControlHeaders(response.headers, request, requestContext, useDurableCache);
|
|
3166
|
+
setCacheTagsHeaders(response.headers, requestContext);
|
|
3180
3167
|
setVaryHeaders(response.headers, request, nextConfig);
|
|
3181
3168
|
setCacheStatusHeader(response.headers);
|
|
3182
3169
|
if (response.status > 300 && response.status < 400 || response.status >= 500) {
|
|
@@ -3188,13 +3175,9 @@ var server_default = async (request, context) => {
|
|
|
3188
3175
|
}
|
|
3189
3176
|
const keepOpenUntilNextFullyRendered = new TransformStream({
|
|
3190
3177
|
async flush() {
|
|
3191
|
-
await
|
|
3192
|
-
await nextHandlerPromise;
|
|
3193
|
-
});
|
|
3178
|
+
await nextHandlerPromise;
|
|
3194
3179
|
if (!context.waitUntil) {
|
|
3195
|
-
await
|
|
3196
|
-
await requestContext.backgroundWorkPromise;
|
|
3197
|
-
});
|
|
3180
|
+
await requestContext.backgroundWorkPromise;
|
|
3198
3181
|
}
|
|
3199
3182
|
}
|
|
3200
3183
|
});
|
|
@@ -856,7 +856,7 @@ function spanHook(span) {
|
|
|
856
856
|
const meta = spanMeta.get(span);
|
|
857
857
|
if (meta) {
|
|
858
858
|
const requestContext = (0, import_request_context.getRequestContext)();
|
|
859
|
-
if (requestContext?.
|
|
859
|
+
if (requestContext?.captureServerTiming) {
|
|
860
860
|
const duration = (typeof endTime === "number" ? endTime : performance.now()) - meta.start;
|
|
861
861
|
const serverTiming = requestContext.serverTiming ?? "";
|
|
862
862
|
const currentRequestSpanCounter = spanCounter.get(requestContext) ?? 1;
|
|
@@ -25421,7 +25421,7 @@ var require_shimmer = __commonJS({
|
|
|
25421
25421
|
function isFunction(funktion) {
|
|
25422
25422
|
return typeof funktion === "function";
|
|
25423
25423
|
}
|
|
25424
|
-
var
|
|
25424
|
+
var logger = console.error.bind(console);
|
|
25425
25425
|
function defineProperty(obj, name2, value) {
|
|
25426
25426
|
var enumerable = !!obj[name2] && obj.propertyIsEnumerable(name2);
|
|
25427
25427
|
Object.defineProperty(obj, name2, {
|
|
@@ -25433,22 +25433,22 @@ var require_shimmer = __commonJS({
|
|
|
25433
25433
|
}
|
|
25434
25434
|
function shimmer(options) {
|
|
25435
25435
|
if (options && options.logger) {
|
|
25436
|
-
if (!isFunction(options.logger))
|
|
25437
|
-
else
|
|
25436
|
+
if (!isFunction(options.logger)) logger("new logger isn't a function, not replacing");
|
|
25437
|
+
else logger = options.logger;
|
|
25438
25438
|
}
|
|
25439
25439
|
}
|
|
25440
25440
|
function wrap(nodule, name2, wrapper) {
|
|
25441
25441
|
if (!nodule || !nodule[name2]) {
|
|
25442
|
-
|
|
25442
|
+
logger("no original function " + name2 + " to wrap");
|
|
25443
25443
|
return;
|
|
25444
25444
|
}
|
|
25445
25445
|
if (!wrapper) {
|
|
25446
|
-
|
|
25447
|
-
|
|
25446
|
+
logger("no wrapper function");
|
|
25447
|
+
logger(new Error().stack);
|
|
25448
25448
|
return;
|
|
25449
25449
|
}
|
|
25450
25450
|
if (!isFunction(nodule[name2]) || !isFunction(wrapper)) {
|
|
25451
|
-
|
|
25451
|
+
logger("original object and wrapper must be functions");
|
|
25452
25452
|
return;
|
|
25453
25453
|
}
|
|
25454
25454
|
var original = nodule[name2];
|
|
@@ -25463,14 +25463,14 @@ var require_shimmer = __commonJS({
|
|
|
25463
25463
|
}
|
|
25464
25464
|
function massWrap(nodules, names, wrapper) {
|
|
25465
25465
|
if (!nodules) {
|
|
25466
|
-
|
|
25467
|
-
|
|
25466
|
+
logger("must provide one or more modules to patch");
|
|
25467
|
+
logger(new Error().stack);
|
|
25468
25468
|
return;
|
|
25469
25469
|
} else if (!Array.isArray(nodules)) {
|
|
25470
25470
|
nodules = [nodules];
|
|
25471
25471
|
}
|
|
25472
25472
|
if (!(names && Array.isArray(names))) {
|
|
25473
|
-
|
|
25473
|
+
logger("must provide one or more functions to wrap on modules");
|
|
25474
25474
|
return;
|
|
25475
25475
|
}
|
|
25476
25476
|
nodules.forEach(function(nodule) {
|
|
@@ -25481,26 +25481,26 @@ var require_shimmer = __commonJS({
|
|
|
25481
25481
|
}
|
|
25482
25482
|
function unwrap(nodule, name2) {
|
|
25483
25483
|
if (!nodule || !nodule[name2]) {
|
|
25484
|
-
|
|
25485
|
-
|
|
25484
|
+
logger("no function to unwrap.");
|
|
25485
|
+
logger(new Error().stack);
|
|
25486
25486
|
return;
|
|
25487
25487
|
}
|
|
25488
25488
|
if (!nodule[name2].__unwrap) {
|
|
25489
|
-
|
|
25489
|
+
logger("no original to unwrap to -- has " + name2 + " already been unwrapped?");
|
|
25490
25490
|
} else {
|
|
25491
25491
|
return nodule[name2].__unwrap();
|
|
25492
25492
|
}
|
|
25493
25493
|
}
|
|
25494
25494
|
function massUnwrap(nodules, names) {
|
|
25495
25495
|
if (!nodules) {
|
|
25496
|
-
|
|
25497
|
-
|
|
25496
|
+
logger("must provide one or more modules to patch");
|
|
25497
|
+
logger(new Error().stack);
|
|
25498
25498
|
return;
|
|
25499
25499
|
} else if (!Array.isArray(nodules)) {
|
|
25500
25500
|
nodules = [nodules];
|
|
25501
25501
|
}
|
|
25502
25502
|
if (!(names && Array.isArray(names))) {
|
|
25503
|
-
|
|
25503
|
+
logger("must provide one or more functions to unwrap on modules");
|
|
25504
25504
|
return;
|
|
25505
25505
|
}
|
|
25506
25506
|
nodules.forEach(function(nodule) {
|
|
@@ -39342,12 +39342,12 @@ var require_logging = __commonJS({
|
|
|
39342
39342
|
break;
|
|
39343
39343
|
default:
|
|
39344
39344
|
}
|
|
39345
|
-
var
|
|
39345
|
+
var getLogger2 = () => {
|
|
39346
39346
|
return _logger;
|
|
39347
39347
|
};
|
|
39348
|
-
exports2.getLogger =
|
|
39349
|
-
var setLogger = (
|
|
39350
|
-
_logger =
|
|
39348
|
+
exports2.getLogger = getLogger2;
|
|
39349
|
+
var setLogger = (logger) => {
|
|
39350
|
+
_logger = logger;
|
|
39351
39351
|
};
|
|
39352
39352
|
exports2.setLogger = setLogger;
|
|
39353
39353
|
var setLoggerVerbosity = (verbosity) => {
|
|
@@ -45546,7 +45546,24 @@ var require_parse = __commonJS({
|
|
|
45546
45546
|
else
|
|
45547
45547
|
target.push([start = parseId(next()), skip("to", true) ? parseId(next()) : start]);
|
|
45548
45548
|
} while (skip(",", true));
|
|
45549
|
-
|
|
45549
|
+
var dummy = { options: void 0 };
|
|
45550
|
+
dummy.setOption = function(name2, value) {
|
|
45551
|
+
if (this.options === void 0) this.options = {};
|
|
45552
|
+
this.options[name2] = value;
|
|
45553
|
+
};
|
|
45554
|
+
ifBlock(
|
|
45555
|
+
dummy,
|
|
45556
|
+
function parseRange_block(token3) {
|
|
45557
|
+
if (token3 === "option") {
|
|
45558
|
+
parseOption(dummy, token3);
|
|
45559
|
+
skip(";");
|
|
45560
|
+
} else
|
|
45561
|
+
throw illegal(token3);
|
|
45562
|
+
},
|
|
45563
|
+
function parseRange_line() {
|
|
45564
|
+
parseInlineOptions(dummy);
|
|
45565
|
+
}
|
|
45566
|
+
);
|
|
45550
45567
|
}
|
|
45551
45568
|
function parseNumber(token2, insideTryCatch) {
|
|
45552
45569
|
var sign = 1;
|
|
@@ -56753,8 +56770,8 @@ var require_src31 = __commonJS({
|
|
|
56753
56770
|
throw new Error("Not available in this library. Use @grpc/proto-loader and loadPackageDefinition instead");
|
|
56754
56771
|
};
|
|
56755
56772
|
exports2.load = load;
|
|
56756
|
-
var setLogger = (
|
|
56757
|
-
logging.setLogger(
|
|
56773
|
+
var setLogger = (logger) => {
|
|
56774
|
+
logging.setLogger(logger);
|
|
56758
56775
|
};
|
|
56759
56776
|
exports2.setLogger = setLogger;
|
|
56760
56777
|
var setLogVerbosity = (verbosity) => {
|
|
@@ -67215,10 +67232,10 @@ var require_sdk = __commonJS({
|
|
|
67215
67232
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
67216
67233
|
new sdk_trace_base_1.BatchSpanProcessor(configuration.traceExporter)
|
|
67217
67234
|
);
|
|
67218
|
-
const
|
|
67235
|
+
const spanProcessors = (_e = configuration.spanProcessors) !== null && _e !== void 0 ? _e : [spanProcessor];
|
|
67219
67236
|
this._tracerProviderConfig = {
|
|
67220
67237
|
tracerConfig: tracerProviderConfig,
|
|
67221
|
-
spanProcessors
|
|
67238
|
+
spanProcessors,
|
|
67222
67239
|
contextManager: configuration.contextManager,
|
|
67223
67240
|
textMapPropagator: configuration.textMapPropagator
|
|
67224
67241
|
};
|
|
@@ -67365,60 +67382,20 @@ var import_resources = __toESM(require_src5(), 1);
|
|
|
67365
67382
|
var import_sdk_node = __toESM(require_src36(), 1);
|
|
67366
67383
|
var import_sdk_trace_node = __toESM(require_src20(), 1);
|
|
67367
67384
|
var import_semantic_conventions = __toESM(require_src(), 1);
|
|
67368
|
-
import {
|
|
67385
|
+
import { getLogger } from "./request-context.cjs";
|
|
67369
67386
|
var {
|
|
67370
67387
|
default: { version, name }
|
|
67371
|
-
} = await import("../../esm-chunks/package-
|
|
67372
|
-
var spanProcessors = [];
|
|
67373
|
-
if (process.env.NETLIFY_OTLP_TRACE_EXPORTER_URL) {
|
|
67374
|
-
spanProcessors.push(
|
|
67375
|
-
new import_sdk_trace_node.SimpleSpanProcessor(
|
|
67376
|
-
new import_exporter_trace_otlp_http.OTLPTraceExporter({
|
|
67377
|
-
url: process.env.NETLIFY_OTLP_TRACE_EXPORTER_URL
|
|
67378
|
-
})
|
|
67379
|
-
)
|
|
67380
|
-
);
|
|
67381
|
-
}
|
|
67382
|
-
if (process.env.NETLIFY_NEXT_PERF_DEBUG) {
|
|
67383
|
-
class CompactConsoleExporter {
|
|
67384
|
-
export(spans, resultCallback) {
|
|
67385
|
-
return this._sendSpans(spans, resultCallback);
|
|
67386
|
-
}
|
|
67387
|
-
shutdown() {
|
|
67388
|
-
this._sendSpans([]);
|
|
67389
|
-
return this.forceFlush();
|
|
67390
|
-
}
|
|
67391
|
-
forceFlush() {
|
|
67392
|
-
return Promise.resolve();
|
|
67393
|
-
}
|
|
67394
|
-
_sendSpans(spans, done) {
|
|
67395
|
-
for (const span of spans) {
|
|
67396
|
-
const startDate = new Date(span.startTime[0] * 10 ** 3 + span.startTime[1] / 10 ** 6);
|
|
67397
|
-
const durationS = span.duration[0] + span.duration[1] / 10 ** 9;
|
|
67398
|
-
console.log(
|
|
67399
|
-
`[Trace ${span.spanContext().traceId}] ${`"${span.name}"`.padEnd(
|
|
67400
|
-
60,
|
|
67401
|
-
" "
|
|
67402
|
-
)} start=${startDate.toISOString()} dur=${durationS.toFixed(3)}s${span.events.length === 0 ? "" : ` events=[${span.events.map(
|
|
67403
|
-
(event) => `{ name="${event.name}", time=${new Date(
|
|
67404
|
-
event.time[0] * 10 ** 3 + event.time[1] / 10 ** 6
|
|
67405
|
-
).toISOString()}}`
|
|
67406
|
-
).join(", ")}]`}`
|
|
67407
|
-
);
|
|
67408
|
-
}
|
|
67409
|
-
if (done) {
|
|
67410
|
-
return done({ code: 0 });
|
|
67411
|
-
}
|
|
67412
|
-
}
|
|
67413
|
-
}
|
|
67414
|
-
spanProcessors.push(new import_sdk_trace_node.SimpleSpanProcessor(new CompactConsoleExporter()));
|
|
67415
|
-
}
|
|
67388
|
+
} = await import("../../esm-chunks/package-C5ZXMRQF.js");
|
|
67416
67389
|
var sdk = new import_sdk_node.NodeSDK({
|
|
67417
67390
|
resource: new import_resources.Resource({
|
|
67418
67391
|
[import_semantic_conventions.SEMRESATTRS_SERVICE_NAME]: name,
|
|
67419
67392
|
[import_semantic_conventions.SEMRESATTRS_SERVICE_VERSION]: version
|
|
67420
67393
|
}),
|
|
67421
|
-
|
|
67394
|
+
spanProcessor: new import_sdk_trace_node.SimpleSpanProcessor(
|
|
67395
|
+
new import_exporter_trace_otlp_http.OTLPTraceExporter({
|
|
67396
|
+
url: process.env.NETLIFY_OTLP_TRACE_EXPORTER_URL
|
|
67397
|
+
})
|
|
67398
|
+
)
|
|
67422
67399
|
});
|
|
67423
67400
|
var tracing_default = sdk;
|
|
67424
67401
|
process.on("SIGTERM", () => {
|
|
@@ -67426,7 +67403,7 @@ process.on("SIGTERM", () => {
|
|
|
67426
67403
|
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
67427
67404
|
() => {
|
|
67428
67405
|
},
|
|
67429
|
-
(error) =>
|
|
67406
|
+
(error) => getLogger().withError(error).log("Error shutting down OpenTelemetry NodeSDK")
|
|
67430
67407
|
).finally(() => process.exit(0));
|
|
67431
67408
|
});
|
|
67432
67409
|
export {
|