[PROF-13798] [Browser Profiler] Quota check#4514
Draft
thomasbertet wants to merge 10 commits intomainfrom
Draft
Conversation
New module that calls GET /api/unstable/profiling/admission with the RUM session ID. Returns 'quota-ok' (HTTP 200, timeout, network error) or 'quota-exceeded' (HTTP 429). Client-side 5s timeout via AbortController + Promise.race. Uses the Zone.js-safe fetch wrapper from @datadog/browser-core.
Profiler starts recording immediately (optimistic), then fires checkProfilingQuota() in parallel. On quota-exceeded (HTTP 429): - Profiler stops and discards the in-flight trace (no data sent) - _dd.profiling.error_reason is set to 'quota-exceeded' on RUM events Stale results (from a prior session) are discarded via a generation counter incremented on each start(). Within-session cancellation (user stop, session expiry) is handled by an instance state guard. SESSION_RENEWED now also restarts the profiler when it was stopped due to quota-exceeded, re-checking quota for the new session.
|
✨ Fix all issues with BitsAI or with Cursor
|
Expose clientToken on TransportConfiguration so it is accessible from RumConfiguration downstream. Previously clientToken was only available at init time when building endpoint builders, making it inaccessible from the profiler chunk. Also run Prettier on the two spec files that had formatting issues.
Bundles Sizes Evolution
🚀 CPU PerformancePending... 🧠 Memory PerformancePending... |
…uota" This reverts commit c280a62.
…eckProfilingQuota Move client token from dd-api-key query param to DD-CLIENT-TOKEN header to avoid leaking it in URL logs. Add getQuotaBaseURL() to resolve the correct base per site (datad0g.com uses dd.datad0g.com, others use app.<site>). Add credentials: 'omit' to suppress cookie sending.
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
Adds client-side enforcement of the per-org profiling quota by calling the quota admission API before allowing profiling data to be sent. Ticket: PROF-13798.
Changes
quotaCheck.ts: callsGET /api/unstable/profiling/admission?session_id=<id>&dd-api-key=<token>. Returns'quota-ok'(HTTP 200, timeout, network error — fail-open) or'quota-exceeded'(HTTP 429). 5 s client-side timeout viaAbortController+Promise.race. Uses the Zone.js-safefetchwrapper from@datadog/browser-core.profiler.ts: profiler starts recording immediately (optimistic), quota check fires in parallel. Onquota-exceeded: profiler stops, trace is discarded (no data sent),_dd.profiling.error_reasonis set to'quota-exceeded'on RUM events. A generation counter prevents stale results from a prior session applying to a new one.SESSION_RENEWEDnow also restarts onquota-exceededso quota is re-checked on session renewal.rumProfiler.types.ts: adds'quota-exceeded'toRumProfilerStoppedInstance.stateReason.Temporary Note:
_dd.profiling.error_reason: 'quota-exceeded'is passed withas anyuntil therum-events-formatschema is updated in arum-events-formatPR.Test instructions
yarn test:unit --spec packages/rum/src/domain/profiling/quotaCheck.spec.ts(5 tests)yarn test:unit --spec packages/rum/src/domain/profiling/profiler.spec.ts(25 tests, includes 8 new quota check scenarios)_dd.profiling.error_reason: 'quota-exceeded'appears on RUM events when the quota API returns 429Checklist