aws-observability / aws-rum-web

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

chore: store resource and navigation events by PerformanceEntry #440

Closed williazz closed 10 months ago

williazz commented 10 months ago

Purpose

We need an event store to link related RUM events. My use case is to link LCP attribution to related RUM events.

  1. Resource event for the image loaded, if any
  2. Navigation event for the current page

Revision 1

  1. EventStore maps custom keys to RumEvents. Plugins write to store with context.record(type, event, key) and read from store with context.getEvent(key). LCP attribution can use PerformanceEntry object references as the keys.
  2. ResourcePlugin stores image resource events by reference to the PerformanceResourceTiming entry
  3. NavigationPlugin caches all level 2 events by reference to PerformanceNavigationTiming entry. Level 1 events do not have a related PerformanceEntry, and are therefore ignored.

Revision 2

Not included in this PR

  1. Linking LCP attribution to event IDs for 2 and 3 from above. LCP attribution collected by web-vitals package includes references navigationEntry and lcpResourceEntry. These references can be used as keys to retrieve the related event ID's via context.getEvent(key).

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

qhanam commented 10 months ago

issue: It's not obvious from the PR description what problem this change solves, or how this change solves it. Reviewing this change is difficult without this context.

williazz commented 10 months ago

issue: It's not obvious from the PR description what problem this change solves, or how this change solves it. Reviewing this change is difficult without this context.

Updated the description. Tl; DR: this PR creates the API necessary for linking LCP attribution to related resource and navigation events.

qhanam commented 10 months ago

The problem we are trying to solve is to allow NavigationPlugin and ResourcePlugin to share event Ids related to web vitals attribution artifacts (specifically, PerformanceEntry objects) with WebVitalsPlugin. By doing so, events recorded by WebVitalsPlugin can reference events recorded by NavigationPlugin/ResourcePlugin, which are attributed to the web vitals value.

This PR proposes that we generalize this use case to allow any plugin to share the events it records with any other plugin.

I wonder if we should further generalize this use case to allow plugins to share any information. My argument for this would be (1) we don't know the future use case, and (2) a general solution might require less management infrastructure, such as the EventStore currently implemented in this PR.

I suggest considering two models:

  1. A "push" model, where plugins publish events to an event bus.
  2. A "pull" model, where plugins can access the context of other plugins.
williazz commented 10 months ago

Closing for #445