-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
docs(js): Add metrics page #15353
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
docs(js): Add metrics page #15353
Changes from all commits
6f224b2
da4448f
a0e9f05
fbc8d7d
431d442
666c216
be41336
4d68513
c74b353
68ab033
aaf48bd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| --- | ||
| title: Set Up Metrics | ||
| sidebar_title: Metrics | ||
| description: "Metrics allow you to send, view and query counters, gauges and measurements from your Sentry-configured apps to track application health and drill down into related traces, logs, and errors." | ||
| sidebar_order: 5755 | ||
| --- | ||
|
|
||
| With Sentry Metrics, you can send counters, gauges, distributions, and sets from your applications to Sentry. Once in Sentry, these metrics can be viewed alongside relevant errors, and searched using their individual attributes. | ||
|
|
||
| <Alert> | ||
| This feature is currently in limited beta. Please reach out on [GitHub](https://github.com/getsentry/sentry-javascript/discussions/18055) if you have feedback or questions. Features in beta are still in-progress and may have bugs. We recognize the irony. | ||
| </Alert> | ||
|
|
||
| ## Requirements | ||
|
|
||
| <PlatformContent includePath="metrics/requirements" /> | ||
|
|
||
| ## Setup | ||
|
|
||
| <PlatformContent includePath="metrics/setup" /> | ||
|
|
||
| ## Usage | ||
|
|
||
| <PlatformContent includePath="metrics/usage" /> | ||
|
|
||
| ## Options | ||
|
|
||
| <PlatformContent includePath="metrics/options" /> | ||
|
|
||
| ## Default Attributes | ||
|
|
||
| <PlatformContent includePath="metrics/default-attributes" /> | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| By default the SDK will attach the following attributes to a metric: | ||
|
|
||
| 1. `sentry.environment`: The environment set in the SDK if defined. | ||
| 2. `sentry.release`: The release set in the SDK if defined. | ||
| 3. `sentry.sdk.name`: The name of the SDK that sent the metric. | ||
| 4. `sentry.sdk.version`: The version of the SDK that sent the metric. | ||
|
|
||
| ### User Attributes | ||
|
|
||
| The SDK will optionally attach user information as attributes (guarded by [`sendDefaultPii`](/platforms/javascript/configuration/options/#sendDefaultPii)): | ||
|
|
||
| 1. `user.id` | ||
| 2. `user.name` | ||
| 3. `user.email` | ||
|
|
||
|
|
||
| ### Browser Attributes | ||
|
|
||
| The SDK will optionally attach browser information as attributes: | ||
|
|
||
| 1. `browser.name` (added during ingestion, guarded by [`sendDefaultPii`](/platforms/javascript/configuration/options/#sendDefaultPii)) | ||
| 2. `browser.version` (added during ingestion, guarded by [`sendDefaultPii`](/platforms/javascript/configuration/options/#sendDefaultPii)) | ||
| 3. `sentry.replay_id`: The replay id of the replay that was active when the metric was collected. (added during ingestion by Relay) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| The Sentry JavaScript SDK provides several options to configure how metrics are captured and sent to Sentry. | ||
|
|
||
| ### Filtering and Modifying Metrics | ||
|
|
||
| Use the `beforeSendMetric` callback to filter or modify metrics before they're sent to Sentry. This is useful for: | ||
|
|
||
| - Removing sensitive data from metric attributes | ||
| - Dropping metrics you don't want to send | ||
| - Adding or modifying attributes | ||
|
|
||
| The callback receives a metric object and must return either a modified metric or `null` to drop it. | ||
|
|
||
| ```javascript | ||
| Sentry.init({ | ||
| // ... | ||
| beforeSendMetric: (metric) => { | ||
| // Drop metrics with specific attributes | ||
| if (metric.attributes?.dropMe === true) { | ||
| return null; | ||
| } | ||
|
|
||
| // Modify metric attributes | ||
| metric.attributes = { | ||
| ...metric.attributes, | ||
| processed: true, | ||
| }; | ||
chargome marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| return metric; | ||
| }, | ||
| }); | ||
| ``` | ||
|
|
||
| ### Disabling Metrics | ||
|
|
||
| If you want to disable metrics collection entirely, you can do so by disabling the `_experimental.enableMetrics` flag: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm a little confused by this; since this is an experimental feature that you need to manually turn on with
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I left this in here since we'll change this on monday to the top-level |
||
|
|
||
| ```javascript | ||
| Sentry.init({ | ||
| dsn: "___PUBLIC_DSN___", | ||
| _experiments: { | ||
| enableMetrics: false, | ||
| } | ||
| }); | ||
| ``` | ||
|
|
||
|
|
||
| ### Flushing Metrics | ||
|
|
||
| By default, metrics are buffered and flushed depending on buffer size and time. If you need to manually flush metrics before the automatic interval, you can use the `flush` method: | ||
|
|
||
| ```javascript | ||
| await Sentry.flush(); | ||
| ``` | ||
|
|
||
| This will flush all pending metrics and events to Sentry. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Metrics are supported in all Sentry JavaScript SDKs version `10.22.0` and above. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| Metrics are gated by an experimental option, `_experiments.enableMetrics` (this will not be required in future versions of the SDK). | ||
|
|
||
| ```javascript | ||
| Sentry.init({ | ||
| dsn: "___PUBLIC_DSN___", | ||
| _experiments: { | ||
| enableMetrics: true, | ||
| }, | ||
| }); | ||
| ``` | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| Once the feature is enabled and the SDK is initialized, you can send metrics using the `Sentry.metrics` APIs. | ||
|
|
||
| The `metrics` namespace exposes three methods that you can use to capture different types of metric information: `count`, `gauge` and `distribution`. | ||
|
|
||
| ### Counter | ||
|
|
||
| Use `count` to track an incrementing value, such as the number of times a button was clicked or a function was called. | ||
|
|
||
| ```javascript | ||
| Sentry.metrics.count("button_click", 1); | ||
| ``` | ||
|
|
||
| ### Gauge | ||
|
|
||
| Use `gauge` to track a value that can go up and down, such as the current memory usage or the number of items in a queue. | ||
|
|
||
| ```javascript | ||
| Sentry.metrics.gauge("queue_depth", 42); | ||
| ``` | ||
|
|
||
| ### Distribution | ||
|
|
||
| Use `distribution` to track the distribution of a value, such as the response time of a request. | ||
|
|
||
| ```javascript | ||
| Sentry.metrics.distribution("response_time", 187.5); | ||
| ``` | ||
|
|
||
| ### Adding Attributes | ||
|
|
||
| You can also pass additional attributes to any of the metric methods via the `attributes` option. Attributes allow you to filter and group metrics. | ||
|
|
||
| ```javascript | ||
| Sentry.metrics.count( | ||
| "button_click", | ||
| 1, | ||
| { | ||
| tags: { | ||
| browser: "Firefox", | ||
| app_version: "1.0.0", | ||
| }, | ||
| } | ||
| ); | ||
| ``` | ||
|
|
||
| ### Specifying Units | ||
|
|
||
| For `gauge` and `distribution` metrics, you can specify a unit using the `unit` option. This helps Sentry display the metric value in a human-readable format. | ||
chargome marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ```javascript | ||
| Sentry.metrics.distribution( | ||
| "response_time", | ||
| 187.5, | ||
| { | ||
| unit: "millisecond", | ||
| } | ||
| ); | ||
|
|
||
| Sentry.metrics.gauge( | ||
| "memory_usage", | ||
| 1024, | ||
| { | ||
| unit: "byte", | ||
| } | ||
| ); | ||
| ``` | ||
Uh oh!
There was an error while loading. Please reload this page.