Skip to content

Commit 3f9bfd0

Browse files
committed
feat(ruby): Metrics docs
1 parent 1b8502c commit 3f9bfd0

File tree

8 files changed

+144
-9
lines changed

8 files changed

+144
-9
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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: 7
6+
sidebar_section: features
7+
beta: true
8+
---
9+
10+
<Alert>
11+
12+
This feature is currently in open beta. Please reach out on [GitHub](https://github.com/getsentry/sentry/discussions/102275) if you have feedback or questions. Features in beta are still in-progress and may have bugs. We recognize the irony.
13+
14+
</Alert>
15+
16+
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.
17+
18+
Once in Sentry, these metrics can be viewed alongside relevant errors, and searched using their individual attributes.
19+
20+
## Requirements
21+
22+
<PlatformContent includePath="metrics/requirements" />
23+
24+
## Usage
25+
26+
<PlatformContent includePath="metrics/usage" />
27+
28+
## Options
29+
30+
<PlatformContent includePath="metrics/options" />
31+
32+
## Default Attributes
33+
34+
<PlatformContent includePath="metrics/default-attributes" />

docs/product/explore/metrics/getting-started/index.mdx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,16 +235,19 @@ To set up Sentry Metrics, use the links below for supported SDKs. After it's bee
235235
url="/platforms/php/guides/laravel/metrics/"
236236
/>
237237

238-
## Upcoming SDKs
239-
240-
We're actively working on adding Metrics functionality to additional SDKs. Check out these GitHub issues for the latest updates:
238+
### Ruby
241239

242240
- <LinkWithPlatformIcon
243241
platform="ruby"
244242
label="Ruby (incl. Rails)"
245-
url="https://github.com/getsentry/sentry-ruby/issues/2776"
243+
url="/platforms/ruby/metrics/"
246244
/>
247245

246+
247+
## Upcoming SDKs
248+
249+
We're actively working on adding Metrics functionality to additional SDKs. Check out these GitHub issues for the latest updates:
250+
248251
- <LinkWithPlatformIcon
249252
platform="go"
250253
label="Go"

includes/metrics/default-attributes/core.mdx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@
22

33
- `environment`: The environment set in the SDK if defined. This is sent from the SDK as `sentry.environment`.
44
- `release`: The release set in the SDK if defined. This is sent from the SDK as `sentry.release`.
5-
- `trace.parent_span_id`: The span ID of the span that was active when the metric was collected (only set if there was an active span). This is sent from the SDK as `sentry.trace.parent_span_id`.
65
- `sdk.name`: The name of the SDK that sent the metric. This is sent from the SDK as `sentry.sdk.name`.
76
- `sdk.version`: The version of the SDK that sent the metric. This is sent from the SDK as `sentry.sdk.version`.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
The Ruby SDK automatically sets several default attributes on all metrics to provide context and improve debugging:
2+
3+
<Include name="metrics/default-attributes/core" />
4+
5+
<Include name="metrics/default-attributes/server" />
6+
7+
<Include name="metrics/default-attributes/user" />
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#### before_send_metric
2+
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 `nil`, the metric is not emitted. Attributes can also be updated in the callback function.
4+
5+
```ruby
6+
Sentry.init do |config|
7+
config.dsn = "___PUBLIC_DSN___"
8+
9+
config.before_send_metric = lambda do |metric|
10+
# filter metric
11+
return nil if metric.name == "removed-metric"
12+
13+
# add attributes
14+
metric.attributes[:extra] = "foo"
15+
16+
# remove attributes
17+
metric.attributes.delete(:browser) if metric.attributes.has_key?(:browser)
18+
19+
metric
20+
end
21+
end
22+
```
23+
24+
The `before_send_metric` function receives a `MetricEvent` object, and should return a `MetricEvent` object if you want it to be sent to Sentry, or `nil` if you want to discard it.
25+
26+
The `MetricEvent` object has the following attributes:
27+
28+
- `name`: (`String`) The name of the metric.
29+
- `type`: (`Symbol`) - one of `:counter`, `:gauge`, `:distribution`) The type of metric.
30+
- `value`: (`Float`) The numeric value of the metric.
31+
- `unit`: (`Optional[String]`) The unit of measurement for the metric value.
32+
- `attributes`: (`Hash`) Additional attributes to be sent with the metric.
33+
- `timestamp`: (`Time`) Timestamp indicating when the metric was recorded.
34+
- `trace_id`: (`Optional[String]`) The trace ID of the trace this metric belongs to.
35+
- `span_id`: (`Optional[String]`) The span ID of the span that was active when the metric was emitted.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Metrics for Python are supported in Sentry Ruby SDK version `6.3.0` and above.
2+
3+
```bash
4+
gem install sentry-ruby
5+
```
6+
7+
Or add it to your Gemfile:
8+
9+
```ruby
10+
gem "sentry-ruby"
11+
```
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
Metrics are enabled by default. Once you initialize the SDK, 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+
## 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+
11+
```ruby
12+
# Record five total button clicks
13+
Sentry.metrics.count(
14+
"button_click",
15+
value: 5,
16+
attributes: { browser: "Firefox", app_version: "1.0.0" }
17+
)
18+
```
19+
20+
## Emit a Distribution
21+
22+
Distributions help you get the most insights from your data by allowing you to obtain aggregations such as `p90`, `min`, `max`, and `avg`.
23+
24+
To emit a distribution, do the following:
25+
26+
```ruby
27+
# Add '15.0' to a distribution used for tracking the loading times per page.
28+
Sentry.metrics.distribution(
29+
"page_load",
30+
15.0,
31+
unit: "millisecond",
32+
attributes: { page: "/home" }
33+
)
34+
```
35+
36+
## Emit a Gauge
37+
38+
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.
39+
40+
To emit a gauge, do the following:
41+
42+
```ruby
43+
# Add '15.0' to a gauge used for tracking the loading times for a page.
44+
Sentry.metrics.gauge(
45+
"page_load",
46+
15.0,
47+
unit: "millisecond",
48+
attributes: { "page": "/home" }
49+
)
50+
```

src/middleware.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1770,10 +1770,6 @@ const USER_DOCS_REDIRECTS: Redirect[] = [
17701770
to: '/platforms/javascript/guides/:guide/opentelemetry/',
17711771
},
17721772
// START redirecting deprecated generic metrics docs to concepts
1773-
{
1774-
from: '/platforms/ruby/metrics/',
1775-
to: '/concepts/key-terms/tracing/span-metrics/',
1776-
},
17771773
{
17781774
from: '/platforms/java/metrics/',
17791775
to: '/concepts/key-terms/tracing/span-metrics/',

0 commit comments

Comments
 (0)