-
Notifications
You must be signed in to change notification settings - Fork 41
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 tracing #1100
Add tracing #1100
Commits on Dec 11, 2023
-
This package provides high level tracing APIs tailored to k6 browser needs, defining methods that allow to correlate async events with the pages to which they belong to.
Configuration menu - View commit details
-
Copy full SHA for 71651ad - Browse repository at this point
Copy the full SHA 71651adView commit details -
Adds a new traces registry which will hold the references for every iteration root span and wrapping context. This span will be extended for every instrumented method call during the iteration execution.
Configuration menu - View commit details
-
Copy full SHA for dca0b5e - Browse repository at this point
Copy the full SHA dca0b5eView commit details -
Initialize traces registry on VU iterStart
The traces registry has to be held per VU scope, as it stores traces indexed per iteration, which are only unique per VU. Therefore keep it under browser registry so we can use it to handle traces generation based on iter events. Because VU.State is nil when the browser registry is initialized, we have to initialize the traces registry on the first VU iteration so we can get access to the k6 TracerProvider. This is done within a sync.Once so we ensure the traces registry is only initialized once per VU.
Configuration menu - View commit details
-
Copy full SHA for 18890e9 - Browse repository at this point
Copy the full SHA 18890e9View commit details -
Start/End iteration traces on iter events
This also sets the trace context, wrapping the iteration's root span, as the context for browser, which will be inherited by the other components such as browser context, page, etc.
Configuration menu - View commit details
-
Copy full SHA for c3d0f49 - Browse repository at this point
Copy the full SHA c3d0f49View commit details -
Shutdown traces registry on exit event
Only stop the traces registry if it has been previously initialized, which won't happen for the initial VU. When stopping, ensure any active live span is ended before exiting.
Configuration menu - View commit details
-
Copy full SHA for e7412f6 - Browse repository at this point
Copy the full SHA e7412f6View commit details -
Configuration menu - View commit details
-
Copy full SHA for c868ca1 - Browse repository at this point
Copy the full SHA c868ca1View commit details -
Wrap Tracer into browser context
This is so the tracer can be retrieved by the other components which inherit the browser context (BrowserContext, Page, etc) and use it to generate spans that represent their actions.
Configuration menu - View commit details
-
Copy full SHA for 8c5934e - Browse repository at this point
Copy the full SHA 8c5934eView commit details -
Generate a span from onFrameNavigated async event parsing. We must also keep a reference to the last active span for the main frame so we can end it when FrameSession.ctx is Done so the span is flushed before exiting.
Configuration menu - View commit details
-
Copy full SHA for c351d75 - Browse repository at this point
Copy the full SHA c351d75View commit details -
Allows to run JS code in the global object instead of a specific execution context.
Configuration menu - View commit details
-
Copy full SHA for a3ff377 - Browse repository at this point
Copy the full SHA a3ff377View commit details -
Inject spanID on frame navigated
In order to be able to correlate the Web Vitals events to the navigation span to which they belong to, we have to add a reference to that span in the page context, so it can be retrieved by our Web Vitals script that is executed in the page before pushing the WV metrics to k6 browser through the set up binding. The JS code to set the spanID in the page context is executed through the EvaluateGlobal method as otherwise it would be executed in the current frame context. The problem is that, because we are processing a navigation event, the frame context has actually already changed in the browser but our event parsing goroutine will not process that until we exit the onFrameNavigated method and receive the onExecutionContextCreated event. This would result in an error when evaluating the JS code due to "execution context changed". In this case, because the JS code sets a property in the global object (window), it is OK to just execute it in the global context. Additionally the EvaluateGlobal method has to be called in a separate goroutine to avoid deadlocking the event parsing goroutine when the frame loading generates CDP events that have to be acted on for the loading process to continue, such as when the frame contains a JS initiated dialog (alert, confirm, prompt, or onbeforeunload) which we have to parse and respond with an explicit accept/dismiss action (see onEventJavascriptDialogOpening).
Configuration menu - View commit details
-
Copy full SHA for 376204a - Browse repository at this point
Copy the full SHA 376204aView commit details -
Add spanID to web_vital_init.js
To be able to associate a web vital to the PageNavigation span, we need to inject the span's id that was previously set in the page in onFrameNavigated to the WV event so that the measurement can be correctly linked to the page navigation span.
Configuration menu - View commit details
-
Copy full SHA for c09804b - Browse repository at this point
Copy the full SHA c09804bView commit details -
Generate a span that represents a WebVital measurement.
Configuration menu - View commit details
-
Copy full SHA for f66f8fc - Browse repository at this point
Copy the full SHA f66f8fcView commit details -
Configuration menu - View commit details
-
Copy full SHA for ea19a68 - Browse repository at this point
Copy the full SHA ea19a68View commit details -
Configuration menu - View commit details
-
Copy full SHA for 5bfdf28 - Browse repository at this point
Copy the full SHA 5bfdf28View commit details -
Configuration menu - View commit details
-
Copy full SHA for 0bdafbe - Browse repository at this point
Copy the full SHA 0bdafbeView commit details -
Configuration menu - View commit details
-
Copy full SHA for c92af9b - Browse repository at this point
Copy the full SHA c92af9bView commit details -
Configuration menu - View commit details
-
Copy full SHA for ab5e5cb - Browse repository at this point
Copy the full SHA ab5e5cbView commit details -
Defines a tracer interface with only the methods required for the common package tracing. This also allows us to implement higher level helper functions that will automatically retrieve the Tracer from a given context and use it to generate a span, or return a noop span if no tracer is found in the context, avoiding a possible NPE.
Configuration menu - View commit details
-
Copy full SHA for 5027c81 - Browse repository at this point
Copy the full SHA 5027c81View commit details -
Configuration menu - View commit details
-
Copy full SHA for 05cf6fc - Browse repository at this point
Copy the full SHA 05cf6fcView commit details -
This functions will try to call the same method they implement from the tracer contained in the given context. If the tracer is not found in the context, they return a noop Span. This makes the code in the common package cleaner and avoids dealing with possible NPEs. At the sime time avoids having to mock the tracer in tests.
Configuration menu - View commit details
-
Copy full SHA for 88ea879 - Browse repository at this point
Copy the full SHA 88ea879View commit details -
Configuration menu - View commit details
-
Copy full SHA for 149f350 - Browse repository at this point
Copy the full SHA 149f350View commit details -
Configuration menu - View commit details
-
Copy full SHA for 5a80597 - Browse repository at this point
Copy the full SHA 5a80597View commit details -
Add support for WithTracerProvider in test VU
Allows to set a specific TracerProvider for the test VU implementation. If not set, it defaults to NoopTracerProvider.
Configuration menu - View commit details
-
Copy full SHA for e425052 - Browse repository at this point
Copy the full SHA e425052View commit details -
Configuration menu - View commit details
-
Copy full SHA for fe7ad96 - Browse repository at this point
Copy the full SHA fe7ad96View commit details -
Configuration menu - View commit details
-
Copy full SHA for 4d68e20 - Browse repository at this point
Copy the full SHA 4d68e20View commit details -
Set browser registry context from root module
Modifies the browser registry constructor to accept a context that will be used in order to build the browser context which will eventually be inherited by the other browser components.
Configuration menu - View commit details
-
Copy full SHA for 0f0e214 - Browse repository at this point
Copy the full SHA 0f0e214View commit details