HTTPArchive/custom-metrics

Add support for primer scripts

rviscomi opened this issue · 2 comments

Custom metrics are executed late in the page load, after most of the initial application code has already run. WebPageTest supports injecting scripts towards the start of the page load, but this isn't guaranteed to always be the first script to execute.

For lack of a better name, primer scripts are guaranteed to be executed before any other 1P code, making them ideal for initializing custom metric telemetry.

  • Add support to WebPageTest to guarantee that primer scripts are executed first
  • Create and document the process for publishing new primer scripts to production

The process should reuse this repo for script development and specify which directory will contain the script or scripts that need to be injected early.

Currently, the main use case is to initialize observers on JS APIs so that we can report usage later in the custom metrics. Without this, we're limited in what we can measure about what JS is actually executed. Regex parsing can tell us what code is on the page, but not what's executed. Blink feature counters (ie chromestatus.com and the blink_features table) do tell us what's executed, but we're limited by what features have been instrumented in Chrome. This gives us the ability to not only detect whether APIs were used, but how.

Agent support has been added and the agent instance templates have been updated to automatically populate the script injection from inject-dist.

@rviscomi feel free to open this if you want to create more documentation than the readme that is currently in inject-dist but the functionality is live (and the webpagetest.httparchive.org instance was also updated to populate the injection scripts from here).

Great thanks! Closing SGTM.