Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to hide build warnings for local development #6

Closed
jakeleventhal opened this issue Aug 25, 2023 · 24 comments · Fixed by #12, #14 or #15
Closed

How to hide build warnings for local development #6

jakeleventhal opened this issue Aug 25, 2023 · 24 comments · Fixed by #12, #14 or #15

Comments

@jakeleventhal
Copy link

warn - logtail: Envvars not detected. If this is production please see https://github.com/logtailhq/next-logtail for help
warn - logtail: Sending Web Vitals to /dev/null
warn - logtail: Sending logs to console

whenever i build my app locally, i get the following errors. How do i suppress these?

@curusarn
Copy link
Contributor

curusarn commented Sep 4, 2023

Hi @jakeleventhal,

Thank you for raising this!

These warnings are supposed to help people avoid forgetting to specify important ENV vars in prod and losing logs. We want to be transparent to prevent mistakes. We could add another ENV variable to suppress these warnings.

Are the warnings annoying enough during development that you want to disable them?

Thanks again for reaching out.

@jakeleventhal
Copy link
Author

Yes @curusarn, i think maybe if node_env is not production they should be suppressed

@alexmarmon
Copy link

@curusarn I'm with @jakeleventhal on this and would love a way to suppress the warnings

@curusarn
Copy link
Contributor

Thank you for the feedback!

We're tracking the issue internally. We should get to fixing it soon.
I'll make sure to keep you updated here!

@PetrHeinz
Copy link
Member

Hello @jakeleventhal and @alexmarmon, thanks for pushing this! 🙌

Just released v0.1.2 that solves the issue by suppressing the warning about missing ENV vars in development environment. You can even override this behavior via LOGTAIL_CHECK_ENV_VARS env var. For details, see #12

Hope that helps! 🙂

@jakeleventhal
Copy link
Author

On my local environment with 0.1.2 i get this output with no env vars detected:

warn - logtail: Envvars not detected. If this is production please see https://github.com/logtail/logtail-nextjs for help
warn - logtail: Sending Web Vitals to /dev/null
warn - logtail: Sending logs to console

@PetrHeinz
Copy link
Member

Seems you have set different NODE_ENV than development.

Could you try running it with LOGTAIL_CHECK_ENV_VARS =false?

@jakeleventhal
Copy link
Author

Yeah it works. when i run build it just default to NODE_ENV=production?

all i am doing is running pnpm run build which just runs the script for vercel build

I think this is default vercel behavior. maybe process.env.NODE_ENV isn't the best proxy for this if that is the default

@PetrHeinz
Copy link
Member

It worked nicely with my setup (without involving Vercel). Now at least, the detection can be suppressed for local development, which is a good thing 🙂

@jakeleventhal
Copy link
Author

Yeah, but I think a better solution ought to exist considering vercel tooling is super common with next.js
I tried setting LOGTAIL_CHECK_ENV_VARS to false in my vercel config but it treats false as "false" and therefore doesnt work

@PetrHeinz
Copy link
Member

"false" is actually OK. ENV vars always contain strings. The LOGTAIL_CHECK_ENV_VARS should work with 1, 0, true and false as most common representation of booleans. See #12 for more details.

If it doesn't work for you, the ENV vars are probably not accessible in your app.

@jakeleventhal
Copy link
Author

the env var is accessible in my app it just doesnt seem to be accessible in vercel build

what do you propose? it seems overkill to ask all vercel users to maintain a .env file specifically for suppressing logtail logs

@PetrHeinz
Copy link
Member

PetrHeinz commented Nov 23, 2023

Hi @jakeleventhal, thanks for the follow-up.

You're right, in Vercel there's different way of determining the app environment (via VERCEL_ENV).

I'm addressing this in #14. After updating to v0.1.3, you shouldn't see the warning during vercel build ran in development 👍

@jakeleventhal
Copy link
Author

jakeleventhal commented Nov 23, 2023

▶ npx vercel build

Vercel CLI 32.5.3
Detected `pnpm-lock.yaml` version 6 generated by pnpm 8
WARNING: You should not upload the `.next` directory.
Skipping "install" command...
Detected Next.js version: 14.0.2
Running "next build"
   Skipping linting
warn - logtail: Envvars not detected. If this is production please see https://github.com/logtail/logtail-nextjs for help
warn - logtail: Sending Web Vitals to /dev/null
warn - logtail: Sending logs to console

This is on @logtail/next@0.1.3

I manually edited the dist for logtail where it prints the logs and added:

        var log = new logger_1.Logger();
        Object.entries(process.env)
            .filter(([key]) => key.startsWith('VERCEL'))
            .forEach(([key, value]) => {
                log.warn(key + ' - ' + value)
            });
        log.warn('logtail: Envvars not detected. If this is production please see https://github.com/logtail/logtail-nextjs for help');
        log.warn('logtail: Sending Web Vitals to /dev/null');
        log.warn('logtail: Sending logs to console');

and the following were printed:

warn - VERCEL_PROJECT_SETTINGS_NODE_VERSION - 18.x
warn - VERCEL_PROJECT_SETTINGS_BUILD_COMMAND - next build
warn - VERCEL - 1
warn - VERCEL_PROJECT_SETTINGS_INSTALL_COMMAND - 

VERCEL_ENV didn't seem to be there

Some other non-filtered relevant env vars:

warn - NEXT_PRIVATE_TARGET - server
warn - NEXT_EDGE_RUNTIME_PROVIDER - vercel
warn - NODE_ENV - production
warn - __VERCEL_BUILD_RUNNING - 1
warn - NEXT_DEPLOYMENT_ID - 

@PetrHeinz
Copy link
Member

@jakeleventhal Interesting... 🤔 Thanks for the further details on this. What's your vercel --version?

I tested the change with Vercel CLI 32.5.6

@PetrHeinz
Copy link
Member

Sorry, I can see that in your log output - Vercel CLI 32.5.3

@PetrHeinz
Copy link
Member

PetrHeinz commented Nov 24, 2023

@jakeleventhal I'm having difficulty replicating it. Could you please check that #15 works in your case? 🙏

@jakeleventhal
Copy link
Author

Is there a canary release or a compiled dist file? Having trouble generating it locally

@PetrHeinz
Copy link
Member

@jakeleventhal There's no pre-release at the moment, I assumed you could edit the dist manually, just as you did in #6 (comment).

@jakeleventhal
Copy link
Author

This one is a bit trickier as the compiled js is quite different and ther are a lot of conditions here. can you provide a snippet of the compiled warnAboutMissingEnvironmentVariables function

@PetrHeinz
Copy link
Member

From dist/withLogtail.js:

function warnAboutMissingEnvironmentVariables() {
   var _a, _b;
   var nodeDevEnv = process.env.NODE_ENV === 'development';
   var vercelDevEnv = process.env.VERCEL_ENV === 'preview' || process.env.VERCEL_ENV === 'development';
   var vercelNonProdBuild = process.env.VERCEL_ENV !== 'production' && process.env.__VERCEL_BUILD_RUNNING === '1';
   var checkEnabled = !nodeDevEnv && !vercelDevEnv && !vercelNonProdBuild;
   if (((_a = process.env.LOGTAIL_CHECK_ENV_VARS) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === 'true' || process.env.LOGTAIL_CHECK_ENV_VARS === '1') {
       checkEnabled = true;
   }
   if (((_b = process.env.LOGTAIL_CHECK_ENV_VARS) === null || _b === void 0 ? void 0 : _b.toLowerCase()) === 'false' || process.env.LOGTAIL_CHECK_ENV_VARS === '0') {
       checkEnabled = false;
   }
   if (checkEnabled) {
       var log = new logger_1.Logger();
       log.warn('logtail: Envvars not detected. If this is production please see https://github.com/logtail/logtail-nextjs for help');
       log.warn('logtail: Sending Web Vitals to /dev/null');
       log.warn('logtail: Sending logs to console');
   }
}

@jakeleventhal
Copy link
Author

works for me, good to merge that PR

@PetrHeinz
Copy link
Member

Thanks for the cooperation on this one, @jakeleventhal 👍 Just released v0.1.4 with the verified fix 🚀

@jakeleventhal
Copy link
Author

I just verified 0.1.4 gives me no issues

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment