-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(browser): Add browser metrics sdk #9794
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general: 👍
export const COUNTER_METRIC_TYPE = 'c'; | ||
export const GAUGE_METRIC_TYPE = 'g'; | ||
export const SET_METRIC_TYPE = 's'; | ||
export const DISTRIBUTION_METRIC_TYPE = 'd'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
m: Since we are not using these anywhere as actual values, should we just define them as types instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ended up using the constants and caught a bug f5d6333
size-limit report 📦
|
Updated the API: // Add 4 to a counter named `hits`
Sentry.metrics.increment('hits', 4);
// Add 2 to gauge named `parallel_requests`, tagged with `happy: "no"`
Sentry.metrics.gauge('parallel_requests', 2, { tags: { happy: 'no' } });
// Add 4.6 to a distribution named `response_time` with unit seconds
Sentry.metrics.distribution('response_time', 4.6, { unit: 'seconds' });
// Add 2 to a set named `valuable.ids`
Sentry.metrics.set('valuable.ids', 2); |
I went ahead and also refactored client and serialization logic as per @lforst feedback. It does have increased bundle size hit, but I believe it is waaaay more maintainable, thanks for keeping me honest! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! As you wrote in the description, integration tests would be great to have but I'm totally fine if we add them in a follow up PR.
}; | ||
} | ||
|
||
if (!!tunnel && !!dsn) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
l: do we need the double !!
here? we just check for definedness, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we do not, will change.
export const NAME_AND_TAG_KEY_NORMALIZATION_REGEX = /[^a-zA-Z0-9_/.-]+/g; | ||
|
||
/** | ||
* Normalization regex for metric tag balues. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* Normalization regex for metric tag balues. | |
* Normalization regex for metric tag values. |
this._min = value; | ||
this._max = value; | ||
this._sum = value; | ||
this._count = 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be moved to line 30
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For now it can't see #8700
/** | ||
* Simple hash function for strings. | ||
*/ | ||
export function simpleHash(s: string): number { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love this function
Based on Yagiz's PR review I refactored the tag serialization logic and also did a rename of the metrics class. Sentry.init({
dsn: '__DSN__',
integrations: [
new Sentry.metrics.MetricsAggregator(),
],
}); Although the duplication of |
Please read the following before reviewing:
ref #9691
This PR introduces functionality for a browser metrics SDK in an alpha state. Via the newly introduced APIs, you can now flush metrics directly to Sentry in the browser.
To enable capturing metrics, you first need to add the
Metrics
integration. This is done for treeshaking purposes.Then you'll be able to add
counters
,sets
,distributions
, andgauges
under theSentry.metrics
namespace.Under the hood, adding the
Metrics
integration adds aSimpleMetricsAggregator
. This is a bundle-sized efficient metrics aggregator that aggregates metrics and flushes them out every 5 seconds. This does not use any weight based logic - this will be implemented in theMetricsAggregator
that is used for server runtimes (node, deno, vercel-edge).To make metrics conditional, it is defined on the client as
public metricsAggregator: MetricsAggregator | undefined
.Next step is to add some integration tests for this functionality, and then add server-runtime logic for it.
Many of the decisions taken for this aggregator + flushing implementation was to try to be as bundle size efficient as possible, happy to answer any specific questions.