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

Add browser extension log field #978

Merged
merged 2 commits into from
Jul 25, 2023
Merged

Add browser extension log field #978

merged 2 commits into from
Jul 25, 2023

Conversation

ka3de
Copy link
Collaborator

@ka3de ka3de commented Jul 18, 2023

Description of changes

Adds a new source:browser log field which allows to distinguish log messages generated by xk6-browser extension from messages generated by k6 core. As mentioned in #934 (comment), the source label is currently used across k6 codebase.

An example of different log messages after the change applied in this PR including:

  • One debug message from k6 browser implementation
  • One log message from browser context execution
  • One console.log message from browser context execution
  • One console.log message from k6 test script execution.
DEBU[0000] wsURL:"ws://127.0.0.1:34591/devtools/browser/dc9e1e8b-058e-47c4-97df-3b4dfa2d81a7"  category="Browser:connect" elapsed="0 ms" iteration_id=dda9fe94f08fa83b source=browser
...
ERRO[0001] Failed to load resource: the server responded with a status of 403 ()  browser_source=network line_number=0 source=browser stacktrace="<nil>" url="https://grafana.com/canspam"
INFO[0001] "This is a console.log message from browser context execution"  browser_source=console-api source=browser
INFO[0001] This is a console.log message from k6 test script context execution  source=console

Closes #934

@ka3de ka3de requested a review from ankur22 July 21, 2023 10:14
Copy link
Collaborator

@ankur22 ankur22 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀

This log field allows to distinguish log messages generated by
xk6-browser extension.
In order to be consistent with the usage of 'source:browser' log fields
across all logs generated from the browser extension, this commit
replaces the current 'source' log field for onConsoleAPICalled logger,
which was previously set to 'browser-console-api', to 'browser'. Also
moves and modifies the previous 'browser-console-api' to be set as
'console-api' for the 'browser_source' keyed field, which is currently
also used in the 'onLogEntryAdded' method logger.
@ka3de ka3de force-pushed the add/934-browser-ext-log-field branch from 09b17c0 to a090ffc Compare July 24, 2023 08:18
@ka3de
Copy link
Collaborator Author

ka3de commented Jul 24, 2023

A note on a090ffc:
I considered initially to refactor our Logger implementation in order to support WithTime and WithField method, but this was deriving in a decent refactor, which I think is better to tackle in a different PR if we want. Also, currently there are only two methods (onLogEntryAdded and onConsoleAPICalled) that build a new logrus Logger independent from our higher level abstraction, both related with browser console output, so we might not want to currently support this anyway.

@ka3de ka3de requested a review from ankur22 July 24, 2023 08:29
Copy link
Collaborator

@ankur22 ankur22 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚢 it!

@ka3de ka3de merged commit 4518aed into main Jul 25, 2023
@ka3de ka3de deleted the add/934-browser-ext-log-field branch July 25, 2023 09:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tag/label browser module logs with browser as the origin
2 participants