Skip to content

Commit 76d08da

Browse files
authored
feat: add new env, new conditions for env checks and logging
* fix: disable collecting startup metrics on ipfs * feat: add RUN_SECRET_ENV_LOGGING, RUN_METRICS to yarn start * feat: renaming * feat(collectStartupChecksRPCMetrics): remove redundant developmentMode * feat(next.config): remove redundant typeof window === 'undefined' check
1 parent 2a306ac commit 76d08da

File tree

5 files changed

+12
-10
lines changed

5 files changed

+12
-10
lines changed

global.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ declare module 'next/config' {
4646
publicRuntimeConfig: {
4747
basePath: string | undefined;
4848
developmentMode: boolean;
49+
collectMetrics: boolean;
4950
};
5051
};
5152

next.config.mjs

+2-4
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@ import { startupCheckRPCs } from './scripts/startup-checks/rpc.mjs';
77
logEnvironmentVariables();
88
buildDynamics();
99

10-
if (
11-
process.env.RUN_STARTUP_CHECKS === 'true' &&
12-
typeof window === 'undefined'
13-
) {
10+
if (process.env.RUN_STARTUP_CHECKS === 'true') {
1411
void startupCheckRPCs();
1512
}
1613

@@ -179,5 +176,6 @@ export default withBundleAnalyzer({
179176
publicRuntimeConfig: {
180177
basePath,
181178
developmentMode,
179+
collectMetrics: process.env.COLLECT_METRICS === 'true',
182180
},
183181
});

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"build": "NODE_OPTIONS='--no-warnings=ExperimentalWarning' next build",
1111
"build:analyze": "ANALYZE_BUNDLE=true yarn build",
1212
"build:ipfs": "IPFS_MODE=true yarn build && IPFS_MODE=true next export",
13-
"start": "NODE_ENV=production RUN_STARTUP_CHECKS=true node -r next-logger --no-warnings=ExperimentalWarning server.mjs",
13+
"start": "NODE_ENV=production COLLECT_METRICS=true RUN_STARTUP_CHECKS=true RUN_SECRET_ENV_LOGGING=true node -r next-logger --no-warnings=ExperimentalWarning server.mjs",
1414
"lint": "eslint --ext ts,tsx,js,mjs .",
1515
"lint:fix": "yarn lint --fix",
1616
"types": "tsc --noEmit",

scripts/log-environment-variables.mjs

+4-1
Original file line numberDiff line numberDiff line change
@@ -80,5 +80,8 @@ export const logSecretEnvironmentVariables = () => {
8080

8181
export const logEnvironmentVariables = () => {
8282
logOpenEnvironmentVariables();
83-
logSecretEnvironmentVariables();
83+
84+
if (process.env.RUN_SECRET_ENV_LOGGING === 'true') {
85+
logSecretEnvironmentVariables();
86+
}
8487
};

utilsApi/metrics/startup-metrics.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import buildInfoJson from 'build-info.json';
55
import { openKeys } from 'scripts/log-environment-variables.mjs';
66
import { getRPCChecks } from 'scripts/startup-checks/rpc.mjs';
77

8-
import { config, secretConfig } from 'config';
8+
import { config } from 'config';
99
import { METRICS_PREFIX } from 'consts/metrics';
1010

1111
import { StartupChecksRPCMetrics } from './startup-checks';
@@ -19,7 +19,7 @@ const collectStartupChecksRPCMetrics = async (
1919
// Await the promise if it's still in progress
2020
const rpcChecksResults = await getRPCChecks();
2121

22-
if (!rpcChecksResults && !secretConfig.developmentMode) {
22+
if (!rpcChecksResults) {
2323
throw new Error(
2424
'[collectStartupChecksRPCMetrics] getRPCChecks resolved as "null"!',
2525
);
@@ -60,8 +60,8 @@ const collectEnvInfoMetrics = (registry: Registry): void => {
6060
export const collectStartupMetrics = async (
6161
registry: Registry,
6262
): Promise<void> => {
63-
// conflicts with HMR
64-
if (config.developmentMode) return;
63+
if (!config.collectMetrics) return;
64+
6565
collectEnvInfoMetrics(registry);
6666

6767
collectBuildInfoMetrics({

0 commit comments

Comments
 (0)