-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Labels
Description
Problem Statement
Currently the MetricsAggregator is optionally stored on the client if the feature has been enabled via the metricsAggregatorIntegration in the browser or an experimental flag for node.
The MetricsAggregator can be much more decoupled from the client and no special configuration is required to keep it's functionality out of the default browser bundle.
Solution Brainstorm
The metrics code only needs to be able to:
- Send envelopes
- Get notice of
flushandcloseevents from the client
This change requires a few steps:
- In the client
- Add
flushandclosehooks - Remove
metricsAggregatorfromBaseClient - Remove
captureAggregateMetricsfrom theBaseClient - Make
_sendEnvelopepublic
- Add
- Wrap the
Sentry.metrics.*exports in a function that allows passing the correct metrics aggregator implementation for browser/node.- On the first call to a
Sentry.metrics.*function, create the aggregator, pass it the client fromgetClient()and it can hook itself up to the clientcloseandflushevents - When the aggregators need to send metrics, they can create the envelope and send via
client.sendEnvelope()
- On the first call to a
This way, in both the browser and node, the metrics aggregator code will only be included in the bundle if calls are made to the Sentry.metrics.* methods. It will also drop a few hundred bytes from the default bundle as the remaining metrics code will get removed from the BaseClient.