You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(python): Illustrate types of metrics (#15556)
Improve Python metrics documentation by:
- adding illustrative use cases to the introduction; and
- explaining the `before_send_metric()` callback; and
- adding individual examples for each metric type.
Copy file name to clipboardExpand all lines: docs/platforms/python/metrics/index.mdx
+3-1Lines changed: 3 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,9 @@ This feature is currently in open beta. Please reach out on [GitHub](https://git
11
11
12
12
</Alert>
13
13
14
-
With Sentry Metrics, you can send counters, gauges and distributions from your applications to Sentry. Once in Sentry, these metrics can be viewed alongside relevant errors, and searched using their individual attributes.
14
+
Sentry metrics help you pinpoint and solve issues that impact user experience and app performance by measuring the data points that are important to you. You can track things like processing time, event size, user signups, and conversion rates, then correlate them back to tracing data in order to get deeper insights and solve issues faster.
15
+
16
+
Once in Sentry, these metrics can be viewed alongside relevant errors, and searched using their individual attributes.
Copy file name to clipboardExpand all lines: platform-includes/metrics/options/python.mdx
+8-4Lines changed: 8 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,17 +1,21 @@
1
1
#### before_send_metric
2
2
3
-
To filter metrics, or update them before they are sent to Sentry, you can use the `before_send_metric` option.
3
+
To filter metrics, or update them before they are sent to Sentry, you can use the `before_send_metric` option. If the callback returns `None`, the metric is not emitted. Attributes can also be updated in the callback function.
Copy file name to clipboardExpand all lines: platform-includes/metrics/usage/python.mdx
+51-15Lines changed: 51 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,26 +2,62 @@ Once the feature is enabled on the SDK and the SDK is initialized, you can send
2
2
3
3
The `metrics` namespace exposes three methods that you can use to capture different types of metric information: `count`, `gauge`, and `distribution`.
4
4
5
+
## Emit a Counter
6
+
7
+
Counters are one of the more basic types of metrics and can be used to count certain event occurrences.
8
+
9
+
To emit a counter, do the following:
10
+
5
11
```python
6
-
from sentry_sdk importmetrics
12
+
importsentry_sdk
7
13
8
-
metrics.count("checkout.failed", 1)
9
-
metrics.gauge("queue.depth", 42)
10
-
metrics.distribution("cart.amount_usd", 187.5)
14
+
# Record five total button clicks
15
+
sentry_sdk.metrics.count(
16
+
"button_click",
17
+
5,
18
+
attributes={
19
+
"browser": "Firefox",
20
+
"app_version": "1.0.0"
21
+
},
22
+
)
11
23
```
12
24
13
-
You can also pass additional attributes directly to `count`, `gauge`, and `distribution` via the `attributes` kwarg.
25
+
## Emit a Distribution
26
+
27
+
Distributions help you get the most insights from your data by allowing you to obtain aggregations such as `p90`, `min`, `max`, and `avg`.
28
+
29
+
To emit a distribution, do the following:
14
30
15
31
```python
16
-
from sentry_sdk import metrics
17
-
18
-
metrics.count(
19
-
"checkout.failed",
20
-
1,
21
-
attributes={
22
-
"route": "/checkout",
23
-
"tenant": "acme",
24
-
"provider": "stripe",
25
-
},
32
+
import sentry_sdk
33
+
34
+
# Add '15.0' to a distribution used for tracking the loading times per page.
35
+
sentry_sdk.metrics.distribution(
36
+
"page_load",
37
+
15.0,
38
+
unit="millisecond",
39
+
attributes={
40
+
"page": "/home"
41
+
},
42
+
)
43
+
```
44
+
45
+
## Emit a Gauge
46
+
47
+
Gauges let you obtain aggregates like `min`, `max`, `avg`, `sum`, and `count`. They can be represented in a more space-efficient way than distributions, but they can't be used to get percentiles. If percentiles aren't important to you, we recommend using gauges.
48
+
49
+
To emit a gauge, do the following:
50
+
51
+
```python
52
+
import sentry_sdk
53
+
54
+
# Add '15.0' to a gauge used for tracking the loading times for a page.
0 commit comments