Skip to content

Commit b8b8e30

Browse files
committed
add js metrics
1 parent 65a3fcb commit b8b8e30

File tree

7 files changed

+160
-8
lines changed

7 files changed

+160
-8
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
title: Set Up Metrics
3+
sidebar_title: Metrics
4+
description: "Metrics allow you to send, view and query counters, gauges and measurements sent from your applications within Sentry."
5+
sidebar_order: 5755
6+
---
7+
8+
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.
9+
10+
<Alert>
11+
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.
12+
</Alert>
13+
14+
## Requirements
15+
16+
<PlatformContent includePath="metrics/requirements" />
17+
18+
## Setup
19+
20+
<PlatformContent includePath="metrics/setup" />
21+
22+
## Usage
23+
24+
<PlatformContent includePath="metrics/usage" />
25+
26+
## Options
27+
28+
<PlatformContent includePath="metrics/options" />
29+
30+
## Default Attributes
31+
32+
<PlatformContent includePath="metrics/default-attributes" />
33+
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
By default the SDK will attach the following attributes to a metric:
2+
3+
1. `sentry.environment`: The environment set in the SDK if defined.
4+
2. `sentry.release`: The release set in the SDK if defined.
5+
3. `sentry.sdk.name`: The name of the SDK that sent the metric
6+
4. `sentry.sdk.version`: The version of the SDK that sent the metric
7+
8+
### User Attributes
9+
10+
The SDK will optionally attach user information as attributes (guarded by `sendDefaultPii`):
11+
12+
1. `user.id`
13+
2. `user.name`
14+
3. `user.email`
15+
16+
17+
### Browser Attributes
18+
19+
The SDK will optionally attach browser information as attributes:
20+
21+
1. `browser.name`
22+
2. `browser.version`
23+
3. `sentry.replay_id`: The replay id of the replay that was active when the metric was collected.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
The Sentry JavaScript SDK provides several options to configure how metrics are captured and sent to Sentry.
2+
3+
### Disabling Metrics
4+
5+
If you want to disable metrics collection entirely, you can do so by disabling the `_experimental.enableMetrics` flag:
6+
7+
```javascript
8+
Sentry.init({
9+
dsn: "___PUBLIC_DSN___",
10+
_experiments: {
11+
enable_metrics: false,
12+
}
13+
});
14+
```
15+
16+
17+
### Flushing Metrics
18+
19+
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:
20+
21+
```javascript
22+
await Sentry.flush();
23+
```
24+
25+
This will flush all pending metrics and events to Sentry.
26+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Metrics are supported in all Sentry JavaScript SDKs version `10.22.0` and above.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Metrics are gated by an experimental option, `_experiments.enableMetrics` (will not be required in future versions of the SDK).
2+
3+
```javascript
4+
Sentry.init({
5+
dsn: "___PUBLIC_DSN___",
6+
_experiments: {
7+
enableMetrics: true,
8+
},
9+
});
10+
```
11+
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
Once the feature is enabled and the SDK is initialized, you can send metrics using the `Sentry.metrics` APIs.
2+
3+
The `metrics` namespace exposes three methods that you can use to capture different types of metric information: `count`, `gauge` and `distribution`.
4+
5+
### Counter
6+
7+
Use `count` to track an incrementing value, such as the number of times a button was clicked or a function was called.
8+
9+
```javascript
10+
Sentry.metrics.count("button_click", 1);
11+
```
12+
13+
### Gauge
14+
15+
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.
16+
17+
```javascript
18+
Sentry.metrics.gauge("queue_depth", 42);
19+
```
20+
21+
### Distribution
22+
23+
Use `distribution` to track the distribution of a value, such as the response time of a request.
24+
25+
```javascript
26+
Sentry.metrics.distribution("response_time", 187.5);
27+
```
28+
29+
### Adding Attributes
30+
31+
You can also pass additional attributes to any of the metric methods via the `attributes` option. Attributes allow you to filter and group metrics.
32+
33+
```javascript
34+
Sentry.metrics.count(
35+
"button_click",
36+
1,
37+
{
38+
tags: {
39+
browser: "Firefox",
40+
app_version: "1.0.0",
41+
},
42+
}
43+
);
44+
```
45+
46+
### Specifying Units
47+
48+
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.
49+
50+
```javascript
51+
Sentry.metrics.distribution(
52+
"response_time",
53+
187.5,
54+
{
55+
unit: "millisecond",
56+
}
57+
);
58+
59+
Sentry.metrics.gauge(
60+
"memory_usage",
61+
1024,
62+
{
63+
unit: "byte",
64+
}
65+
);
66+
```

redirects.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,14 +1080,6 @@ const userDocsRedirects = [
10801080
source: '/platforms/javascript/tracing/trace-propagation/:path*',
10811081
destination: '/platforms/javascript/tracing/distributed-tracing/:path*',
10821082
},
1083-
{
1084-
source: '/platforms/javascript/metrics/:path*',
1085-
destination: '/platforms/javascript/tracing/span-metrics/:path*',
1086-
},
1087-
{
1088-
source: '/platforms/javascript/guides/:guide/metrics/:path*',
1089-
destination: '/platforms/javascript/guides/:guide/tracing/span-metrics/:path*',
1090-
},
10911083
{
10921084
source: '/platforms/javascript/tracing/instrumentation/performance-metrics/',
10931085
destination: '/platforms/javascript/tracing/span-metrics/',

0 commit comments

Comments
 (0)