SMOODEV-2706: Add installWebVitals RUM one-liner to browser SDK#74
Closed
brentrager wants to merge 1 commit into
Closed
SMOODEV-2706: Add installWebVitals RUM one-liner to browser SDK#74brentrager wants to merge 1 commit into
brentrager wants to merge 1 commit into
Conversation
Package Core Web Vitals collection into @smooai/observability/browser so
customers get LCP/CLS/INP/FCP/TTFB with a single call. Records against the
existing browser MetricsClient using the metric contract dogfooded in
apps/web:
- web.vitals.{lcp,fcp,inp,ttfb} — histogram, unit ms
- web.vitals.cls — histogram, unitless raw CLS
- attrs: route, rating, navigation_type
Browser-guarded, idempotent, lazy-loads web-vitals only on opt-in. No
product internals. Held for release until the logs signal ships.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01S2bM94GAnVjYSSv1x7HKRB
🦋 Changeset detectedLatest commit: d4b8474 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Contributor
Author
|
Standing down — premise was false: the browser SDK has no metrics transport (getMetricsClient is a Node-only OTel no-op in the browser), so installWebVitals would silently send nothing. Real prerequisite is a browser metrics transport (extend the error transport's IngestPayload with type:'metric'), deferred to the customer-release phase (pearl th-e67905) after dogfooding the path inside the monorepo. Branch left on remote for reference; not deleting since it'll inform th-e67905. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Customers embedding the
@smooai/observabilitybrowser SDK have no turnkey way to report Core Web Vitals. They'd have to wireweb-vitalscallbacks to aMetricsClientthemselves and get the metric names/attrs right by hand.Solution
Add
installWebVitals(metrics, opts?)to@smooai/observability/browser— a one-liner that records Core Web Vitals against the existing browserMetricsClient:Pinned metric contract (matches the apps/web RUM dogfood exactly):
web.vitals.lcp/.fcp/.inp/.ttfb— histogram, unitms(viaMetricsClient.timing)web.vitals.cls— histogram, unitless raw CLS (viaMetricsClient.histogram)route(location.pathname, overridable viaopts.routefor SPA routers),rating(good|needs-improvement|poor),navigation_type(metric.navigationType)Details:
typeof window === 'undefined').web-vitalsis dynamically imported only wheninstallWebVitalsis called, so it stays out of the critical path and off the node/SSR bundle.web-vitals@^5.3.0added as a dependency (tiny, no transitive deps).Verification
pnpm --filter @smooai/observability test— 62 pass (3 new, drivingrecordWebVitalwith a fakeMetricsClient+ synthetic metrics; asserts exact name / recording kind / attrs for each vital).pnpm --filter @smooai/observability typecheck— clean.pnpm --filter @smooai/observability build— clean; confirmedinstallWebVitals/recordWebVitalexported fromdist/browser.mjs+browser.d.mts, andimport("web-vitals")stays a lazy runtime import (not bundled).Release
🤖 Generated with Claude Code
https://claude.ai/code/session_01S2bM94GAnVjYSSv1x7HKRB