Skip to content

Commit 5a72bfe

Browse files
committed
Add debugging
1 parent a14cdf5 commit 5a72bfe

File tree

2 files changed

+56
-5
lines changed

2 files changed

+56
-5
lines changed

packages/edge-config/src/index.ts

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,21 +63,33 @@ const getFileSystemEdgeConfig = trace(
6363
connection: Connection,
6464
): Promise<EmbeddedEdgeConfig | null> {
6565
// can't optimize non-vercel hosted edge configs
66-
if (connection.type !== 'vercel') return null;
66+
if (connection.type !== 'vercel') {
67+
// eslint-disable-next-line -- debugging
68+
console.log('getFileSystemEdgeConfig: skipping non-vercel');
69+
return null;
70+
}
6771
// can't use fs optimizations outside of lambda
68-
if (!process.env.AWS_LAMBDA_FUNCTION_NAME) return null;
72+
if (!process.env.AWS_LAMBDA_FUNCTION_NAME) {
73+
// eslint-disable-next-line -- debugging
74+
console.log('getFileSystemEdgeConfig: skipping non-lambda');
75+
return null;
76+
}
6977

7078
try {
7179
const content = await readFileTraced(
7280
`/opt/edge-config/${connection.id}.json`,
7381
'utf-8',
7482
);
7583

84+
// eslint-disable-next-line -- debugging
85+
console.log('getFileSystemEdgeConfig: readFileTraced');
7686
return cachedJsonParseTraced(
7787
connection.id,
7888
content,
7989
) as EmbeddedEdgeConfig;
8090
} catch {
91+
// eslint-disable-next-line -- debugging
92+
console.log('getFileSystemEdgeConfig: error -> null');
8193
return null;
8294
}
8395
},
@@ -107,9 +119,13 @@ const getPrivateEdgeConfig = trace(
107119
typeof privateEdgeConfig === 'object' &&
108120
typeof privateEdgeConfig.get === 'function'
109121
) {
122+
// eslint-disable-next-line -- debugging
123+
console.log('getPrivateEdgeConfig: using privateEdgeConfig from symbol');
110124
return privateEdgeConfig.get(connection.id);
111125
}
112126

127+
// eslint-disable-next-line -- debugging
128+
console.log('getPrivateEdgeConfig: skipping');
113129
return null;
114130
},
115131
{
@@ -142,10 +158,20 @@ function createGetInMemoryEdgeConfig(
142158

143159
return trace(
144160
(localOptions) => {
145-
if (localOptions?.consistentRead || !shouldUseDevelopmentCache)
161+
// eslint-disable-next-line -- debugging
162+
console.log(`getInMemoryEdgeConfig: called`);
163+
if (localOptions?.consistentRead || !shouldUseDevelopmentCache) {
164+
// eslint-disable-next-line -- debugging
165+
console.log('getInMemoryEdgeConfig: skipping', {
166+
localOptions,
167+
shouldUseDevelopmentCache,
168+
});
146169
return Promise.resolve(null);
170+
}
147171

148172
if (!latestRequest) {
173+
// eslint-disable-next-line -- debugging
174+
console.log(`getInMemoryEdgeConfig: creating new instance`);
149175
latestRequest = fetchWithCachedResponse(
150176
`${connection.baseUrl}/items?version=${connection.version}`,
151177
{
@@ -183,6 +209,9 @@ function createGetInMemoryEdgeConfig(
183209
latestRequest = null;
184210
},
185211
);
212+
} else {
213+
// eslint-disable-next-line -- debugging
214+
console.log(`getInMemoryEdgeConfig: using existing`);
186215
}
187216

188217
if (!embeddedEdgeConfigPromise) {
@@ -216,7 +245,11 @@ async function getLocalEdgeConfig(
216245
connection: Connection,
217246
options?: EdgeConfigFunctionsOptions,
218247
): Promise<EmbeddedEdgeConfig | null> {
219-
if (options?.consistentRead) return null;
248+
if (options?.consistentRead) {
249+
// eslint-disable-next-line -- debugging
250+
console.log('getLocalEdgeConfig: skipping for consistentRead');
251+
return null;
252+
}
220253

221254
const edgeConfig =
222255
(await getPrivateEdgeConfig(connection)) ||
@@ -368,6 +401,8 @@ export const createClient = trace(
368401
if (localOptions?.consistentRead)
369402
addConsistentReadHeader(localHeaders);
370403

404+
// eslint-disable-next-line -- debugging
405+
console.log('fetching edge config from network');
371406
return fetchWithCachedResponse(
372407
`${baseUrl}/item/${key}?version=${version}`,
373408
{

packages/edge-config/src/utils/io-boundary.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,28 @@ export function withIOBoundary<
2626
F extends (...args: any[]) => Promise<any>,
2727
>(fn: F): F {
2828
async function bounded(this: unknown, ...args: unknown[]): Promise<unknown> {
29+
// eslint-disable-next-line -- debugging
30+
const {
31+
workUnitAsyncStorage,
32+
} = require('next/dist/server/app-render/work-unit-async-storage.external');
33+
34+
const tag = performance.now().toString(16);
35+
// eslint-disable-next-line -- debugging
36+
console.log(`${tag}, withIOBoundary: start`);
2937
const boundary = getCurrentBoundary();
3038
try {
3139
/* eslint-disable @typescript-eslint/no-unsafe-return -- we're wrapping */
32-
return await fn.call(this, ...args);
40+
// eslint-disable-next-line -- debugging
41+
const result = await fn.call(this, ...args);
42+
// eslint-disable-next-line -- debugging
43+
console.log(`${tag}, withIOBoundary: end`);
44+
return result;
3345
} finally {
46+
// eslint-disable-next-line -- debugging
47+
console.log(`${tag}, withIOBoundary: finally`);
3448
await boundary;
49+
// eslint-disable-next-line -- debugging
50+
console.log(`${tag}, withIOBoundary: awaited boundary`);
3551
}
3652
}
3753

0 commit comments

Comments
 (0)