-
Notifications
You must be signed in to change notification settings - Fork 42
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
Conversation
37a5123
to
f635676
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Colossal work and nicely done 👏 I have some weak suggestions. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great! Excited to see the results, and the next steps.
One question I have is why were only a subset of APIs instrumented?
I knew I have read this question somewhere but missed to answer it @ankur22. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🚀
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀
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.
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.
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.
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.
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.
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.
Generate a span that represents a WebVital measurement.
25eebcf
to
f4cdfc8
Compare
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.
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.
Allows to set a specific TracerProvider for the test VU implementation. If not set, it defaults to NoopTracerProvider.
Reduces nested levels.
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.
Squashed fixup commits, rebased on top of main to resolve conflict on |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🚀
What?
This PR uses the tracing instrumentation provided by k6 through the
VU.State
in order to generate traces that represent the inner workings of k6 browser.Why?
Tracing has been chosen as the best suited method in order to build a timeline view of a k6 browser test, which can provide a more visual representation of a browser test along with the metrics associated for each action, such as specific WebVitals measurements per navigation, errors produced, etc.
Checklist
Related PR(s)/Issue(s)
Related: grafana/k6#3445