Repository navigation
⚗️ [PROF-16224] start early collection of errors and profiling before the SDK is loaded - #5192
Draft
thomasbertet wants to merge 2 commits into
Draft
thomasbertet wants to merge 2 commits into
thomasbertet wants to merge 2 commits into
Conversation
… the SDK is loaded
Bundles Sizes Evolution
|
❌ ErrorsYour PR has failed checks. Please review the issues below and take necessary action before merging. 🚦 1 Pipeline job failed
ℹ️ InfoNo other issues found (see more)🧪 All tests passed 🎯 Code Coverage (details) Useful? React with 👍 / 👎 This comment will be updated automatically if new data arrives.🔗 Commit SHA: 1f3872a | Docs | View more details | Give us feedback! |
This branch has not been deployed
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.
Motivation
The SDK only sees its data sources once its bundle is evaluated.
startBufferingData()already buffers errors, fetch, XHR and console from bundle evaluation untilinit()(RUM-10145 #3622, extended by #4470/#4489), but everything between HTML parse and bundle evaluation stays dark, and the JS Self-Profiling Profiler only starts when the profiler chunk loads.PROF-16224 RFC proposes an early collection package: a tiny script evaluated as the first script of the page. This implements its first slice: raw errors and profiling.
Changes
@datadog/browser-early-collection: standalone, dependency-free script (bundledatadog-early-collection.js). Evaluating it starts:sampleInterval: 10,maxBufferSize: 9000, fails silently when unsupported or when theDocument-Policy: js-profilingheader is missing).window._DD_EARLY_COLLECTION(version,startClocks, buffer capped at 500 entries,profiler, idempotentstop()).startEarlyCollection()); the auto-start entry lives inentries/main.ts, outsidesrc/, because thedisallow-side-effectsrule scopes topackages/*/src.startBufferingData()skips the runtime-error instrumentation when the early global is present (the early listeners keep collecting); fetch, XHR and console are unchanged.takeOverEarlyCollection()installs the SDK error instrumentation first, then drains the early buffer and processes entries withcomputeRawError(stack parsing moved to init time), replays them as RUM error events of the initial view, then seals the early collection and deletes the global.collection_type: 'early'), andprofilerApistops it on all not-profiling paths (no session, not sampled, unsupported browser, chunk load failure, SDK stop), following the pattern of open ✨ [PROF-16083] start profiler collection before the SDK and profiler chunk are loaded #5069.Not included: Logs SDK and browser-rum-slim handoff (the early global is only reclaimed by the RUM SDK), setup UI / CDN distribution, console/fetch/XHR early collectors, sandbox dogfood injection. Tracked as open questions in the RFC.
Note for reviewers: this implementation was written by an AI coding agent and reviewed by a human; the files most worth a careful pass are
earlyCollectionTakeover.ts(init ordering and draining) and thedatadogProfiler.tsadoption wiring.Test instructions
yarn workspace @datadog/browser-early-collection buildproducespackages/browser-early-collection/bundle/datadog-early-collection.jsyarn test:unit --spec packages/browser-early-collection/src/index.spec.tsyarn test:unit --spec packages/browser-core/src/domain/earlyCollection/earlyCollection.spec.ts --spec packages/browser-core/src/domain/earlyCollection/earlyCollectionTakeover.spec.tsyarn test:unit --spec packages/browser-core/src/domain/bufferedData.spec.ts --spec packages/browser-rum-core/src/domain/error/errorCollection.spec.tsyarn test:unit --spec packages/browser-rum/src/boot/profilerApi.spec.ts --spec packages/browser-rum/src/domain/profiling/datadogProfiler.spec.tscollection_type: 'early').Checklist