Skip to content

Commit

Permalink
feat: add new env, new conditions for env checks and logging
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
solidovic authored Feb 11, 2025
1 parent 2a306ac commit 76d08da
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 10 deletions.
1 change: 1 addition & 0 deletions global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ declare module 'next/config' {
publicRuntimeConfig: {
basePath: string | undefined;
developmentMode: boolean;
collectMetrics: boolean;
};
};

Expand Down
6 changes: 2 additions & 4 deletions next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ import { startupCheckRPCs } from './scripts/startup-checks/rpc.mjs';
logEnvironmentVariables();
buildDynamics();

if (
process.env.RUN_STARTUP_CHECKS === 'true' &&
typeof window === 'undefined'
) {
if (process.env.RUN_STARTUP_CHECKS === 'true') {
void startupCheckRPCs();
}

Expand Down Expand Up @@ -179,5 +176,6 @@ export default withBundleAnalyzer({
publicRuntimeConfig: {
basePath,
developmentMode,
collectMetrics: process.env.COLLECT_METRICS === 'true',
},
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"build": "NODE_OPTIONS='--no-warnings=ExperimentalWarning' next build",
"build:analyze": "ANALYZE_BUNDLE=true yarn build",
"build:ipfs": "IPFS_MODE=true yarn build && IPFS_MODE=true next export",
"start": "NODE_ENV=production RUN_STARTUP_CHECKS=true node -r next-logger --no-warnings=ExperimentalWarning server.mjs",
"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",
"lint": "eslint --ext ts,tsx,js,mjs .",
"lint:fix": "yarn lint --fix",
"types": "tsc --noEmit",
Expand Down
5 changes: 4 additions & 1 deletion scripts/log-environment-variables.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,8 @@ export const logSecretEnvironmentVariables = () => {

export const logEnvironmentVariables = () => {
logOpenEnvironmentVariables();
logSecretEnvironmentVariables();

if (process.env.RUN_SECRET_ENV_LOGGING === 'true') {
logSecretEnvironmentVariables();
}
};
8 changes: 4 additions & 4 deletions utilsApi/metrics/startup-metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import buildInfoJson from 'build-info.json';
import { openKeys } from 'scripts/log-environment-variables.mjs';
import { getRPCChecks } from 'scripts/startup-checks/rpc.mjs';

import { config, secretConfig } from 'config';
import { config } from 'config';
import { METRICS_PREFIX } from 'consts/metrics';

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

if (!rpcChecksResults && !secretConfig.developmentMode) {
if (!rpcChecksResults) {
throw new Error(
'[collectStartupChecksRPCMetrics] getRPCChecks resolved as "null"!',
);
Expand Down Expand Up @@ -60,8 +60,8 @@ const collectEnvInfoMetrics = (registry: Registry): void => {
export const collectStartupMetrics = async (
registry: Registry,
): Promise<void> => {
// conflicts with HMR
if (config.developmentMode) return;
if (!config.collectMetrics) return;

collectEnvInfoMetrics(registry);

collectBuildInfoMetrics({
Expand Down

0 comments on commit 76d08da

Please sign in to comment.