-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
Problem Statement
Currently, the Sentry SDK loads all configured modules (error tracking, performance monitoring, session replay, etc.) regardless of their sample rates. This means users who will never generate certain types of events due to sampling still have to download the associated code, increasing bundle size unnecessarily.
For high-traffic applications where sampling rates are very low (e.g., 1% for errors, 0.01% for replays), this creates unnecessary overhead for users who will not have these events sent to Sentry.
Current Behavior
- All SDK modules are loaded upfront
- Bundle size impact affects all users regardless of whether they'll send events
- Sample rates only determine if events are sent, not if code is loaded
- this is the currently the intent of those sample rate configs, so i wouldn't interpret that as negative
- Sampling decisions can be made dynamically during the session based on event attributes
Desired Outcome
A stripped down "SDK" that:
- Loads only a minimal core module initially
- Determines if a user/session falls within "some" sampling rates
- Dynamically imports additional modules (tracing, replay, etc.) only when needed
- Reduces bundle size impact for users outside sampling thresholds
Proposed Solution
Architecture Changes
-
Create a lightweight core module that:
- Handles initialization and sampling decisions
- Contains minimal error tracking capabilities
- Manages dynamic imports of additional features
-
Split current functionality into separate loadable chunks:
- Performance monitoring
- Session replay
- User feedback
- etc.
-
Implement dynamic loading logic
Potential Tradeoffs and Limitations
-
Loss of Dynamic/Functional Sampling Capabilities:
- Sampling Context Data
- Current SDK allows sampling decisions based on functional context
-
Timing Considerations:
- Initial sampling decision must be made before knowing full context
-
Implementation Complexity:
- Need to carefully manage module loading states
- Must handle race conditions between dynamic imports and event generation
- Additional complexity in managing module dependencies (should be handled already since tree shaking requires that the bundles can be stripped down already)
Discussion Points
- would there be a preload sample rate config, additionally?
Metadata
Metadata
Assignees
Labels
Projects
Status