aws-observability / aws-rum-web

Amazon CloudWatch RUM Web Client
Apache License 2.0
119 stars 65 forks source link

Time to interactive #465

Closed ps863 closed 10 months ago

ps863 commented 11 months ago

Changes

Testing

Details

TTI (Time to Interactive) is a measurement that can tell users how their web application took for them to ready for interaction.

TTI can be measurement using several different algorithms (mainly Google and Boomerang).

Since TTI is gradually being phased out, supported for the library implementations of either is limited/on path to deprecation. Therefore, in this PR, we implement the Boomerang TTI algorithm ourselves for better maintainability and avoid taking dependency on packages that are no longer actively maintained.

How can users get TTI telemetry for their web applications?

Documentation changes will come in separate PR. Since TTI is used by limited users and incurs additional telemetry expenses (for additional events), users will have to import the TTI plugin and then configure their web client configuration to use it.

import { TTIPlugin } from "aws-rum-web";
const config = {
    sessionSampleRate: 1,
    guestRoleArn:
      "",
    identityPoolId: "",
    endpoint: "https://dataplane.rum.us-west-2.amazonaws.com",
    telemetries: ["performance", "errors", "http"],
    eventPluginsToLoad: [new TTIPlugin()],
    allowCookies: true,
    enableXRay: false,
  };

How is TTI using algorithm measured?

We implement TTI Boomerang algorithm with some modifications

Steps to TTI:

1) Find visually ready timestamp (highest of domcontentLoadedEnd(if available), FCP(if available), LCP(if available)) 2) Starting from the Visually Ready timestamp, find a 500ms quiet window.

A quiet window has the following characteristics: a) No Long Tasks b) FPS is above 20

Boomerang TTI's measurement interval is every 100ms. Each check is performed and bucketed into a 100ms interval.

3) TTI is recorded as Visually ready timestamp + time from visually ready to the start of the quiet window

Note: We do not record PageBusy metrics for now as there were some performance issues observed with applications getting blocked. Without PageBusy metric, the algorithm requires that Long Tasks are recorded to compute a TTI. As such TTI can only be computed for now for browsers that support Long Tasks.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

williazz commented 11 months ago

I agree with the overall design. My main feedback is:

  1. Improve readability where possible
  2. Teardown listeners
  3. Improve performance of FPS tracker, if possible