Skip to content

feat(preview): add monitoring dimensions + preload outcome [PREVIEW-224]#1639

Open
ahorowitz123 wants to merge 9 commits into
masterfrom
PREVIEW-224
Open

feat(preview): add monitoring dimensions + preload outcome [PREVIEW-224]#1639
ahorowitz123 wants to merge 9 commits into
masterfrom
PREVIEW-224

Conversation

@ahorowitz123
Copy link
Copy Markdown
Contributor

Summary

  • Accept three host-supplied monitoring dimensions (access_pattern, preview_mode, shared_link_auth) as options on Preview and attach them to every emitted preview_metric / preview_error payload via emitLogEvent.
  • Add BaseViewer.getPreloadStatus() returning 'na' by default; override in DocBaseViewer (this.preloader.loadTime → hit/miss) and VideoBaseViewer (this.preloader.wrapperEl → hit/miss). Generalizes the preload-hit signal beyond the doc + WebP-only path.
  • In emitLoadMetrics, tag the load event with preload_status and emit a new preview_preload_outcome counter event so the dashboard can compute preload hit rate directly.

Why

Part of the Preview Performance Monitoring dashboard rollout under WEBAPP-53337. The dashboard needs to slice TTPL by access pattern, preview mode, shared-link auth, and preload hit/miss — none of which were tagged today. Companion host-side work lands in the EndUserApp, preview-client, and box-ui-elements tickets (PREVIEW-225/226/227).

Ticket

PREVIEW-224

Test plan

  • Unit tests added for `emitLogEvent` (new dimensions present when set, omitted when unset)
  • Unit tests added for `emitLoadMetrics` (`preload_status` on load event, separate outcome counter)
  • Unit tests added for `parseOptions` (new options stored / defaulted to undefined)
  • `getPreloadStatus` tested on BaseViewer (na), DocBaseViewer (hit/miss/na), VideoBaseViewer (hit/miss/na)
  • Full jest suite passes (3105 tests)
  • ESLint clean on touched files
  • Manual verification: host app passes new options and confirms payloads carry the dimensions (tracked by companion tickets)

🤖 Generated with Claude Code

Accept access_pattern, preview_mode, shared_link_auth as host-supplied
options and attach them to every emitted metric/error. Expose
getPreloadStatus() on BaseViewer and override in doc/video viewers so
emitLoadMetrics can tag the load event with preload_status and emit a
new preview_preload_outcome counter.

PREVIEW-224

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@ahorowitz123 ahorowitz123 requested a review from a team as a code owner May 7, 2026 18:02
ahorowitz123 and others added 8 commits May 8, 2026 11:39
Reads the existing Logger.log.cache.hit signal (set by Preview
loadFromCache) and maps it to a hit/miss string on every emitted
event. Gives the monitoring dashboard per-metric visibility into file
metadata cache effectiveness without a join against the preview
session log.

PREVIEW-224

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
DocBaseViewer.getPreloadStatus() reads this.preloader.loadTime to
report preload hit/miss on emitted metrics, but only DocFirstPreloader
set loadTime. Standard DocPreloader and PresentationPreloader never
did, so the dashboard always saw miss. Set loadTime when the preload
element is revealed, matching the existing DocFirstPreloader pattern.

PREVIEW-224

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Redefine the two cache/prefetch dimensions to match what the dashboard
actually wants to measure:

- preload_status: did the host call Preview.prefetch(fileId) for this
  file before the full preview load? Tracked via a new prefetchedFiles
  Set populated in prefetch(). Replaces the brittle viewer-level
  getPreloadStatus() logic that relied on loadTime/wrapperEl signals
  that were often undefined even when preload worked.
- prefetch_status: did the file-metadata cache (previewService.cache
  / Logger.setCached) serve this load? Renamed from
  file_info_cache_status to match its real meaning.

Also removes BaseViewer.getPreloadStatus() and the doc/video
overrides, the DocPreloader/PresentationPreloader loadTime writes,
and the isConnected fallback in DocBaseViewer — all unnecessary now.

PREVIEW-224

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Previously these tags were attached to every emitted event via
emitLogEvent, which would skew the dashboard denominator since events
like thumbnail open, find bar open, and perf metrics all fired on
every session.

Now the tags live only on the three events where they are actually
needed: the load event, the preview_preload_outcome counter, and
preview_error. Exactly one of {load, error} fires per session, giving
a clean hit-rate numerator/denominator.

Extracted the computation into getLoadStateTags() so all three
callers share the same logic.

PREVIEW-224

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The ContentPreview wrapper creates a new Preview instance per preview
session, while host apps call prefetch() on a different long-lived
Preview instance in the file list / service layer. An internal Set of
prefetched file IDs therefore lives on the wrong instance and is
always empty at emit time.

Accept preloadStatus as an option instead, matching how
access_pattern, preview_mode, and shared_link_auth are already
host-supplied. Host apps (EUA, preview-client) now compute the
hit/miss value themselves based on their own prefetch tracking.

Drops the internal prefetchedFiles Set and the .add() call in
prefetch().

PREVIEW-224

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Lets the host supply both cache dimensions (preload_status and
prefetch_status) explicitly rather than Preview inferring
prefetch_status from its own Logger.cache.hit. Same architecture
issue as preload_status: the host often calls prefetch() on a
different Preview instance than the one running the session, so any
Preview-local bookkeeping drifts out of sync.

When the host omits either option, the corresponding field is left
off the emitted payload.

PREVIEW-224

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The host-supplied values were recording 'did the host initiate a
prefetch/preload attempt' rather than 'did it actually succeed before
the user opened preview'. Users reported seeing hit values even while
the preview was clearly still spinning on a network fetch.

Derive both dimensions inside the SDK from real session-end signals:
- preload_status: set when VIEWER_EVENT.preload fires (the viewer
  actually rendered the preload representation to the DOM)
- prefetch_status: read from Logger.log.cache.hit which is set in
  loadFromCache() when the SDK skips the file-info API call entirely

Drops the host preloadStatus / prefetchStatus options.

PREVIEW-224

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Doc viewers emit 'preload' on the preloader which DocBaseViewer
handles locally in onPreload() and calls logger.setPreloaded() on —
the event never bubbles up to Preview.handleViewerEvents so
this.preloadEmitted was always false for docs. Fall back to
this.logger.log.time.preload (set by setPreloaded) when the
VIEWER_EVENT.preload case didn't fire.

PREVIEW-224

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant