Skip to content

Decouple metrics aggregation from client #10582

@timfish

Description

@timfish

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 flush and close events from the client

This change requires a few steps:

  • In the client
    • Add flush and close hooks
    • Remove metricsAggregator from BaseClient
    • Remove captureAggregateMetrics from the BaseClient
    • Make _sendEnvelope public
  • 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 from getClient() and it can hook itself up to the client close and flush events
    • When the aggregators need to send metrics, they can create the envelope and send via client.sendEnvelope()

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.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions