-
Notifications
You must be signed in to change notification settings - Fork 943
Clarification around when state of environment is evaluated for instance? Request to evaluate on instance creation #783
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
Comments
Correct. Let it be clear (not as a criticism of the question, which I appreciate being asked) - order of operations in the sense it is applied here is common throughout software engineering. You cannot expect the order of operations to be completely arbitrary with the same result. This seems to be a common misconception with some of the more "confused" requests I get here.
There's absolutely no reason these modules cannot work together. They're both incredibly simple, and it takes a very simple understanding of environment variables to figure out why certain orders of operation work and which do not. The vast majority of support tickets sent here w.r.t.
Right. Why would it? Further, the very nature of "each time it's included" doesn't make sense - Node.js has a
Correct.
This is where I lost you. Why is this confusing?
Yep, you've pretty much debugged it entirely given the preceding steps.
Of course it's possible. It's also a needless performance hit. The general assumption is that the
Force And no, it makes little sense making this the default behavior.
That was a feature suggestion, one that I am very starkly against. Nowhere was it indicated this is a current feature.
Performance, and the fact most programs do not modify environment during runtime. Programming isn't "anything goes". You need to understand the order in which you do things.
Sorry, but I fully disagree that it "aligns with expectation". I would expect most systems developers would disagree, too. Of course it's allowed and possible and even useful at times, but rarely relied upon.
Performance is always a concern. This is why systems engineers tend not to take web development seriously in the first place, if I may be so bold (disclaimer: that is my own observation - other maintainers of
Sorry to seem harsh, but there's nothing to fix here. Going to close this as it's a question - feel free to follow up and I'd be happy to respond. Thanks! |
Ok, thanks for explanation. It at least confirms my understanding.
Great! Is there an example available that uses I understand to satisfy the order, we would want the You mentioned:
What is the equivalent when using In other words, what would I need to change in https://github.com/mattmazzola/debugtest/blob/master/src/index.ts to make it log
I didn't mean to re-parse each time it's included, I meant to reparse when an instance is created. You seem much more aware of the lower levels of language and performance concerns so you may see this as "magic" or "anything goes" but I feel because the developer called a function they expects something to happen so it is deterministic. Such as
I can see why it would be bad for default now, but I thought for more casual/hobby usage where people want to see logs of different components of their applications but aren't worried about performance this would be useful.
Agreed. I think there is a solution to simply defer evaluation until the first instance is created. Then we get the best of both worlds. Evaluate/Parsed only once for performance AND the developer easily change the order of what it happens by changing when statements are executed instead of worrying about require/import dependency graph. Is something like this possible?
|
Hi, I hoped to ask a question that would help clarify some confusion I'm seeing in other related issues about the debug logs from the instances not being enabled thus logs not appearing when users expect it should be enabled.
It seems this is often an order of operations issue. People expect the environment variables to be evaluated when an instance is created, but based on the responses to other issues, it seems the variables are evaluated when the module is imported which is causing the confusion. Example #750
The reason I had come across this is because I was trying to get get
dotenv
to work with this packagedebug
. I think these are two very common solution and could work together more easily.Common expectation (DOES NOT LOG)
Output:
You can see it does work if the environment variables is set BEFORE the process is started in the output below
From my understanding the reason this doesn't work is because the environment state is evaluated when the module is imported. And in the example the environment variables are only set after
dotenv.config()
is called.This means all instances created by the debug will be disabled event if
DEBUG=*
is set. This is very confusing.Order of operations
Questions:
I saw there is some mention of ability to do this manually as seen here
const debugInstance = debug('someInstance', {reloadEnv: true})
from this comment #750 (comment)However, I was not able to get it to work and it's also not in the typescript definitions.
I don't know what the reason would be for the single evaluation on import, but I was thinking this would actually be a good default option as it aligns with expectation and only those users very concerned about performance would opt if there is some significant penalty.
I create a repo with reproduction here if there is a way to fix it:
https://github.com/mattmazzola/debugtest
The text was updated successfully, but these errors were encountered: