-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Make console.log() available in the init context #951
Comments
Description of this issue helped me in finding out a problem I have been struggling with for hours: #969 |
For me the whole noisiness is not an issue ... if you want to log something in the init context I suppose you are debugging something. Making you jump through hoops and one of them being making the whole output even more noisy by enabling verbose is seems unreasonable. On the second(first) issue of Logger being in So technically adding:
somewhere in here fixes it ... At this point I wonder if the |
You're absolutely right, sorry for disagreeing earlier! I didn't consider the extra noisiness And if we can fix the configuration challenges you describe (:sob:), have proper loggers per-VU, and actually implement #889 and attach (via But yeah, I don't have a good solution for the redirection to file at this point, sorry. The massive refactoring I'm currently doing will somewhat improve the passing of a logger from I propose that we either wait until we fix some of the configuration for this, or we just implement this in a hacky way where the first init context execution always logs to stdout, regardless if a file was specified. I don't like either of those options, but I don't see many alternatives... |
This commit does the bare minimal to enable useage of console init context. Unfortunetely this means that redirection to file is currently not supported in init context.
This commit does the bare minimal to enable useage of console init context. Unfortunetely this means that redirection to file is currently not supported in init context.
This commit does the bare minimal to enable useage of console init context. Unfortunetely this means that redirection to file is currently not supported in init context.
Any update on when this can be fixed? It would sometimes be very helpful to log info during development of init scripts (for auth for example). |
Even more problematic with not having |
@maxekman, you are right. We have an open PR that fixes this (#982), but we haven't merged it yet, because it's incompatible with the Unfortunately, to properly fix this would require significant refactoring. So it's likely we'll soon merge the fix as it is, even even with that known bug, and we'll come back at some point in the future to properly fix everything... |
It would be very welcome to get that merged! In my current situation I can't even import a lib for VUs (auth0-js) as it depends on console. |
As a workaround for anyone blocked by imports requiring the console I managed to define the missing console using console-browserify inside the generated UMD file: |
This commit does the bare minimal to enable useage of console init context. Unfortunetely this means that redirection to file is currently not supported in init context.
@maxekman, you should now be able to use the |
As seen in this issue,
console.log()
could be quite useful in the init context for debugging purposes.The main user-facing problem with this it the fact that code in the init context is executed multiple times. Off the top of my head, it's executed once in the beginning of a k6 run to get the exported script
options
, once forsetup()
, once for the initialization in each VU, and once inteardown()
. So if we enable this by default, it's going to be quite noisy...There are 2 somewhat major things from an implementation perspective that are potentially problematic. First, the logger for each runtime (i.e. VU) is currently in the
lib.State
struct, which isn't available in the init context. In fact, its presence of absence are often how we verify whether a particular piece of k6 Go code is executed in the VU or init context respectively...The second issue stems from the fact that we likely can't enable this logging by default due to its noisiness. This likely means that we have to hide it behind a flag. Unfortunately, it can't be a JS option only, since those are retrieved after the init context is executed once. But it seems like something minor that doesn't deserve its own CLI/environment variable flag...
So, here's an initial proposal that needs to be further evaluated for feasibility:
console.log()
in the init context will return an error. But it won't be the currentReferenceError: console is not defined
, rather it will be something likeUsing console.log() in the init context only works when verbose mode is enabled. You can do that with the --verbose/-v CLI flags or the K6_VERBOSE environment variable.
console
methods in the init context will start to work. Each message will likely be emitted multiple times, once per init context execution, unless there's an error somewhere in the code that aborts the script execution.source
field in each log message. And it's also somewhat tied to this issue about having VU numbers in the init context.But yeah, more evaluation definitely needed, since this seemingly simple feature has a lot of complications if we want to get it right...
The text was updated successfully, but these errors were encountered: