Skip to content

Commit 8c30a9d

Browse files
authored
L-1016 Do not warn about missing environment variables in development (#12)
1 parent 0bc83a2 commit 8c30a9d

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

src/withLogtail.ts

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,25 @@ declare global {
2020
var EdgeRuntime: string;
2121
}
2222

23+
function warnAboutMissingEnvironmentVariables() {
24+
let checkEnabled = process.env.NODE_ENV !== 'development';
25+
if (process.env.LOGTAIL_CHECK_ENV_VARS?.toLowerCase() === 'true' || process.env.LOGTAIL_CHECK_ENV_VARS === '1') {
26+
checkEnabled = true;
27+
}
28+
if (process.env.LOGTAIL_CHECK_ENV_VARS?.toLowerCase() === 'false' || process.env.LOGTAIL_CHECK_ENV_VARS === '0') {
29+
checkEnabled = false;
30+
}
31+
32+
if (checkEnabled) {
33+
const log = new Logger();
34+
log.warn(
35+
'logtail: Envvars not detected. If this is production please see https://github.com/logtail/logtail-nextjs for help'
36+
);
37+
log.warn('logtail: Sending Web Vitals to /dev/null');
38+
log.warn('logtail: Sending logs to console');
39+
}
40+
}
41+
2342
export function withLogtailNextConfig(nextConfig: NextConfig): NextConfig {
2443
return {
2544
...nextConfig,
@@ -28,12 +47,8 @@ export function withLogtailNextConfig(nextConfig: NextConfig): NextConfig {
2847

2948
const proxyEndpoint = config.getProxyEndpoint();
3049
if (!proxyEndpoint) {
31-
const log = new Logger();
32-
log.warn(
33-
'logtail: Envvars not detected. If this is production please see https://github.com/logtail/logtail-nextjs for help'
34-
);
35-
log.warn('logtail: Sending Web Vitals to /dev/null');
36-
log.warn('logtail: Sending logs to console');
50+
warnAboutMissingEnvironmentVariables();
51+
3752
return rewrites || []; // nothing to do
3853
}
3954

0 commit comments

Comments
 (0)