-
Notifications
You must be signed in to change notification settings - Fork 5
perf: shrink ranking frame images, lazy-load Sentry Replay #232
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,7 @@ | ||
| import { env } from "$env/dynamic/public"; | ||
| import { handleErrorWithSentry, replayIntegration } from "@sentry/sveltekit"; | ||
| import * as Sentry from "@sentry/sveltekit"; | ||
| import { getClient, handleErrorWithSentry, init } from "@sentry/sveltekit"; | ||
|
|
||
| Sentry.init({ | ||
| init({ | ||
| dsn: env.PUBLIC_SENTRY_DSN, | ||
|
|
||
| tracesSampleRate: 1.0, | ||
|
|
@@ -18,8 +17,7 @@ Sentry.init({ | |
| // sessions when an error occurs. | ||
| replaysOnErrorSampleRate: 1.0, | ||
|
|
||
| // If you don't want to use Session Replay, just remove the line below: | ||
| integrations: [replayIntegration()], | ||
| // Session Replay is added lazily below instead of listed here -- see loadReplay(). | ||
|
|
||
| dataCollection: { | ||
| // To disable sending user data and HTTP bodies, uncomment the lines below. For more info visit: | ||
|
|
@@ -29,5 +27,30 @@ Sentry.init({ | |
| }, | ||
| }); | ||
|
|
||
| // Session Replay is one of the heaviest parts of the Sentry SDK. Referencing `replayIntegration` | ||
| // only inside this dynamic import (never via a static import elsewhere in this file) keeps it out | ||
| // of the eagerly-loaded entry chunk that every page load has to parse and execute -- it ends up in | ||
| // its own chunk, fetched only once the page has settled. This doesn't change which sessions | ||
| // actually get recorded, since that's still governed by replaysSessionSampleRate/ | ||
| // replaysOnErrorSampleRate above, read whenever the integration is added. | ||
| // | ||
| // Trade-off: Replay isn't active until this runs, so a page view that ends (tab closed, | ||
| // navigated away) before then produces no replay and no replaysOnErrorSampleRate coverage for | ||
| // errors thrown in that window. Accepted deliberately -- reducing parse/eval cost for every | ||
| // visitor outweighs replay coverage for the rare very-short-lived view. | ||
| function loadReplay() { | ||
| import("@sentry/sveltekit").then(({ replayIntegration }) => { | ||
| getClient()?.addIntegration(replayIntegration()); | ||
| }); | ||
| } | ||
|
|
||
| if (typeof requestIdleCallback === "function") { | ||
| // timeout ensures this still fires under continuous page activity, where an idle period may | ||
| // otherwise never occur -- matching the setTimeout fallback's 4s bound below. | ||
| requestIdleCallback(loadReplay, { timeout: 4000 }); | ||
| } else { | ||
| setTimeout(loadReplay, 4000); | ||
|
Comment on lines
+47
to
+52
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift 🔎 Supported by static analysis🏁 Script executed: #!/bin/bash
set -eu
printf '%s\n' '--- applicable repository guidance ---'
find /tmp/coderabbit-repo-knowledge/thunlights-distopia-01d05aee -type f -name '*.md' -print \
| sort \
| while IFS= read -r f; do
case "$f" in
*/learnings/*|*/architecture/*) continue ;;
esac
printf '\n### %s\n' "$f"
cat "$f"
done
printf '%s\n' '--- hook outline and changed file ---'
ast-grep outline src/presentation/web/src/hooks.client.ts || true
cat -n src/presentation/web/src/hooks.client.ts
printf '%s\n' '--- Sentry dependency declarations ---'
rg -n -C 3 '"`@sentry/`(sveltekit|browser)"|sentry-javascript|replaysOnErrorSampleRate|replayIntegration|addIntegration|loadReplay|requestIdleCallback' \
src/presentation/web package.json pnpm-lock.yaml yarn.lock package-lock.json 2>/dev/null || trueRepository: ThunLights/distopia Length of output: 50376 🏁 Script executed: #!/bin/bash
set -eu
printf '%s\n' '--- hook ---'
cat -n src/presentation/web/src/hooks.client.ts
printf '%s\n' '--- package manifests and lockfile entries ---'
rg -n -C 5 '"`@sentry/sveltekit`"|`@sentry/sveltekit`|replaysOnErrorSampleRate|replayIntegration|addIntegration|loadReplay|requestIdleCallback' \
src/presentation/web/package.json package.json pnpm-lock.yaml 2>/dev/null || true
printf '%s\n' '--- tracked Sentry-related files ---'
git ls-files | rg '(^|/)(hooks\.client\.ts|package\.json|pnpm-lock\.yaml)$|sentry|replay' | head -80
printf '%s\n' '--- pinned Sentry source: client integration lifecycle ---'
curl -fsSL https://raw.githubusercontent.com/getsentry/sentry-javascript/10.70.0/packages/core/src/client.ts \
| rg -n -C 12 'addIntegration|setupOnce|afterAllSetup|integration' | head -220
printf '%s\n' '--- pinned Sentry source: Replay integration and error sampling ---'
for f in \
packages/replay-internal/src/integration.ts \
packages/replay-internal/src/replay.ts \
packages/replay-internal/src/coreHandlers.ts \
packages/replay-internal/src/session.ts \
packages/replay/src/index.ts
do
printf '\n### %s\n' "$f"
curl -fsSL "https://raw.githubusercontent.com/getsentry/sentry-javascript/10.70.0/$f" \
| rg -n -C 10 'addIntegration|replaysOnErrorSampleRate|start\(|startBuffering|setupOnce|error|recording|session' \
| head -240 || true
doneRepository: ThunLights/distopia Length of output: 30285 🏁 Script executed: #!/bin/bash
set -eu
fetch_range() {
file="$1"
start="$2"
end="$3"
printf '\n### %s:%s-%s\n' "$file" "$start" "$end"
curl -fsSL "https://raw.githubusercontent.com/getsentry/sentry-javascript/10.70.0/$file" \
| nl -ba | sed -n "${start},${end}p"
}
fetch_range packages/replay-internal/src/integration.ts 239 430
fetch_range packages/replay-internal/src/replay.ts 316 620
fetch_range packages/replay-internal/src/replay.ts 620 900
fetch_range packages/replay-internal/src/coreHandlers/handleClick.ts 1 180
fetch_range packages/replay-internal/src/coreHandlers/handleKeyboardEvent.ts 1 140
printf '\n### SvelteKit replay export\n'
curl -fsSL https://raw.githubusercontent.com/getsentry/sentry-javascript/10.70.0/packages/sveltekit/src/index.client.ts \
| rg -n -C 8 'replayIntegration|Replay'Repository: ThunLights/distopia Length of output: 998 🏁 Script executed: #!/bin/bash
set -eu
fetch_range() {
file="$1"
start="$2"
end="$3"
printf '\n### %s:%s-%s\n' "$file" "$start" "$end"
curl -fsSL "https://raw.githubusercontent.com/getsentry/sentry-javascript/10.70.0/$file" \
| sed -n "${start},${end}p"
}
fetch_range packages/replay-internal/src/integration.ts 239 430
fetch_range packages/replay-internal/src/replay.ts 316 620
fetch_range packages/replay-internal/src/replay.ts 620 900
fetch_range packages/replay-internal/src/coreHandlers/handleClick.ts 1 180
fetch_range packages/replay-internal/src/coreHandlers/handleKeyboardEvent.ts 1 140
printf '\n### SvelteKit replay export candidates\n'
for file in packages/sveltekit/src/index.client.ts packages/sveltekit/src/index.ts packages/sveltekit/src/client.ts; do
printf '\n--- %s ---\n' "$file"
curl -fsSL "https://raw.githubusercontent.com/getsentry/sentry-javascript/10.70.0/$file" \
| grep -n -C 8 'replayIntegration\|Replay' || true
doneRepository: ThunLights/distopia Length of output: 33214 🏁 Script executed: #!/bin/bash
set -eu
printf '%s\n' '--- Replay integration continuation ---'
curl -fsSL https://raw.githubusercontent.com/getsentry/sentry-javascript/10.70.0/packages/replay-internal/src/integration.ts \
| sed -n '430,560p'
printf '%s\n' '--- Replay sampling and listener setup ---'
curl -fsSL https://raw.githubusercontent.com/getsentry/sentry-javascript/10.70.0/packages/replay-internal/src/replay.ts \
| sed -n '880,1160p'
printf '%s\n' '--- replay-internal source files ---'
curl -fsSL https://api.github.com/repos/getsentry/sentry-javascript/contents/packages/replay-internal/src?ref=10.70.0 \
| grep -o '"name": "[^"]*"' | head -100
printf '%s\n' '--- likely error handlers ---'
for file in \
packages/replay-internal/src/coreHandlers/handleError.ts \
packages/replay-internal/src/coreHandlers/handleSentryError.ts \
packages/replay-internal/src/handlers/handleError.ts \
packages/replay-internal/src/handlers/handleSentryError.ts
do
if body="$(curl -fsSL "https://raw.githubusercontent.com/getsentry/sentry-javascript/10.70.0/$file" 2>/dev/null)"; then
printf '\n### %s\n' "$file"
printf '%s\n' "$body" | sed -n '1,260p'
fi
doneRepository: ThunLights/distopia Length of output: 10657 Preserve initial Replay coverage.
🤖 Prompt for AI AgentsSource: MCP tools |
||
| } | ||
|
|
||
| // If you have a custom error handler, pass it to `handleErrorWithSentry` | ||
| export const handleError = handleErrorWithSentry(); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: ThunLights/distopia
Length of output: 15587
🏁 Script executed:
Repository: ThunLights/distopia
Length of output: 6089
Handle replay chunk load failures.
When
import("@sentry/sveltekit")rejects, the unhandled.then()promise also rejects. The browser can report an unhandled rejection, andreplayIntegration()is not registered. Add a.catch(...)that uses the application’s logging or error-reporting path, and test the rejection case.🤖 Prompt for AI Agents
Source: MCP tools