Skip to content

Commit e4dddb1

Browse files
authored
feat(metrics): add documentation for metrics for laravel/symfony (#15694)
I copy & pasted the usage because they have a different flushing behaviours compared to the regular SDK. ## DESCRIBE YOUR PR *Tell us what you're changing and why. If your PR **resolves an issue**, please link it so it closes automatically.* ## IS YOUR CHANGE URGENT? Help us prioritize incoming PRs by letting us know when the change needs to go live. - [ ] Urgent deadline (GA date, etc.): <!-- ENTER DATE HERE --> - [ ] Other deadline: <!-- ENTER DATE HERE --> - [ ] None: Not urgent, can wait up to 1 week+ ## SLA - Teamwork makes the dream work, so please add a reviewer to your PRs. - Please give the docs team up to 1 week to review your PR unless you've added an urgent due date to it. Thanks in advance for your help! ## PRE-MERGE CHECKLIST *Make sure you've checked the following before merging your changes:* - [ ] Checked Vercel preview for correctness, including links - [ ] PR was reviewed and approved by any necessary SMEs (subject matter experts) - [ ] PR was reviewed and approved by a member of the [Sentry docs team](https://github.com/orgs/getsentry/teams/docs) ## LEGAL BOILERPLATE <!-- Sentry employees and contractors can delete or ignore this section. --> Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. and is gonna need some rights from me in order to utilize my contributions in this here PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms. ## EXTRA RESOURCES - [Sentry Docs contributor guide](https://docs.sentry.io/contributing/)
1 parent 97770f2 commit e4dddb1

File tree

5 files changed

+102
-8
lines changed

5 files changed

+102
-8
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- [Laravel SDK](/platforms/php/guides/laravel) version `4.20.0` or above.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- [Symfony SDK](/platforms/php/guides/symfony) version `5.8.0` or above.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
Metrics are enabled by default in the PHP SDK. After the SDK is initialized, you can send metric data through `\Sentry\trace_metrics()`, which acts as the entry point for recording counts, gauges, and distributions.
2+
3+
The SDK buffers up to 1000 metric entries at a time. Once that limit is reached, it keeps only the most recent 1000. If you need to retain more than that, flush the metrics periodically before you exceed the buffer.
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+
```php
12+
// Record five total button clicks
13+
\Sentry\trace_metrics()->count('button-click', 5, ['browser' => 'Firefox', 'app_version' => '1.0.0']);
14+
```
15+
16+
## Emit a Distribution
17+
18+
Distributions help you get the most insights from your data by allowing you to obtain aggregations such as `p90`, `min`, `max`, and `avg`.
19+
20+
To emit a distribution, do the following:
21+
22+
```php
23+
use \Sentry\Metrics\Unit;
24+
25+
// Add '15.0' to a distribution used for tracking the loading times per page.
26+
\Sentry\trace_metrics()->distribution('page-load', 15.0, ['page' => '/home'], Unit::millisecond());
27+
```
28+
29+
## Emit a Gauge
30+
31+
Gauges let you obtain aggregates like `min`, `max`, `avg`, `sum`, and `count`. Gauges can not be used to represent percentiles. If percentiles aren't important to you, we recommend using gauges.
32+
33+
To emit a gauge, do the following:
34+
35+
```php
36+
use \Sentry\Metrics\Unit;
37+
38+
// Add '15.0' to a gauge used for tracking the loading times per page.
39+
\Sentry\trace_metrics()->gauge('page-load', 15.0, ['page' => '/home'], Unit::millisecond());
40+
```
41+
42+
## Flush
43+
44+
Metrics are flushed and sent to Sentry at the end of each request or command.
45+
46+
If you emit more than 1000 metrics per request or command, make sure to manually flush to prevent losing metrics.
47+
48+
```php
49+
\Sentry\trace_metrics()->flush();
50+
```
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
Metrics are enabled by default in the Symfony SDK. After the SDK is initialized, you can send metric data through `\Sentry\trace_metrics()`, which acts as the entry point for recording counts, gauges, and distributions.
2+
3+
The SDK buffers up to 1000 metric entries at a time. Once that limit is reached, it keeps only the most recent 1000. If you need to retain more than that, flush the metrics periodically before you exceed the buffer.
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+
```php
12+
// Record five total button clicks
13+
\Sentry\trace_metrics()->count('button-click', 5, ['browser' => 'Firefox', 'app_version' => '1.0.0']);
14+
```
15+
16+
## Emit a Distribution
17+
18+
Distributions help you get the most insights from your data by allowing you to obtain aggregations such as `p90`, `min`, `max`, and `avg`.
19+
20+
To emit a distribution, do the following:
21+
22+
```php
23+
use \Sentry\Metrics\Unit;
24+
25+
// Add '15.0' to a distribution used for tracking the loading times per page.
26+
\Sentry\trace_metrics()->distribution('page-load', 15.0, ['page' => '/home'], Unit::millisecond());
27+
```
28+
29+
## Emit a Gauge
30+
31+
Gauges let you obtain aggregates like `min`, `max`, `avg`, `sum`, and `count`. Gauges can not be used to represent percentiles. If percentiles aren't important to you, we recommend using gauges.
32+
33+
To emit a gauge, do the following:
34+
35+
```php
36+
use \Sentry\Metrics\Unit;
37+
38+
// Add '15.0' to a gauge used for tracking the loading times per page.
39+
\Sentry\trace_metrics()->gauge('page-load', 15.0, ['page' => '/home'], Unit::millisecond());
40+
```
41+
42+
## Flush
43+
44+
Metrics are flushed and sent to Sentry at the end of each request or command.
45+
46+
If you emit more than 1000 metrics per request or command, make sure to manually flush to prevent losing metrics.
47+
48+
```php
49+
\Sentry\trace_metrics()->flush();
50+
```

src/middleware.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1786,14 +1786,6 @@ const USER_DOCS_REDIRECTS: Redirect[] = [
17861786
from: '/platforms/unity/metrics/',
17871787
to: '/concepts/key-terms/tracing/span-metrics/',
17881788
},
1789-
{
1790-
from: '/platforms/php/guides/laravel/metrics/',
1791-
to: '/concepts/key-terms/tracing/span-metrics/',
1792-
},
1793-
{
1794-
from: '/platforms/php/guides/symfony/metrics/',
1795-
to: '/concepts/key-terms/tracing/span-metrics/',
1796-
},
17971789
// END redirecting deprecated generic metrics docs to concepts
17981790
{
17991791
from: '/learn/cli/configuration/',

0 commit comments

Comments
 (0)